Skip to content

Commit

Permalink
Use NotImplemented instead of None as default value for `TaggedOp…
Browse files Browse the repository at this point in the history
…eration._unitary_` (#4795)

This makes the implementation of `_unitary_` method on `TaggedOperation` consistent with other protocols like `_mixture_` and `_kraus_`.
  • Loading branch information
tanujkhattar authored Jan 4, 2022
1 parent 1d76e50 commit 7d6ba34
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/raw_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ def _has_unitary_(self) -> bool:
return protocols.has_unitary(self.sub_operation)

def _unitary_(self) -> Union[np.ndarray, NotImplementedType]:
return protocols.unitary(self.sub_operation, default=None)
return protocols.unitary(self.sub_operation, NotImplemented)

def _commutes_(
self, other: Any, *, atol: Union[int, float] = 1e-8
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/ops/raw_types_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,9 @@ def test_tagged_operation_forwards_protocols():
assert cirq.resolve_parameters_once(parameterized_op, resolver) == cirq.XPowGate(exponent=0.25)(
q1
).with_tags(tag)
assert parameterized_op._unitary_() is NotImplemented
assert parameterized_op._mixture_() is NotImplemented
assert parameterized_op._kraus_() is NotImplemented

y = cirq.Y(q1)
tagged_y = cirq.Y(q1).with_tags(tag)
Expand Down

0 comments on commit 7d6ba34

Please sign in to comment.