-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add XPow/YPow/ZPow
and factor out CirqGateAsBloqBase
#469
Conversation
This LGTM % nits. The more standard rotation bloqs are preserved, which is good! |
should we remove/replace the existing Rx,Ry,Rz? I'm not a huge fan of the "pow" nomenclature since I don't think this has really caught on outside of Cirq; but this matches cirq so I can see why we'd want to keep the name |
Why would we remove them? It's convenient having the textbook rotation gates around no? |
Yeah, I don't think we should remove them. We can probably make them derive from |
… Address other nits
@mpharrigan @fdmalone This is ready for a re-review |
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.
I think this LGTM. It took me a second to get the inheritance straight in my head but I think this is nice. Presumably we may want to replace various other single-qubit bloqs this way?
That's right, and this approach can be used for multi qubit cirq-core gates as well (like XX, YY, ZZ, etc.); the exact same code will work. |
@@ -53,34 +54,36 @@ def _get_cirq_quregs(signature: Signature, qm: InteropQubitManager): | |||
return ret | |||
|
|||
|
|||
@frozen | |||
class CirqGateAsBloq(GateWithRegisters): | |||
class CirqGateAsBloqBase(GateWithRegisters): |
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.
don't you need to mark this as abstract? even if the metaclass is inherited, it would probably help for documenting
gate: cirq.Gate | ||
@property | ||
@abc.abstractmethod | ||
def cirq_gate(self) -> cirq.Gate: |
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.
update class docstring .. this is no longer a wrapper, right? it's something else
XPow/YPow/ZPow
rotations gateXPow/YPow/ZPow
and factor out CirqGateAsBloqBase
XPow/YPow/ZPow
and factor out CirqGateAsBloqBaseXPow/YPow/ZPow
and factor out CirqGateAsBloqBase
class CirqGateAsBloq(CirqGateAsBloqBase): | ||
gate: cirq.Gate |
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.
docstring!
post-hoc review; would appreciate if you could open a small follow-up pr |
This PR does a bunch of changes/improvements in cirq interop
CirqGateAsBloqBase
abstract class which has all the functionality to auto populate the bloq methods using underlying Cirq gates. There is one abstract method calledcirq_gate
which can be over-riden by derived classes.CirqGateAsBloq
simply derives fromCirqGateAsBloqBase
and uses the user specifiedself.gate
as the correspondingcirq_gate
.CirqGateAsBloqBase
class and specify a custom cirq gate as thecirq_gate
property. For commonly used gates in Cirq-Core, this inheritance based method for wrapping cirq gates solves the discoverability issue and reduces boilerplace code.rotations.py
file to wrapRx / Ry / Rz / XPow / YPow / ZPow
gates. As you can see, the wrapper code is now much simpler.Register(qubits, shape=(nqubits), bitsize=1)
toRegister('q', shape=(nqubits), bitsize=1)
ifnqubits > 1
orRegister('q', shape=(), bitsize=1)
if nqbits = 1. Changingqubits
toq
is nicer because we don't need to worry about singular / plural when number of qubits are > 1 or = 1.The
XPow/YPow/ZPow
gates have an option to configure the global phase and follow a pattern similar to Cirq. These gates are useful when implementing phase gradient states. Docstrings for these gates are copied over from Cirq.As a follow up, we can also consider making these new gates implementation more robust so we can get rid of
XGate
/YGate
/ZGate
that also currently exist.