-
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
Add cirq.eject_phased_paulis
transformer to replace cirq.EjectPhasedPaulis
#4958
Add cirq.eject_phased_paulis
transformer to replace cirq.EjectPhasedPaulis
#4958
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
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.
A few nits and then two bigger feedback points:
- We should probably have this work with PhasedXZ
- Is there a change in behavior on the old transformer that we should fix ?
cirq-core/cirq/transformers/analytical_decompositions/two_qubit_to_cz.py
Show resolved
Hide resolved
atol: float = 1e-8, | ||
eject_parameterized: bool = False, | ||
) -> 'cirq.Circuit': | ||
"""Transformer pass to push X, Y, and PhasedX gates towards the end of the circuit. |
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.
This can probably be made to include PhasedXZ gates as well.
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.
Added support for PhasedXZ
gates with z_exponent = 0 (which are equivalent to PhasedX gates). Added a test which demonstrates how to deal with a general PhasedXZGate
, i.e.
run cirq.eject_z(cirq.eject_phased_paulis(cirq.eject_z(c)))
.
cirq.eject_z(c)
: This ejects Z gates and ensures that thez_component
ofPhasedXZGate
is 0.cirq.eject_phased_paulis(c)
: This ejectsPhasedXPowGates
, potentially leaving z phased from CZ phase kickback, which will then be removed by the 3rdcirq.eject_z()
.
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.
Awesome, could we also support the case where axis_exponent=0 and x_exponent=0 but z_exponent can be whatever we want ? This seems like it might be able to be worked into _try_get_known_z_half_turns
without much difficulty ?
@MichaelBroughton Addressed Feedback, ready for another look. |
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, two concerns now are:
- Can we accomodate the PhasedXZ case where axis_exponent=0 and x_xeponent=0 (aka just a Z).
- Can we double check that CCO behave themselves when they are the operations that are getting moved (it's good that things work when they aren't getting moved) ?
atol: float = 1e-8, | ||
eject_parameterized: bool = False, | ||
) -> 'cirq.Circuit': | ||
"""Transformer pass to push X, Y, and PhasedX gates towards the end of the circuit. |
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.
Awesome, could we also support the case where axis_exponent=0 and x_exponent=0 but z_exponent can be whatever we want ? This seems like it might be able to be worked into _try_get_known_z_half_turns
without much difficulty ?
atol: float = 1e-8, | ||
eject_parameterized: bool = False, | ||
) -> 'cirq.Circuit': | ||
"""Transformer pass to push X, Y, and PhasedX gates towards the end of the circuit. |
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.
Might want to also mention PhasedXZGates in the topline of the docstring.
[cirq.PhasedXPowGate(phase_exponent=0.25).on(a)], | ||
[cirq.measure(a, key="m")], | ||
[cirq.X(b).with_classical_controls("m")], |
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.
What would be the expected output for something like ?
[cirq.PhasedXPowGate(phase_exponent=0.25).on(a)],
[cirq.measure(a, key="m")],
[cirq.X(b).with_classical_controls("m")],
[cirq.measure(b, key='m2')]
?
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.
cirq.X(b).with_classical_controls
will be unaffected because op.gate
is None for CCOs. The first PhasedXPowGate
will get absorbed into the measurement. So, the output will be:
a: ───!M─────────────────
║
b: ───╫────X───M('m2')───
║ ║
m: ═══@════^═════════════
circuit: 'cirq.AbstractCircuit', | ||
*, | ||
context: Optional['cirq.TransformerContext'] = None, | ||
atol: float = 1e-8, |
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.
This seems a little tight, floats are usually only good up to 1e-6 or so.
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.
1e-8 tolerance is standard across the codebase, try running grep -RI '1e-8' --include \*.py
.
|
…edPaulis` (quantumlib#4958) * Add cirq.eject_phased_paulis transformer to replace cirq.EjectPhasedPaulis * Add CCO tests, support PhasedXZGates * Support PhasedXZGates equivalent to z rotations and update docstrings
…edPaulis` (quantumlib#4958) * Add cirq.eject_phased_paulis transformer to replace cirq.EjectPhasedPaulis * Add CCO tests, support PhasedXZGates * Support PhasedXZGates equivalent to z rotations and update docstrings
…edPaulis` (quantumlib#4958) * Add cirq.eject_phased_paulis transformer to replace cirq.EjectPhasedPaulis * Add CCO tests, support PhasedXZGates * Support PhasedXZGates equivalent to z rotations and update docstrings
Breaking change:
cirq.EjectPhasedPaulis
optimizer will now remove empty moments by default.