Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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:
'''
Hd:beta
'''
prog0.insert(simulate_pauliZ_hamiltonian(qubit_list,self.Hp,2*self.gamma[i]))
prog1.insert(simulate_pauliZ_hamiltonian(qubit_list,self.Hp,2*self.gamma[i]))
for j in range(self.qnum):
if j!=label[0]:
prog0.insert(RX(qubit_list[j],self.beta[i]*2))
prog1.insert(RX(qubit_list[j],self.beta[i]*2))
else:
prog0.insert(RX(qubit_list[j],self.beta[i]*2+pi/2))
prog1.insert(RX(qubit_list[j],self.beta[i]*2-pi/2))
actual_qlist=[]
for i in label[3]:
actual_qlist.append(qubit_list[i[1]])
expectation0=get_one_expectation_component(prog0,actual_qlist)
expectation1=get_one_expectation_component(prog1,actual_qlist)
return (expectation0-expectation1)/2*coef