From fe6725a2921b11871def719c037be50b101b23cb Mon Sep 17 00:00:00 2001 From: TheGupta2012 Date: Thu, 19 Nov 2026 11:47:49 +0530 Subject: [PATCH 1/4] test: cover inv @ on a custom gate whose body contains nop Co-Authored-By: Claude Opus 5.5 --- tests/qasm3/test_gates.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/qasm3/test_gates.py b/tests/qasm3/test_gates.py index e2ee1576..8aebcc04 100644 --- a/tests/qasm3/test_gates.py +++ b/tests/qasm3/test_gates.py @@ -77,10 +77,15 @@ def test_single_qubit_qasm3_gates(circuit_name, request): ("nop q[0], q[0];", ["nop q[0];", "nop q[0];"]), ("gate g a { nop a; }\ng q[0];", ["nop q[0];"]), ("gate g a, b { nop a, b; x b; }\ng q[0], r[0];", ["nop q[0];", "nop r[0];", "x r[0];"]), + ("gate g a { nop a; }\ninv @ g q[0];", ["nop q[0];"]), + ( + "gate g a, b { nop a; x b; nop b; }\ninv @ g q[0], r[0];", + ["nop r[0];", "x r[0];", "nop q[0];"], + ), ], ) def test_nop_unrolls_per_operand(statement, expected): - """A nop unrolls to one nop per operand qubit, also inside a gate definition. + """A nop unrolls to one nop per operand qubit, also inside a gate definition and its inverse. openqasm3 1.0.1 parses these as nop gate calls and 1.0.2 as nop statements, and both give the same unrolled program. From 15c1aeae4fc07f115e2b5e8258977d3e3e0eed9d Mon Sep 17 00:00:00 2001 From: TheGupta2012 Date: Thu, 19 Nov 2026 11:49:03 +0530 Subject: [PATCH 2/4] docs(changelog): add the inv @ nop fix [no ci] Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9c7fbd6..8e50acb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Types of changes: ### Removed ### Fixed +- `unroll()` accepts `inv @` on a custom gate whose body contains `nop`, and keeps each `nop` in the inverted body. Before, it raised `ValidationError: Unsupported / undeclared QASM operation: nop` ([#485](https://github.com/qBraid/pyqasm/pull/485), [#477](https://github.com/qBraid/pyqasm/issues/477)). - `publish-lab-env.yml` files a publish request before it approves the environment. Since qBraid/qbraid-api#1334 the server approves only an environment with an open request, so every run failed at approve with `Environment must have status REQUESTED or PENDING to publish`. The request counts toward the API key owner's publish quota and notifies the platform admins ([#491](https://github.com/qBraid/pyqasm/pull/491), [#490](https://github.com/qBraid/pyqasm/issues/490)). ### Dependencies From e2267f3db0c501f6ee358de0b8a3f7073a95b477 Mon Sep 17 00:00:00 2001 From: TheGupta2012 Date: Thu, 19 Nov 2026 11:47:49 +0530 Subject: [PATCH 3/4] fix: invert nop as itself in inv @ gate bodies map_qasm_inv_op_to_callable had no entry for nop, so inv @ on a custom gate whose body contains nop raised ValidationError. nop is its own inverse, so add it to SELF_INVERTING_ONE_QUBIT_OP_SET. Co-Authored-By: Claude Opus 5.5 --- src/pyqasm/maps/gates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyqasm/maps/gates.py b/src/pyqasm/maps/gates.py index d6d5edbb..6e28f44b 100644 --- a/src/pyqasm/maps/gates.py +++ b/src/pyqasm/maps/gates.py @@ -1204,7 +1204,7 @@ def map_qasm_op_to_callable(op_node: QuantumGate) -> tuple[Callable, int]: # ty ) -SELF_INVERTING_ONE_QUBIT_OP_SET = {"id", "h", "x", "y", "z"} +SELF_INVERTING_ONE_QUBIT_OP_SET = {"id", "h", "x", "y", "z", "nop"} ST_GATE_INV_MAP = { "s": "sdg", "t": "tdg", From 9f22e5e8ae9bcc5c0cba2a35a9d3ffe76d99418f Mon Sep 17 00:00:00 2001 From: TheGupta2012 Date: Thu, 19 Nov 2026 11:56:27 +0530 Subject: [PATCH 4/4] fix: reverse an inverted gate body before splitting nop openqasm3 1.0.2 parses nop as a statement, which the visitor split per operand before reversing an inverted body. That put the nops of inv @ g in the opposite order from 1.0.1. Reverse first, then split. Co-Authored-By: Claude Opus 5.5 --- src/pyqasm/visitor.py | 5 ++--- tests/qasm3/test_gates.py | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pyqasm/visitor.py b/src/pyqasm/visitor.py index cd51f311..09f36c37 100644 --- a/src/pyqasm/visitor.py +++ b/src/pyqasm/visitor.py @@ -1400,11 +1400,10 @@ def _visit_custom_gate_operation( for formal_arg, actual_arg in zip(gate_definition.arguments, operation.arguments) } - gate_definition_ops = Qasm3Transformer.expand_nop_statements( - copy.deepcopy(gate_definition.body) - ) + gate_definition_ops = copy.deepcopy(gate_definition.body) if inverse: gate_definition_ops.reverse() + gate_definition_ops = Qasm3Transformer.expand_nop_statements(gate_definition_ops) self._scope_manager.push_scope({}) self._scope_manager.push_context(Context.GATE) diff --git a/tests/qasm3/test_gates.py b/tests/qasm3/test_gates.py index 8aebcc04..894706aa 100644 --- a/tests/qasm3/test_gates.py +++ b/tests/qasm3/test_gates.py @@ -82,6 +82,10 @@ def test_single_qubit_qasm3_gates(circuit_name, request): "gate g a, b { nop a; x b; nop b; }\ninv @ g q[0], r[0];", ["nop r[0];", "x r[0];", "nop q[0];"], ), + ( + "gate g a, b { nop a, b; cx a, b; }\ninv @ g q[0], r[0];", + ["cx q[0], r[0];", "nop q[0];", "nop r[0];"], + ), ], ) def test_nop_unrolls_per_operand(statement, expected):