Skip to content

Commit

Permalink
fix phase_by protocol for tagged operations (#6792)
Browse files Browse the repository at this point in the history
`cirq.phase_by` can return a default value for operation that cannot be phased,
but that was broken for tagged operations.  Here is a fix for that.

Fixes #6791
  • Loading branch information
richrines1 authored Nov 14, 2024
1 parent 30f5b48 commit dc8a43b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cirq-core/cirq/ops/raw_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,9 @@ def _trace_distance_bound_(self) -> float:
return protocols.trace_distance_bound(self.sub_operation)

def _phase_by_(self, phase_turns: float, qubit_index: int) -> 'cirq.Operation':
return protocols.phase_by(self.sub_operation, phase_turns, qubit_index)
return protocols.phase_by(
self.sub_operation, phase_turns, qubit_index, default=NotImplemented
)

def __pow__(self, exponent: Any) -> 'cirq.Operation':
return self.sub_operation**exponent
Expand Down
2 changes: 2 additions & 0 deletions cirq-core/cirq/ops/raw_types_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,8 @@ def test_tagged_operation_forwards_protocols():
assert cirq.commutes(tagged_x, clifford_x)
assert cirq.commutes(clifford_x, tagged_x)
assert cirq.commutes(tagged_x, tagged_x)
assert cirq.phase_by(clifford_x, 0.125, 0, default=None) is None
assert cirq.phase_by(tagged_x, 0.125, 0, default=None) is None

assert cirq.trace_distance_bound(y**0.001) == cirq.trace_distance_bound(
(y**0.001).with_tags(tag)
Expand Down

0 comments on commit dc8a43b

Please sign in to comment.