-
Notifications
You must be signed in to change notification settings - Fork 983
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 global_shift
parameter to PhasedISwapPowGate
#5328
Conversation
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.
We should also update, and add tests, for the following methods:
_decompose_
: Decompose preserving global phase._json_dict_
: Json serialization should also include global_shift. We should make sure deserialization of old objects still works.- Add tests for value equality of gates with non-zero global shift (which should work correctly because it depends upon
self._iswap._value_equality_values_
) _with_exponent
should preserve the global_shift.- Add tests for pauli expansion with non-zero global shift
@@ -144,7 +156,7 @@ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE': | |||
|
|||
yield cirq.Z(a) ** self.phase_exponent | |||
yield cirq.Z(b) ** -self.phase_exponent | |||
yield cirq.ISWAP(a, b) ** self.exponent | |||
yield cirq.ISwapPowGate(global_shift=self.global_shift).on(a, b) ** self.exponent |
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.
_decompose_
: Decompose preserving global phase.
Done.
@@ -75,7 +78,11 @@ def _num_qubits_(self) -> int: | |||
return 2 | |||
|
|||
def _json_dict_(self) -> Dict[str, Any]: |
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.
_json_dict_
: Json serialization should also include global_shift. We should make sure deserialization of old objects still works.
Done.
@@ -96,28 +115,30 @@ def test_decompose_invalid_qubits(): | |||
|
|||
|
|||
@pytest.mark.parametrize( | |||
'phase_exponent, exponent', | |||
'phase_exponent, exponent, global_shift', |
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.
Add tests for pauli expansion with non-zero global shift
Done.
@@ -106,7 +113,9 @@ def _resolve_parameters_( | |||
) | |||
|
|||
def _with_exponent(self, exponent: value.type_alias.TParamVal) -> 'PhasedISwapPowGate': |
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.
_with_exponent
should preserve the global_shift.
Done.
|
||
|
||
def test_phased_iswap_equality(): | ||
assert cirq.PhasedISwapPowGate(phase_exponent=0, exponent=0.4) == cirq.ISWAP**0.4 | ||
assert ( |
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.
Add tests for value equality of gates with non-zero global shift (which should work correctly because it depends upon
self._iswap._value_equality_values_
)
Done.
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.
Also add a test for inequality
cirq.PhasedISwapPowGate(phase_exponent=0, exponent=0.4, global_shift=0.3) != cirq.ISWAP ** 0.4
It would be better to use EqualsTester if we can.
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.
It would be better to use EqualsTester if we can.
Done.
Fixes: quantumlib#4570 Follow up on review of quantumlib#4606
Fixes: #4570
Follow up on review of #4606