From e71b7b63f86ab6ec93a7e98b0312169eaea3cdb3 Mon Sep 17 00:00:00 2001 From: Emlyn Graham Date: Fri, 28 Nov 2025 15:57:54 +0100 Subject: [PATCH 1/2] added CZ --- graphix_qasm_parser/parser.py | 5 ++++- requirements.txt | 2 +- tests/test_parser.py | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/graphix_qasm_parser/parser.py b/graphix_qasm_parser/parser.py index 9f6738b..a7cc14a 100644 --- a/graphix_qasm_parser/parser.py +++ b/graphix_qasm_parser/parser.py @@ -13,7 +13,7 @@ ParserRuleContext, ) from graphix import Circuit -from graphix.instruction import CCX, CNOT, RX, RY, RZ, RZZ, SWAP, H, I, S, X, Y, Z +from graphix.instruction import CCX, CNOT, RX, RY, RZ, RZZ, SWAP, CZ, H, I, S, X, Y, Z from openqasm_parser import qasm3Lexer, qasm3Parser, qasm3ParserVisitor # override introduced in Python 3.12 @@ -302,6 +302,9 @@ def visitGateCallStatement(self, ctx: qasm3Parser.GateCallStatementContext) -> N elif gate == "swap": # https://openqasm.com/language/standard_library.html#swap instruction = SWAP(targets=(operands[0], operands[1])) + elif gate == "cz": + # https://openqasm.com/language/standard_library.html#cz + instruction = CZ(targets=(operands[0], operands[1])) elif gate == "h": # https://openqasm.com/language/standard_library.html#h instruction = H(target=operands[0]) diff --git a/requirements.txt b/requirements.txt index 848b66b..d1abbcc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -graphix>=0.3.1 +graphix @ git+https://github.com/TeamGraphix/graphix.git@add_cz_instruction openqasm-parser>=3.1.0 diff --git a/tests/test_parser.py b/tests/test_parser.py index f72677f..76f0a1d 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -3,7 +3,7 @@ import math import pytest -from graphix.instruction import CCX, CNOT, RX, RY, RZ, RZZ, SWAP, H, S, X, Y, Z +from graphix.instruction import CCX, CNOT, CZ, RX, RY, RZ, RZZ, SWAP, H, S, X, Y, Z from graphix_qasm_parser import OpenQASMParser @@ -51,6 +51,7 @@ def test_parse_all_instructions() -> None: # noqa: PLR0915 crz(pi/3) q[0], q[1]; cx q[0], q[1]; swap q[0], q[1]; +cz q[0], q[1]; h q[0]; s q[0]; x q[0]; @@ -82,6 +83,9 @@ def test_parse_all_instructions() -> None: # noqa: PLR0915 assert isinstance(instruction, SWAP) assert instruction.targets == (0, 1) instruction = next(iterator) + assert isinstance(instruction, CZ) + assert instruction.targets == (0, 1) + instruction = next(iterator) assert isinstance(instruction, H) assert instruction.target == 0 instruction = next(iterator) From d7fa9e8e2aa9ecca92ad71ca2d0b9e2ee8d48117 Mon Sep 17 00:00:00 2001 From: Emlyn Graham Date: Fri, 28 Nov 2025 16:11:07 +0100 Subject: [PATCH 2/2] removed Python 3.9 --- .github/workflows/ci.yml | 2 +- graphix_qasm_parser/parser.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7632d9b..87175ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: os: ["ubuntu-latest", "windows-latest", "macos-latest"] - python: ["3.9", "3.10", "3.11", "3.12", "3.13"] + python: ["3.10", "3.11", "3.12", "3.13"] name: "Python ${{ matrix.python }} / ${{ matrix.os }}" runs-on: ${{ matrix.os }} diff --git a/graphix_qasm_parser/parser.py b/graphix_qasm_parser/parser.py index a7cc14a..ce1c1a8 100644 --- a/graphix_qasm_parser/parser.py +++ b/graphix_qasm_parser/parser.py @@ -13,7 +13,7 @@ ParserRuleContext, ) from graphix import Circuit -from graphix.instruction import CCX, CNOT, RX, RY, RZ, RZZ, SWAP, CZ, H, I, S, X, Y, Z +from graphix.instruction import CCX, CNOT, CZ, RX, RY, RZ, RZZ, SWAP, H, I, S, X, Y, Z from openqasm_parser import qasm3Lexer, qasm3Parser, qasm3ParserVisitor # override introduced in Python 3.12