Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pyqasm/maps/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions src/pyqasm/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion tests/qasm3/test_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,19 @@ 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];"],
),
(
"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):
"""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.
Expand Down
Loading