Skip to content

Commit 5922ec4

Browse files
Add OpenQASM 3 exporter for circuits
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.
1 parent c0f7d16 commit 5922ec4

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-10
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ jobs:
2323
runs-on: ${{ matrix.os }}
2424

2525
steps:
26-
- uses: actions/checkout@v4
26+
- uses: actions/checkout@v5
27+
with:
28+
fetch-depth: 0 # Fetch all, necessary to find tags and branches
29+
fetch-tags: true
2730

2831
- uses: actions/setup-python@v5
2932
with:

.github/workflows/cov.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ jobs:
1414
runs-on: ubuntu-latest
1515

1616
steps:
17-
- uses: actions/checkout@v4
17+
- uses: actions/checkout@v5
18+
with:
19+
fetch-depth: 0 # Fetch all, necessary to find tags and branches
20+
fetch-tags: true
1821

1922
- name: Set up Python
2023
uses: actions/setup-python@v5

.github/workflows/doc.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ jobs:
2020
name: "Check documentation"
2121
runs-on: ubuntu-latest
2222
steps:
23-
- uses: actions/checkout@v4
23+
- uses: actions/checkout@v5
24+
with:
25+
fetch-depth: 0 # Fetch all, necessary to find tags and branches
26+
fetch-tags: true
2427

2528
- uses: actions/setup-python@v5
2629
with:

.github/workflows/typecheck.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ jobs:
1919
runs-on: ubuntu-latest
2020

2121
steps:
22-
- uses: actions/checkout@v4
22+
- uses: actions/checkout@v5
23+
with:
24+
fetch-depth: 0 # Fetch all, necessary to find tags and branches
25+
fetch-tags: true
2326

2427
- uses: actions/setup-python@v5
2528
with:
@@ -46,7 +49,10 @@ jobs:
4649
runs-on: ubuntu-latest
4750

4851
steps:
49-
- uses: actions/checkout@v4
52+
- uses: actions/checkout@v5
53+
with:
54+
fetch-depth: 0 # Fetch all, necessary to find tags and branches
55+
fetch-tags: true
5056

5157
- uses: actions/setup-python@v5
5258
with:

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- #343: Circuit exporter to OpenQASM3:
13+
`graphix.qasm3_exporter.circuit_to_qasm3`.
14+
1215
- #332: New class `StandardizedPattern` that contains the decomposed
1316
parts of a standardized pattern.
1417

noxfile.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def install_pytest(session: Session) -> None:
1616
@nox.session(python=["3.9", "3.10", "3.11", "3.12", "3.13"])
1717
def tests_minimal(session: Session) -> None:
1818
"""Run the test suite with minimal dependencies."""
19-
session.install("-e", ".")
19+
session.install(".")
2020
install_pytest(session)
2121
# We cannot run `pytest --doctest-modules` here, since some tests
2222
# involve optional dependencies, like pyzx.
@@ -27,7 +27,7 @@ def tests_minimal(session: Session) -> None:
2727
@nox.session(python=["3.10", "3.11", "3.12", "3.13"])
2828
def tests_dev(session: Session) -> None:
2929
"""Run the test suite with dev dependencies."""
30-
session.install("-e", ".[dev]")
30+
session.install(".[dev]")
3131
# We cannot run `pytest --doctest-modules` here, since some tests
3232
# involve optional dependencies, like pyzx.
3333
session.run("pytest")
@@ -36,7 +36,7 @@ def tests_dev(session: Session) -> None:
3636
@nox.session(python=["3.9", "3.10", "3.11", "3.12", "3.13"])
3737
def tests_extra(session: Session) -> None:
3838
"""Run the test suite with extra dependencies."""
39-
session.install("-e", ".[extra]")
39+
session.install(".[extra]")
4040
install_pytest(session)
4141
session.install("nox") # needed for `--doctest-modules`
4242
session.run("pytest", "--doctest-modules")
@@ -45,14 +45,14 @@ def tests_extra(session: Session) -> None:
4545
@nox.session(python=["3.10", "3.11", "3.12", "3.13"])
4646
def tests_all(session: Session) -> None:
4747
"""Run the test suite with all dependencies."""
48-
session.install("-e", ".[dev,extra]")
48+
session.install(".[dev,extra]")
4949
session.run("pytest", "--doctest-modules")
5050

5151

5252
@nox.session(python=["3.9", "3.10", "3.11", "3.12", "3.13"])
5353
def tests_symbolic(session: Session) -> None:
5454
"""Run the test suite of graphix-symbolic."""
55-
session.install("-e", ".")
55+
session.install(".")
5656
install_pytest(session)
5757
session.install("nox") # needed for `--doctest-modules`
5858
# Use `session.cd` as a context manager to ensure that the
@@ -67,3 +67,21 @@ def tests_symbolic(session: Session) -> None:
6767
# session.run("git", "clone", "https://github.com/TeamGraphix/graphix-symbolic")
6868
with session.cd("graphix-symbolic"):
6969
session.run("pytest", "--doctest-modules")
70+
71+
72+
@nox.session(python=["3.9", "3.10", "3.11", "3.12", "3.13"])
73+
def tests_qasm_parser(session: Session) -> None:
74+
"""Run the test suite of graphix-qasm-parser."""
75+
session.install(".")
76+
install_pytest(session)
77+
session.install("nox") # needed for `--doctest-modules`
78+
# Use `session.cd` as a context manager to ensure that the
79+
# working directory is restored afterward. This is important
80+
# because Windows cannot delete a temporary directory while it
81+
# is the working directory.
82+
with TemporaryDirectory() as tmpdir, session.cd(tmpdir):
83+
# See https://github.com/TeamGraphix/graphix-qasm-parser/pull/1
84+
session.run("git", "clone", "-b", "fix_typing_issues", "https://github.com/TeamGraphix/graphix-qasm-parser")
85+
with session.cd("graphix-qasm-parser"):
86+
session.install(".")
87+
session.run("pytest", "--doctest-modules")

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ pytest-mock
2020
# Optional dependencies
2121
qiskit>=1.0
2222
qiskit-aer
23+
24+
graphix-qasm-parser @ git+https://github.com/TeamGraphix/graphix-qasm-parser.git@fix_typing_issues

0 commit comments

Comments
 (0)