-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Clean up redundant complex type unions #7041
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -271,9 +271,7 @@ def __mul__(self, other: 'cirq.Operation') -> 'cirq.PauliString[Union[TKey, cirq | |||||
pass | ||||||
|
||||||
@overload | ||||||
def __mul__( | ||||||
self, other: Union[complex, int, float, numbers.Number] | ||||||
) -> 'cirq.PauliString[TKey]': | ||||||
def __mul__(self, other: Union[complex, numbers.Number]) -> 'cirq.PauliString[TKey]': | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am getting True for
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here also I went the opposite direction. |
||||||
pass | ||||||
|
||||||
def __mul__(self, other): | ||||||
|
@@ -518,7 +516,7 @@ def _unitary_(self) -> Optional[np.ndarray]: | |||||
def _apply_unitary_(self, args: 'protocols.ApplyUnitaryArgs'): | ||||||
if not self._has_unitary_(): | ||||||
return None | ||||||
assert isinstance(self.coefficient, complex) | ||||||
assert isinstance(self.coefficient, numbers.Complex) | ||||||
if self.coefficient != 1: | ||||||
args.target_tensor *= self.coefficient | ||||||
return protocols.apply_unitaries([self[q].on(q) for q in self.qubits], self.qubits, args) | ||||||
|
@@ -792,9 +790,11 @@ def __pos__(self) -> 'PauliString': | |||||
return self | ||||||
|
||||||
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): | ||||||
"""Override behavior of numpy's exp method.""" | ||||||
"""Override numpy behavior.""" | ||||||
if ufunc == np.exp and len(inputs) == 1 and inputs[0] is self: | ||||||
return math.e**self | ||||||
if ufunc == np.multiply and len(inputs) == 2 and inputs[1] is self: | ||||||
return self * inputs[0] | ||||||
return NotImplemented | ||||||
|
||||||
def __pow__(self, power): | ||||||
|
@@ -1174,14 +1174,14 @@ def _as_pauli_string(self) -> PauliString: | |||||
def __mul__(self, other): | ||||||
if isinstance(other, SingleQubitPauliStringGateOperation): | ||||||
return self._as_pauli_string() * other._as_pauli_string() | ||||||
if isinstance(other, (PauliString, complex, float, int)): | ||||||
if isinstance(other, (PauliString, numbers.Complex)): | ||||||
return self._as_pauli_string() * other | ||||||
if (as_pauli_string := _try_interpret_as_pauli_string(other)) is not None: | ||||||
return self * as_pauli_string | ||||||
return NotImplemented | ||||||
|
||||||
def __rmul__(self, other): | ||||||
if isinstance(other, (PauliString, complex, float, int)): | ||||||
if isinstance(other, (PauliString, numbers.Complex)): | ||||||
return other * self._as_pauli_string() | ||||||
if (as_pauli_string := _try_interpret_as_pauli_string(other)) is not None: | ||||||
return as_pauli_string * 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.
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.
I actually went the opposite direction. The function fails on complex numbers (there's a mod operation in it), so I'm not sure why complex was an option at all.