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 _phase_by_ method to ZZPowGate #6062

Merged
merged 3 commits into from
Apr 14, 2023
Merged

Conversation

richrines1
Copy link
Contributor

@richrines1 richrines1 commented Apr 13, 2023

this was motivated by cirq.eject_z failing to commute through ZZPowGates, for example:

circuit = cirq.Circuit(
    cirq.Z(cirq.q(1)),
    cirq.ZZ(cirq.q(0), cirq.q(1)) ** 0.5,
    cirq.Z(cirq.q(1)),
)
print(cirq.eject_z(circuit))

output before:

0: ───────ZZ───────────
          │
1: ───Z───ZZ^0.5───Z───

output after adding _phase_by_:

0: ───ZZ───────
      │
1: ───ZZ^0.5───

(ZZPowGate is diagonal so this implementation is trivial)

@richrines1 richrines1 requested review from a team, vtomole and cduck as code owners April 13, 2023 20:12
@richrines1 richrines1 requested a review from maffoo April 13, 2023 20:12
@google-cla
Copy link

google-cla bot commented Apr 13, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@CirqBot CirqBot added the Size: XS <10 lines changed label Apr 13, 2023
Copy link
Collaborator

@viathor viathor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two comments:

  • Please sign the CLA.
  • Optional: It'd be good to add a unit test (e.g. comparing the outcome of _phase_by_ to a circuit that conjugates ZZPowGate).

@richrines1
Copy link
Contributor Author

* Please sign the CLA.

done.

* Optional: It'd be good to add a unit test (e.g. comparing the outcome of `_phase_by_` to a circuit that conjugates `ZZPowGate`).

added a simple test (which just checks that the output of cirq.phase_by() is now the same as the input). it looks like the result is already checked against the unitary obtained via explicit conjugation as part of assert_eigengate_implements_consistent_protocols - do you think it's worth adding another test like that here or is this sufficient?

Copy link
Collaborator

@viathor viathor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@viathor viathor merged commit ee2d32a into quantumlib:master Apr 14, 2023
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: XS <10 lines changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants