Skip to content

Commit

Permalink
Removed the .real in expval, since PauliwordOp may have complex coeff…
Browse files Browse the repository at this point in the history
…icients in which case this would produce the wrong value.
  • Loading branch information
TimWeaving committed Jan 21, 2025
1 parent 813079b commit 517de3f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions symmer/operators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def expval(self, psi: "QuantumState") -> complex:
complex: The expectation value.
"""
if self.n_terms > psi.n_terms and psi.n_terms > 10:
return (psi.dagger * self * psi).real
return psi.dagger * self * psi
else:
if self.n_terms > 1:
@process.parallelize
Expand All @@ -807,7 +807,7 @@ def f(P, psi):
else:
expvals = np.array(single_term_expval(self, psi))

return np.sum(expvals * self.coeff_vec).real
return np.sum(expvals * self.coeff_vec)

def __mul__(self,
mul_obj: Union["PauliwordOp", "QuantumState", complex],
Expand Down

0 comments on commit 517de3f

Please sign in to comment.