Skip to content

Commit 99993b9

Browse files
authoredDec 20, 2023
Check identity first when comparing moments (#6388)
1 parent a2530fe commit 99993b9

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed
 

‎cirq-core/cirq/circuits/moment.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,14 @@ def __eq__(self, other) -> bool:
343343
if not isinstance(other, type(self)):
344344
return NotImplemented
345345

346-
return self._sorted_operations_() == other._sorted_operations_()
346+
return self is other or self._sorted_operations_() == other._sorted_operations_()
347347

348348
def _approx_eq_(self, other: Any, atol: Union[int, float]) -> bool:
349349
"""See `cirq.protocols.SupportsApproximateEquality`."""
350350
if not isinstance(other, type(self)):
351351
return NotImplemented
352352

353-
return protocols.approx_eq(
353+
return self is other or protocols.approx_eq(
354354
self._sorted_operations_(), other._sorted_operations_(), atol=atol
355355
)
356356

@@ -510,13 +510,11 @@ def _from_json_dict_(cls, operations, **kwargs):
510510
return cls.from_ops(*operations)
511511

512512
def __add__(self, other: 'cirq.OP_TREE') -> 'cirq.Moment':
513-
514513
if isinstance(other, circuits.AbstractCircuit):
515514
return NotImplemented # Delegate to Circuit.__radd__.
516515
return self.with_operations(other)
517516

518517
def __sub__(self, other: 'cirq.OP_TREE') -> 'cirq.Moment':
519-
520518
must_remove = set(op_tree.flatten_to_ops(other))
521519
new_ops = []
522520
for op in self.operations:

0 commit comments

Comments
 (0)
Please sign in to comment.