-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add assert_specifies_has_unitary_if_unitary
to consistency tests
#1759
Conversation
# Conflicts: # cirq/testing/consistent_protocols.py
Is this intended to change the protocol to require |
It's intended to ensure we always use it within cirq |
@@ -33,6 +33,9 @@ def __init__(self, | |||
self.phase_exponent = cirq.canonicalize_half_turns(phase_exponent) | |||
self.exponent = exponent | |||
|
|||
def _has_unitary_(self): | |||
return not cirq.is_parameterized(self) | |||
|
|||
def _unitary_(self) -> Union[np.ndarray, NotImplementedType]: | |||
if cirq.is_parameterized(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Inconsistent with other places.
@@ -33,6 +33,9 @@ def __init__(self, | |||
self.phase_exponent = cirq.canonicalize_half_turns(phase_exponent) | |||
self.exponent = exponent | |||
|
|||
def _has_unitary_(self): | |||
return not cirq.is_parameterized(self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Inconsistent with other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How so?
cirq/ops/fsim_gate.py
Outdated
@@ -66,6 +66,9 @@ def _is_parameterized_(self): | |||
return cirq.is_parameterized(self.theta) or cirq.is_parameterized( | |||
self.phi) | |||
|
|||
def _has_unitary_(self): | |||
return not self._is_parameterized_() | |||
|
|||
def _unitary_(self) -> Optional[np.ndarray]: | |||
if cirq.is_parameterized(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Inconsistent with other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Often self._is_parameterized_()
is used instead.
Ping @Strilanc. |
# Conflicts: # cirq/ops/common_gates.py # cirq/ops/matrix_gates.py # cirq/ops/raw_types.py # cirq/testing/consistent_protocols.py
# Conflicts: # cirq/ops/identity.py
Ping @cduck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just one qudit compatibility issue.
cirq/ops/fsim_gate.py
Outdated
@@ -66,6 +66,9 @@ def _is_parameterized_(self): | |||
return cirq.is_parameterized(self.theta) or cirq.is_parameterized( | |||
self.phi) | |||
|
|||
def _has_unitary_(self): | |||
return not self._is_parameterized_() | |||
|
|||
def _unitary_(self) -> Optional[np.ndarray]: | |||
if cirq.is_parameterized(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Often self._is_parameterized_()
is used instead.
cirq/ops/raw_types.py
Outdated
@@ -449,6 +449,14 @@ def _decompose_(self, qubits): | |||
return protocols.inverse( | |||
protocols.decompose_once_with_qubits(self._original, qubits)) | |||
|
|||
def _has_unitary_(self): | |||
from cirq import protocols, devices | |||
qubits = devices.LineQubit.range(self._num_qubits_()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be LineQid.for_gate(self)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
# Conflicts: # cirq/ops/pauli_string_phasor.py
Done |
Automerge cancelled: A status check is failing. |
Did you intentionally remove IdentityOperation.gate or is that a merge issue? |
It was a merge issue |
Automerge cancelled: There are merge conflicts. |
Ping @Strilanc. |
# Conflicts: # docs/api.rst
Automerge cancelled: A status check is failing. |
# Conflicts: # cirq/ops/identity.py # cirq/ops/raw_types_test.py # cirq/testing/consistent_protocols.py
Automerge cancelled: A status check is failing. |
No description provided.