Skip to content

Commit 21c813d

Browse files
restrict identity check to other.gate
1 parent 9c55a61 commit 21c813d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

cirq-core/cirq/ops/linear_combinations.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from cirq import linalg, protocols, qis, value
3131
from cirq._doc import document
3232
from cirq.linalg import operator_spaces
33-
from cirq.ops import identity, raw_types, pauli_gates, pauli_string, gate_operation
33+
from cirq.ops import identity, raw_types, pauli_gates, pauli_string
3434
from cirq.ops.pauli_string import PauliString, _validate_qubit_mapping
3535
from cirq.value.linear_dict import _format_terms
3636

@@ -570,10 +570,11 @@ def __iadd__(self, other):
570570
return self
571571

572572
def __add__(self, other):
573-
if isinstance(other, (gate_operation.GateOperation)):
574-
other = PauliString(other)
575573
if not isinstance(other, (numbers.Complex, PauliString, PauliSum)):
576-
return NotImplemented
574+
if hasattr(other, 'gate') and isinstance(other.gate, identity.IdentityGate):
575+
other = PauliString(other)
576+
else:
577+
return NotImplemented
577578
result = self.copy()
578579
result += other
579580
return result

0 commit comments

Comments
 (0)