fix: forgot to reset state object in computing different observables
This commit is contained in:
@@ -241,22 +241,22 @@ def exp_value_observable_symbolic(
|
|||||||
"within a single term (e.g. (0,0,0) is invalid).",
|
"within a single term (e.g. (0,0,0) is invalid).",
|
||||||
)
|
)
|
||||||
|
|
||||||
ket = self._qibo_circuit_to_quimb(
|
circuit_tn = self._qibo_circuit_to_quimb(
|
||||||
circuit,
|
circuit,
|
||||||
quimb_circuit_type=self.circuit_ansatz,
|
quimb_circuit_type=self.circuit_ansatz,
|
||||||
gate_opts={"max_bond": self.max_bond_dimension, "cutoff": self.svd_cutoff},
|
gate_opts={"max_bond": self.max_bond_dimension, "cutoff": self.svd_cutoff},
|
||||||
).psi
|
).psi
|
||||||
|
bra = circuit_tn.copy().H
|
||||||
bra = ket.copy().H
|
|
||||||
|
|
||||||
expectation_value = 0.0
|
expectation_value = 0.0
|
||||||
for opstr, sites, coeff in zip(operators_list, sites_list, coeffs_list):
|
for opstr, sites, coeff in zip(operators_list, sites_list, coeffs_list):
|
||||||
|
ket = circuit_tn.copy()
|
||||||
coeff = coeff.real
|
coeff = coeff.real
|
||||||
for label, site in zip(opstr, sites):
|
for label, site in zip(opstr, sites):
|
||||||
op_matrix = qu.pauli(label.upper())
|
op_matrix = qu.pauli(label.upper())
|
||||||
ket.gate_(op_matrix, site)
|
ket.gate_(op_matrix, site)
|
||||||
exp_values = (bra & ket).contract(optimize="auto-hq").real
|
exp_value = (bra & ket).contract(optimize="auto-hq").real
|
||||||
expectation_value = expectation_value + coeff * exp_values
|
expectation_value = expectation_value + coeff * exp_value
|
||||||
|
|
||||||
return expectation_value
|
return expectation_value
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user