Skip to content

Conversation

@thierry-martinez
Copy link
Collaborator

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.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.

@codecov
Copy link

codecov bot commented Oct 1, 2025

Codecov Report

❌ Patch coverage is 90.47619% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.68%. Comparing base (8143f0c) to head (6908216).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
graphix/qasm3_exporter.py 90.90% 5 Missing ⚠️
graphix/pretty_print.py 87.50% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thierry-martinez thierry-martinez mentioned this pull request Oct 1, 2025
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.
Comment on lines 50 to 51
if instruction.kind == InstructionKind.M:
return f"b[{instruction.target}] = measure q[{instruction.target}]"
Copy link
Contributor

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 $Z$-basis (see doc). However, 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 ?

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

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

Copy link
Collaborator Author

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.

Copy link
Contributor

@matulni matulni left a 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!

Copy link
Contributor

@shinich1 shinich1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@thierry-martinez thierry-martinez merged commit 5e684ac into TeamGraphix:master Oct 20, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants