-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support multi moment gauge compiling #7501
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
base: main
Are you sure you want to change the base?
Conversation
c182892
to
cc2b38a
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7501 +/- ##
========================================
Coverage 97.50% 97.51%
========================================
Files 1103 1106 +3
Lines 99683 99907 +224
========================================
+ Hits 97198 97422 +224
Misses 2485 2485 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
32c5bb3
to
05cc48b
Compare
Hey @eliottrosenberg @NoureldinYosri , here is multi moment gauge compiling!! After evaluating multiple strategies, this approach proves to be optimal regarding both execution speed and future extensibility. Note gauges could be automatically added to circuits with default setup, wonder if the default setup is suitable for most use cases? (see Example section and Usage section in the description above) |
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! Great work, @babacry!
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.
@babacry is there a way to reuse code you wrote before in _PauliAndZPow
?
cirq-core/cirq/transformers/gauge_compiling/multi_moment_gauge_compiling.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/gauge_compiling/multi_moment_gauge_compiling.py
Outdated
Show resolved
Hide resolved
else: | ||
self.zpow = ops.ZPowGate(exponent=-left.exponent + self.zpow.exponent) | ||
|
||
def _merge_right_zpow(self, right: ops.ZPowGate): |
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.
didn't you implement the logic for pulling gates somewhere else? or is this specific to these gates?
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.
Not really, existing functions only allow for pulling Pauli gates through Clifford gates. However, the cphase gate is non-Clifford. When a Pauli operator is pushed through a cphase gate, it transforms into a combination of a Pauli operator and a Z-rotation. To handle this, the method tracks both the Pauli operator and the additional Z-rotation throughout the moments.
cirq-core/cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py
Show resolved
Hide resolved
a9be7d7
to
ba7b4d7
Compare
Thanks Nour for the insightful reivews! We don't have a _PauliAndZPow support in cirq yet. If you are mentioning the PR I worked on to support a specific use case of multi moment gauge compiling, the pr is closed. The only pull-through support in cirq is pulling Pauli gates through Cliffords. Could you help take another look? I've resolved some comments by committing changes, also left some comments for further discussions for the use of @attrs.frozen. @NoureldinYosri |
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.
initial review of style ... I still haven't reviewed the logic of commuting gates
cirq-core/cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py
Show resolved
Hide resolved
cirq-core/cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py
Show resolved
Hide resolved
cirq-core/cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/gauge_compiling/multi_moment_gauge_compiling.py
Outdated
Show resolved
Hide resolved
cirq-core/cirq/transformers/gauge_compiling/multi_moment_gauge_compiling.py
Outdated
Show resolved
Hide resolved
Thanks for the careful and insightful reviews, @NoureldinYosri ! I've frozen attributes in classes instead of allowing inplace updates. And a couple of other comments are addressed. Please help take another look, thanks! |
Support multi moment gauge transformation, where target moments will be gauged with new moments, e.g.,
MultiMomentGaugeTransformer
class is defined.CPhaseGaugeTransformerMM
.CPhaseGaugeTransformerMM
, e.g., Pauli Gates, ZPowGate etc. If these gates are detected, gauge will be calculated accordingly. Users can tweak their desired gates by instantiate their own transformer bytransformer = CPhaseGaugeTransformerMM(supported_gates=ops.Gateset(g1,g2,g3))
. By default_SUPPORTED_GATESET
are used.Example:
Usage
case 1: default setup, any moment with CZPowGate and optionally with _SUPPORTED_GATES will be gauged (see example above),
case 2: Only CZPowGate-only moments will be gauged (see
test_gauge_on_czpow_only_moments
test case),