1 name = 
"PyQNLPSimulator"     8 from ._PyQNLPSimulator 
import *
    10 from scipy.linalg 
import expm
    12 from itertools 
import product
    13 from scipy.optimize 
import least_squares
    17     This class is primarily for experimenting with gate operations during algorithm development.    18     This wraps the underlying gate types from the given simulator, and also gives a numpy version.    20     THIS IS NOT TO BE USED FOR PERFORMANT/PRODUCTION CODE AND IS STRICTLY FOR DEV/TEST.    24             "X" : simulator.getGateX(),
    25             "Y" : simulator.getGateX(),
    26             "Z" : simulator.getGateX(),
    27             "H" : simulator.getGateX(),
    28             "I" : simulator.getGateX(),
    29             "Xnp" : simulator.getGateX(),
    30             "Xnp" : simulator.getGateX(),
    31             "Xnp" : simulator.getGateX(),
    32             "Xnp" : simulator.getGateX(),
    34         self.
X = simulator.getGateX()
    35         self.
Y = simulator.getGateY()
    36         self.
Z = simulator.getGateZ()
    37         self.
H = simulator.getGateH()
    38         self.
I = simulator.getGateI()
    40         self.
Xnp = np.matrix(self.
X.as_numpy())
    41         self.
Ynp = np.matrix(self.
Y.as_numpy())
    42         self.
Znp = np.matrix(self.
Z.as_numpy())
    43         self.
Hnp = np.matrix(self.
H.as_numpy())
    44         self.
Inp = np.matrix(self.
I.as_numpy())
    50         return np.matrix(expm(-0.5*1j*theta*self.
Xnp))
    53         return np.matrix(expm(-0.5*1j*theta*self.
Ynp))
    56         return np.matrix(expm(-0.5*1j*theta*self.
Znp))
    59         "RZ excluding global phase of exp(iTheta/2)"    61         return np.matrix([[1.0,0.0], [0., np.exp(1j*theta)] ])
    63     def RU(self, theta, U):
    65         if isinstance(U, list):
    67         elif isinstance(U, DCMatrix):
    70             raise TypeError(
"U is not an accepted type: should be list or DCMatrix")
    72         return np.matrix(expm(-0.5*1j*theta*res))
    76         from scipy.optimize 
import least_squares 
as lsq
    81         self.
gates = [
"X", 
"Y", 
"Z", 
"H", 
"RX", 
"RY", 
"RZ", 
"RZPh"]
    84     def findOps(self, gate_order, cost_tol = 1e-3):
    85         lambda x: np.array([2*x[0] + x[1] - 1])
    91         def setMinFunc(x, gates):
    96             for g 
in reversed(gates):
    98                     nn *= getattr(self.
gate_ops , g)(x[param_val])
   101                     nn *= getattr(self.
gate_ops, 
"".join((g,
"np")))
   104             ml = [i 
for sublist 
in mm 
for i 
in sublist]
   105             mr = [np.real(i) 
for i 
in ml]
   106             mi = [np.imag(i) 
for i 
in ml]
   108             nl = [i 
for sublist 
in nn 
for i 
in sublist]
   109             nr = [np.real(i) 
for i 
in nl]
   110             ni = [np.imag(i) 
for i 
in nl]
   113             ab = np.sum([i**2 
for i 
in np.subtract(m,n)])
   118             res = least_squares(setMinFunc, [0]*num_params, args=(gate_order,), bounds=(-np.pi, np.pi))
   119             if res.cost <= cost_tol:
   120                 return res.success, res.x
   125             rr = setMinFunc([], gate_order)
   126             return np.isclose(rr, 0, rtol=cost_tol), []
   129         """Generate the combinations of operations.   130         Same gate is never called twice in a row."""   132         ops_list0 = list(product(gates, repeat=depth))
   133         ops_list = list(product(gates, repeat=depth))
   135         for idx_ops_list, ops 
in enumerate(ops_list):
   136             for idx_ops 
in range(1,len(ops)):
   137                 if ops[idx_ops] == ops[idx_ops-1]:
   139                     del_idx.add(idx_ops_list)
   140         ops_list = [val 
for idx,val 
in enumerate(ops_list) 
if idx 
not in del_idx]
 
def findOps(self, gate_order, cost_tol=1e-3)
 
def __init__(self, simulator)
 
def __init__(self, simulator, unitary)
 
def genOps(self, list gates, depth=5)
 
def createU(self, list vals)