-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Implement GlobalPhaseGate #4697
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.
-
Should we deprecate
GlobalPhaseOperation
in favour ofGlobalPhaseGate
? I don't think we need to keep both. -
I'd like to see what other maintainers think about the paradigm shift here -- i.e. we are introducing the first gate in Cirq which should be applied to an empty set of qubits (i.e.
op = GlobalPhaseGate(1j).on()
).
cc @dstrain115 @MichaelBroughton Thoughts?
It came up during discussion on Cirq sync that |
That seems like a different kind of gate though, like a TargetedPhaseShiftGate, right? GlobalPhaseGate with no qubits is designed to be a drop-in replacement for GlobalPhaseOp. If we start saying GlobalPhaseGate has different behaviors than GlobalPhaseOp depending on what qubits you provide, then the migration path is much rougher (or impossible in cases where you don't know your qubits in advance). |
That's right. The comment was that we should probably work directly towards deprecating |
Would we need to deprecate one over the other though? Would we not keep both? Or was the idea of a GlobalPhaseOp just unsound from the start? If we do need to replace it with something else, what does that new thing do with the qubits it is given? I'm not seeing how those qubits affect the unitary or are otherwise used. |
The original concern I had in mind was that things might not behave as expected if we have a However, on digging a bit more, it seems like this particular use case works as expected right now because controlled CircuitOperations decompose into controlled versions of the underlying operations in the circuit and a controlled global phase op behaves like a z rotation, which is expected. We should still add a custom cc @95-martin-orion Since you originally brought this up in the cirq sync -- do you see any other case where the combination of GlobalPhaseOperation + CircuitOperation isn't behaving as expected? |
You hit the main case I was concerned about, that being the different meanings of "global" when nesting circuits. |
So what I'm hearing is that since the existing behavior of GlobalPhaseOp is "local" as desired when placed in a controlled subcircuit, we can give GlobalPhaseGate the exact same implementation, meaning there is no need to have it accept qubits in the constructor because they would have no effect and would just be confusing. Is that a correct interpretation? Should the name be changed to "PhaseShiftGate", so as not to imply a truly global behavior? |
Yes, that's right. I'd prefer to stick with |
That made this PR go from medium to 32 files :) but most of the changes were mechanical. Change GlobalPhaseOp() -> global_phase_op(), and isinstance(x.untagged, GlobalPhaseOp) -> isinstance(x.gate, GlobalPhaseGate). |
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.
Looks good overall. Left a round of comments, mainly around using GlobalPhaseGate in Gateset.
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.
LGTM
Implements GlobalPhaseOperation in terms of a GateOperation on a new class GlobalPhaseGate. Mostly involved moving existing functions from the operation to the gate, and then having the operation call those methods under the hood.
Implements GlobalPhaseOperation in terms of a GateOperation on a new class GlobalPhaseGate. Mostly involved moving existing functions from the operation to the gate, and then having the operation call those methods under the hood.
Implements GlobalPhaseOperation in terms of a GateOperation on a new class GlobalPhaseGate. Mostly involved moving existing functions from the operation to the gate, and then having the operation call those methods under the hood.
Implements GlobalPhaseOperation in terms of a GateOperation on a new class GlobalPhaseGate.
Mostly involved moving existing functions from the operation to the gate, and then having the operation call those methods under the hood.
xref #4683
@tanujkhattar