Skip to content

fix for issue #4087 #4103

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

Merged
merged 4 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion cirq-core/cirq/ops/linear_combinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,10 @@ def __iadd__(self, other):

def __add__(self, other):
if not isinstance(other, (numbers.Complex, PauliString, PauliSum)):
return NotImplemented
if hasattr(other, 'gate') and isinstance(other.gate, identity.IdentityGate):
other = PauliString(other)
else:
return NotImplemented
result = self.copy()
result += other
return result
Expand Down
4 changes: 4 additions & 0 deletions cirq-core/cirq/ops/linear_combinations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,10 @@ def test_paulisum_validation():
ld = cirq.LinearDict({key: 2.0})
assert cirq.PauliSum(ld) == cirq.PauliSum.from_pauli_strings([2 * cirq.X(q[0])])

ps = cirq.PauliSum()
ps += cirq.I(cirq.LineQubit(0))
assert ps == cirq.PauliSum(cirq.LinearDict({frozenset(): complex(1)}))


def test_add_number_paulisum():
q = cirq.LineQubit.range(2)
Expand Down