Skip to content
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

Merged
merged 15 commits into from
May 5, 2022

Conversation

vtomole
Copy link
Collaborator

@vtomole vtomole commented May 3, 2022

Fixes: #4570

Follow up on review of #4606

@vtomole vtomole requested review from a team and cduck as code owners May 3, 2022 23:05
@vtomole vtomole requested a review from dabacon May 3, 2022 23:05
@CirqBot CirqBot added the size: S 10< lines changed <50 label May 3, 2022
@tanujkhattar tanujkhattar self-assigned this May 3, 2022
@vtomole vtomole requested a review from tanujkhattar May 3, 2022 23:17
Copy link
Collaborator

@tanujkhattar tanujkhattar left a 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
Copy link
Collaborator Author

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]:
Copy link
Collaborator Author

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',
Copy link
Collaborator Author

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':
Copy link
Collaborator Author

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 (
Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

@vtomole vtomole requested a review from tanujkhattar May 4, 2022 20:40
@tanujkhattar tanujkhattar added automerge Tells CirqBot to sync and merge this PR. (If it's running.) and removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) labels May 4, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label May 5, 2022
@CirqBot CirqBot merged commit e7207a2 into quantumlib:master May 5, 2022
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels May 5, 2022
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PhasedISwapPowGate constructor does not take global_shift
4 participants