Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When state has few terms compared with operator, faster to do direct… #173

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions symmer/operators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,16 +829,19 @@ def expval(self, psi: "QuantumState") -> complex:
Returns:
complex: The expectation value.
"""
if self.n_terms > 1:
@process.parallelize
def f(P, psi):
return single_term_expval(P, psi)

expvals = np.array(f(self, psi))
if self.n_terms > psi.n_terms:
return (psi.dagger * self * psi).real
else:
expvals = np.array(single_term_expval(self, psi))
if self.n_terms > 1:
@process.parallelize
def f(P, psi):
return single_term_expval(P, psi)

expvals = np.array(f(self, psi))
else:
expvals = np.array(single_term_expval(self, psi))

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

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