Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def prog_generation(self,qubit_list):
prog=QProg()
prog.insert(single_gate_apply_to_all(gate=H, qubit_list=qubit_list))
for i in range(self.step):
prog.insert(simulate_pauliZ_hamiltonian(qubit_list,self.Hp,2*self.gamma[i]))\
.insert(pauliX_model(qubit_list,self.beta[i]))
return prog
def get_cost_value(self,qubit_list):
'''
compute Hp's expectation,
all_cut_value_list:eigenvalues of Hp
'''
prog=QProg()
prog.insert(single_gate_apply_to_all(gate=H, qubit_list=qubit_list))
for i in range(self.step):
prog.insert(simulate_pauliZ_hamiltonian(qubit_list,self.Hp,2*self.gamma[i]))\
.insert(pauliX_model(qubit_list,self.beta[i]))
cost_value=0
if len(self.all_cut_value_list):
result=prob_run_list(program=prog,qubit_list=qubit_list,select_max=-1)
cost_value=vector_dot(result,self.all_cut_value_list)
# cost_value=np.sum(np.array(result)*np.array(self.all_cut_value_list))
else:
cost_value=get_expectation(qubit_list,prog,self.Hp)
return cost_value
'''
prog0=QProg()
prog1=QProg()
prog0.insert(single_gate_apply_to_all(gate=H, qubit_list=qubit_list))
prog1.insert(single_gate_apply_to_all(gate=H, qubit_list=qubit_list))
coef=0
if label[1]==0:
coef=2*self.Hp.ops[label[0]]
else:
coef=2
for i in range(len(self.gamma)):
if label[2]!=i:
prog0.insert(simulate_pauliZ_hamiltonian(qubit_list,self.Hp,2*self.gamma[i]))\
.insert(pauliX_model(qubit_list,self.beta[i]))
prog1.insert(simulate_pauliZ_hamiltonian(qubit_list,self.Hp,2*self.gamma[i]))\
.insert(pauliX_model(qubit_list,self.beta[i]))
else:
if label[1]==0:
'''
Hp:gamma
'''
for j in self.Hp.ops:
if j!=label[0]:
prog0.insert(simulate_one_term(qubit_list,j, self.Hp.ops[j],2*self.gamma[i]))
prog1.insert(simulate_one_term(qubit_list,j, self.Hp.ops[j],2*self.gamma[i]))
else:
prog0.insert(simulate_one_term(qubit_list,j, self.Hp.ops[j],2*self.gamma[i]+pi/2/self.Hp.ops[j]))
prog1.insert(simulate_one_term(qubit_list,j, self.Hp.ops[j],2*self.gamma[i]-pi/2/self.Hp.ops[j]))
prog0.insert(pauliX_model(qubit_list,self.beta[i]))
prog1.insert(pauliX_model(qubit_list,self.beta[i]))
elif label[1]==1: