Skip to content

🧮 MLIR - Decide and document classical result semantics (SSA vs memory via memref) #1123

@burgholzer

Description

@burgholzer

Background

Frontends like OpenQASM 3, Qiskit, or our own MQT Core IR allow both scalar captures (bit c = measure q;) and writes into bit arrays (c[0] = measure q[0];). MLIR favors SSA values, while QIR and frontends often assume reference/memory semantics for classical bits.

Problem

We need a consistent representation across MQTRef and MQTOpt that enables import, optimization, classical control, and QIR lowering without losing the intended number of observable outputs.
A quantum program requesting a classical register of size N will expect (at least) N classical values to be available.

Proposal:

  • Default: measure returns i1 (SSA), as it does at the moment. When a classical register is needed (because it is part of the input program), store the result into a memref<?xi1> at the appropriate index. This keeps MQTOpt value-semantics-friendly and uses MLIR-native memref for storage.
  • Alternative: A memory-writing measure form (measure %q, %mem, %idx) for direct stores where desirable (optional extension).

Examples:

  • Scalar SSA result
    %c = mqtref.measure %q : !mqtref.qubit -> i1
  • Store into classical register
    %cReg = memref.alloc(%n) : memref<?xi1>
    memref.store %c, %cReg[%i] : memref<?xi1>
  • Load from classical register for control flow
    %cond = memref.load %cReg[%i] : memref<?xi1>
    scf.if %cond { /* ... */ }

Acceptance criteria:

  • Decision note committed in docs (e.g., docs/mlir.md) detailing the rationale behind the decision being made here
  • QuantumComputation with classical registers can be faithfully mapped to MLIR

Metadata

Metadata

Assignees

Labels

MLIRAnything related to MLIRc++Anything related to C++ codedocumentationImprovements or additions to documentationenhancementImprovement of existing feature

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions