Skip to content

Implement PauliStringPhasorGate #4696

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

Merged
merged 31 commits into from
Dec 20, 2021
Merged

Implement PauliStringPhasorGate #4696

merged 31 commits into from
Dec 20, 2021

Conversation

daxfohl
Copy link
Collaborator

@daxfohl daxfohl commented Nov 22, 2021

BREAKING CHANGE: PauliStringPhasor no longer inherits from PauliStringGateOperation.

Implements PauliStringPhasor in terms of a GateOperation on a new class PauliStringPhasorGate.

Mostly involved moving existing functions from the operation to the gate, and then having the operation call those methods under the hood.

Closes #1561, xref #4683

@tanujkhattar

@daxfohl daxfohl requested review from cduck, vtomole and a team as code owners November 22, 2021 18:21
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Nov 22, 2021
@daxfohl daxfohl requested a review from dabacon November 22, 2021 18:21
@CirqBot CirqBot added the size: M 50< lines changed <250 label Nov 22, 2021
@tanujkhattar tanujkhattar self-assigned this Nov 22, 2021
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.

A first round of high level comments. My main question is that whether we can fix these inconsistencies at a higher level; i.e.

Q1: Can we make PauliString a GateOperation ?

Q2: Can we make PauliStringGateOperation a GateOperation or deprecate it after this change?

@daxfohl
Copy link
Collaborator Author

daxfohl commented Nov 22, 2021

Q1: Can we make PauliString a GateOperation ?

I didn't notice that it wasn't (it has a gate field). It would be nice if we could. I'll look into that separately. I don't think it would affect what we do in this PR, but would be good to verify. Edit: I looked at PauliString and I think it's fine as-is. Having a gate is the important thing, whether or not it inherits GateOperation.

Q2: Can we make PauliStringGateOperation a GateOperation or deprecate it after this change?

I think we should deprecate it. It doesn't appear to be a useful abstraction, it just provides some convenience functions that should probably be module-level, if anything. That said, we may want an interface ContainsPauliString that could be used for anything that has a pauli_string property.

@daxfohl
Copy link
Collaborator Author

daxfohl commented Nov 23, 2021

@tanujkhattar Here's a slightly different approach where we don't break the inheritance from PauliStringGateOperation. https://github.com/quantumlib/Cirq/compare/master...daxfohl:gates-psp2?expand=1. This would be safer, I think, and follows the precedent of PauliString, in that it doesn't inherit GateOperation, but still provides a gate. (As I mentioned above, to me having a gate is the important thing; it doesn't matter whether it inherits GateOperation or not).

It's a little more redundant, since it has to do all the protocol forwarding. But safer since it doesn't break the hierarchy. I do see a couple places in the code where isinstance(PauliStringGateOperation) is used. So it's probably better to be safe here. If we want to deprecate PauliStringGateOperation later and change the hierarchy, we can do that separately. But I don't see a particular need to rush that.

(Ideally we could make PauliStringGateOperation inherit GateOperation and have the best of both worlds. But I can't think of a way to do that since it is not guaranteed to have a gate. Unless we give it a dummy NoOpGate if nothing else is provided.)

What do you think? Should we go with this alternate approach?

@daxfohl
Copy link
Collaborator Author

daxfohl commented Dec 1, 2021

Per cirq-sync notes it sounds like we'd prefer the breaking change. I'll revert to the previous implementation here, and then make sure everywhere our code has isinstance(PauliStringGateOperation) also handles GateOperation[PauliStringPhasorGate].

This reverts commit 6f68dbb, reversing
changes made to d5cf5b0.
@daxfohl
Copy link
Collaborator Author

daxfohl commented Dec 15, 2021

Reverted this to bring back the hard break from PauliStringGateOperation as we'd discussed in cirq-sync noted above. @tanujkhattar

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.

Looking pretty good. Left a final round of comments.

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.

Final round of comments. Thanks for the iterations!

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.

LGTM

@tanujkhattar tanujkhattar added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Dec 20, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Dec 20, 2021
@CirqBot CirqBot merged commit 1d8d2f3 into quantumlib:master Dec 20, 2021
@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 Dec 20, 2021
@tanujkhattar tanujkhattar added the BREAKING CHANGE For pull requests that are important to mention in release notes. label Dec 20, 2021
@daxfohl daxfohl deleted the gates-psp branch December 21, 2021 02:39
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this pull request Jan 22, 2022
BREAKING CHANGE: PauliStringPhasor no longer inherits from PauliStringGateOperation.

Implements PauliStringPhasor in terms of a GateOperation on a new class PauliStringPhasorGate.

Mostly involved moving existing functions from the operation to the gate, and then having the operation call those methods under the hood.

Closes quantumlib#1561, xref quantumlib#4683

@tanujkhattar
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
BREAKING CHANGE: PauliStringPhasor no longer inherits from PauliStringGateOperation.

Implements PauliStringPhasor in terms of a GateOperation on a new class PauliStringPhasorGate.

Mostly involved moving existing functions from the operation to the gate, and then having the operation call those methods under the hood.

Closes quantumlib#1561, xref quantumlib#4683

@tanujkhattar
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
BREAKING CHANGE: PauliStringPhasor no longer inherits from PauliStringGateOperation.

Implements PauliStringPhasor in terms of a GateOperation on a new class PauliStringPhasorGate.

Mostly involved moving existing functions from the operation to the gate, and then having the operation call those methods under the hood.

Closes quantumlib#1561, xref quantumlib#4683

@tanujkhattar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING CHANGE For pull requests that are important to mention in release notes. cla: yes Makes googlebot stop complaining. size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PauliStringPhasor should be a Gate
3 participants