Skip to content

Comments

Add physical qubit support for plain QASM 3 programs#291

Merged
TheGupta2012 merged 3 commits intomainfrom
fix-physical-qubits
Feb 24, 2026
Merged

Add physical qubit support for plain QASM 3 programs#291
TheGupta2012 merged 3 commits intomainfrom
fix-physical-qubits

Conversation

@TheGupta2012
Copy link
Member

Bug Fix

Adds support for physical qubit identifiers ($0, $1, …) in plain (non-OpenPulse) QASM 3 programs. Previously, physical qubits were only handled inside OpenPulse contexts; using them in a regular QASM 3 program would either silently mishandle them or raise unexpected errors.

Changes

  • Visitor: Detect physical qubit references ($n) in _get_op_bits and register them via the new _register_physical_qubit helper, updating qubit depth tracking and num_qubits automatically.
  • Barrier: Allow physical qubit indices on barriers in plain QASM programs instead of rejecting them as invalid pulse qubits.
  • Measurement: Route physical qubits in measurement statements through _register_physical_qubit when OpenPulse grammar is not active.
  • Analyzer: Update extract_duplicate_qubit to handle both Identifier (physical) and IndexedIdentifier (virtual) qubit types.
  • Transformer: Widen transform_gate_qubits qubit map type to accept Identifier | IndexedIdentifier.
  • Depth tracking: Extract a _get_qubit_name_and_id helper to unify index extraction for physical and virtual qubits across depth updates and branch-qubit tracking.
  • Tests: Add comprehensive test suite for physical qubits covering basic gates, custom gates, barriers, measurements, non-contiguous indices, unrolling, and duplicate detection.

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 90.38462% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pyqasm/visitor.py 88.88% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@TheGupta2012 TheGupta2012 merged commit 84e4746 into main Feb 24, 2026
21 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.

3 participants