-
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 ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7501 +/- ##
========================================
Coverage 98.68% 98.68%
========================================
Files 1091 1094 +3
Lines 96851 97089 +238
========================================
+ Hits 95576 95815 +239
+ Misses 1275 1274 -1 ☔ 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
?
|
||
"""Creates the abstraction for multi moment gauge compiling as a cirq transformer.""" | ||
|
||
from __future__ import annotations |
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.
why is this needed?
self, | ||
target: ops.Gate | ops.Gateset | ops.GateFamily, | ||
supported_gates: ops.Gateset = ops.Gateset(), | ||
rng: np.random.Generator = np.random.default_rng(), |
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.
there are two issues here, default values get initialized once so all instances of the class the don't explicitly pass a rng
object will share the same rng
. and an rng
as a class property means that the class has an internal mutable state which is undesirable.
please prefer to pass the an rng_or_seed
to the functions that need it instead of having an internal state
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?
|
||
|
||
class CPhaseGaugeTransformerMM(MultiMomentGaugeTransformer): | ||
|
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.
lets make both MultiMomentGaugeTransformer
and CPhaseGaugeTransformerMM
be @attrs.frozen
then here we can do
supported_gates = attrs.field(default=_SUPPORTED_GATESET)
target = attrs.field(default=_TARGET_GATESET, init=False, repr=False, eq=False, hash=False)
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),