-
Notifications
You must be signed in to change notification settings - Fork 39
Add OpenQASM 3 exporter for circuits #343
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 OpenQASM 3 exporter for circuits #343
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #343 +/- ##
==========================================
+ Coverage 79.52% 79.68% +0.15%
==========================================
Files 41 42 +1
Lines 5793 5852 +59
==========================================
+ Hits 4607 4663 +56
- Misses 1186 1189 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This commit introduces an OpenQASM 3 exporter for Graphix circuits. The functionality was originally proposed in TeamGraphix#245 but has not yet been merged. The added tests verify that a round-trip through the OpenQASM 3 representation preserves Graphix circuits, using the graphix-qasm3-parser plugin. This plugin is therefore added as a `requirements-dev.txt` dependency. CI is updated so that `pip install .` can detect the current version number of Graphix, instead of the default `0.1`: to do so, the whole history and the tags should be available. We removed the "-e" option from CI because it is useless in the CI context. In the long term the `qasm3_exporter` module will also host the pattern exporter, but that feature is intentionally omitted from this PR to keep the change focused.
a9d2236 to
1fda549
Compare
| if instruction.kind == InstructionKind.M: | ||
| return f"b[{instruction.target}] = measure q[{instruction.target}]" |
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.
If I understood correctly, the measure primitive projects in the graphix.instruction.M has attributes plane and angle. Shouldn't we rotate the measurement basis (i.e., cast measurement instructions into M[plane=Plane.XZ, angle=0] commands) before calling the qasm exporter ?
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.
Agree here also. It appears you have to define alternative measurement bases as subroutines in openQASM (see https://openqasm.com/language/subroutines.html) since they aren't included by default.
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.
You're right, the emitted instruction only works for M[plane=Plane.XZ, angle=0]. In a076142, I added a check that rejects any other measurements. I think we should provide functions to rewrite circuits to a particular set of instructions (in this case, measurements in a fixed form), and the OpenQASM exporter should not try to rewrite the circuit itself.
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.
It seems that the workaround in @emlynsg's link amounts to adding extra instructions, which can be done at the level of the circuit (and the pattern), so I agree that it's best to separate the rewrite from the OpenQASM exporter (so that it's a mere translator which doesn't change the depth of the object).
I propose that we open an issue once this PR is merged to we don't forget
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 just opened #352 to discuss about this.
matulni
left a comment
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.
Thanks, the refactor is very nice. LGTM!
shinich1
left a comment
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!
This commit introduces an OpenQASM 3 exporter for Graphix circuits. The functionality was originally proposed in #245 but has not yet been merged.
The added tests verify that a round-trip through the OpenQASM 3 representation preserves Graphix circuits, using the graphix-qasm3-parser plugin. This plugin is therefore added as a
requirements-dev.txtdependency.CI is updated so that
pip install .can detect the current version number of Graphix, instead of the default0.1: to do so, the whole history and the tags should be available. We removed the "-e" option from CI because it is useless in the CI context.In the long term the
qasm3_exportermodule will also host the pattern exporter, but that feature is intentionally omitted from this PR to keep the change focused.