Skip to content

✨ Preserve quantum-register subroutines in OpenQASM 3 #2429

Description

@burgholzer

🤖 AI text below 🤖

Problem Statement

OpenQASM 3 supports subroutines such as def f(qubit[4] q), but MQT Core currently models only custom gate definitions. Import lowers gate formals to scalar QC qubits, and export accepts only leading f64 parameters followed by scalar-qubit arguments.

Using gate or flattening a register loses the source-level function boundary and cannot represent indexed register logic faithfully.

Proposed Solution

Import and export one coherent, useful subset of OpenQASM 3 subroutines after the shared QC/QCO register-call contract is available.

Supported subset

  • Global, defined, non-recursive, void def subroutines.
  • One or more scalar qubit or fixed positive qubit[N] parameters.
  • Existing supported statements in the body, including calls to previously defined supported gates and subroutines.
  • No local qubit declarations.
  • Register actuals are whole register identifiers. Scalar actuals use existing scalar references.
  • All quantum actuals at a call must be provably pairwise disjoint.

Import each supported subroutine as a private QC func.func with borrowed scalar/memref arguments and ordinary func.call. Export reachable ordinary functions with at least one fixed register argument as def. Continue to export scalar mqt.unitary functions as gate.

Keep the parser, semantic model, QC emitter, and exporter in one pull request. A syntax-only intermediate state is not independently useful.

Likely implementation areas:

  • OpenQASM lexer tokens and syntax nodes
  • OpenQASMParser.h and semantic analysis
  • OpenQASMToQCEmitter.cpp
  • TranslateQCToOpenQASM3.cpp
  • Frontend documentation and focused parser, semantics, emitter, and round-trip tests

Acceptance criteria

  • Import and export support a subroutine with mixed scalar-qubit and multiple fixed-register parameters.
  • Nested supported subroutine calls work when definitions precede use.
  • QC→OpenQASM 3→QC preserves register count, order, and static sizes.
  • Duplicate and overlapping quantum actuals are rejected before emission.
  • Dynamic registers, slices, concatenations, unresolved calls, recursion, and non-void subroutines receive targeted diagnostics.
  • Existing custom-gate import and export behavior remains unchanged.
  • Tests include negative parser/semantic cases and an end-to-end round trip.

Dependencies and related work

Non-goals

Classical by-value parameters; classical register parameters; bit[N] references; classical return values; extern; early return; recursion; local qubit declarations; dynamic or sliced quantum arrays; modifiers on subroutine calls.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    MLIRAnything related to MLIROpenQASMAnything related to OpenQASMfeatureNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions