Conversions

Internal Conversions

-mqtopt-to-mqtref

Convert MQT’s Opt to MQT’s Ref dialect.

This pass converts all current MQTOpt operations to an equivalent MQTRef operation. The result of the converted MQTRef alloc operation acts as a qubit register reference and replaces the operand of the operation that uses the initial MQTOpt qubit register. This reference is then propagated to all subsequent operations that use the state of the initial MQTOpt register and replaces their operand. The same applies to the result of the extract operation that acts as a qubit reference and is propagated to all later uses of this qubit. The MQTOpt insert operation is deleted as there is no equivalent operation in the MQTRef dialect. The use of the insert operation’s result in any subsequent operation is replaced by the qubit register reference.

-mqtref-to-mqtopt

Convert MQT’s Ref to MQT’s Opt dialect.

This pass converts all current MQTRef operations to an equivalent MQTOpt operation. To convert them to the opt dialect, the conversion pass maintains a map that matches each ref qubit and ref qubit register to its latest state value when replacing them with an opt operation. These state values are obtained by updating the map with the return values of the newly created opt operations. The MQTOpt insert operation is added when matching the dealloc operation of any qubit register. An MQTOpt insert operation is then created for each qubit that was extracted from the qubit register and placed before the dealloc operation.

QIR Conversions

-mqtref-to-qir

Lower the MQTRef dialect to the LLVM dialect compliant with QIR 2.0 (Base Profile)

Overview Converts the MQTRef dialect to the LLVM dialect following the QIR 2.0 Base Profile. Quantum operations are mapped to calls into the QIR instruction set, while non-quantum operations are lowered using MLIR’s standard LLVM conversions.

Requirements

  • Input is a valid module in the MQTRef dialect.

  • Static or dynamic qubit addressing is supported.

  • The entry function must be marked with the entry_point attribute.

  • The program must have straight-line control flow (no complex branching).

Behavior

  • Each MQTRef quantum operation is replaced by a call to the corresponding QIR function in the LLVM dialect.

  • Required QIR module flags are attached as attributes to the entry function.

  • The entry function is split into four blocks to satisfy QIR Base Profile constraints.

  • Non-quantum dialects are lowered via MLIR’s built-in conversions.

Block structure (Base Profile) 0. Initialization block

  • Sets up the execution environment and performs required runtime initialization.

  1. Reversible operations block

    • Contains only void-returning calls to reversible quantum operations.

  2. Irreversible operations block

    • Contains only void-returning calls to operations marked irreversible, e.g.: __quantum__qis__mz__body, __quantum__rt__qubit_release_array, __quantum__rt__qubit_release, __quantum__qis__reset__body.

  3. Epilogue block

    • Records measurement results and returns from the entry function.

  • Blocks are connected via unconditional branches in the order listed above.

Operation mapping

  • mqtref.measure → call to __quantum__qis__mz__body followed by __quantum__rt__result_record_output to record the measurement result.

Lowering of non-quantum operations

  • Dialects lowered via MLIR conversions: func, arith, cf → LLVM dialect.

Limitations

  • Only straight-line control flow is supported.

  • Adheres to QIR Base Profile requirements.

  • Unsupported operations or control flow patterns may cause the conversion to fail.

Producing LLVM IR

  • After conversion to the LLVM dialect, produce LLVM IR with: mlir-translate –mlir-to-llvmir input.mlir > output.ll

-qir-to-mqtref

Raise LLVM/QIR (Base Profile) to the MQTRef dialect by converting QIR calls into mqtref ops

Overview Converts LLVM dialect modules that use QIR into MQTRef IR by pattern-matching and replacing calls to QIR functions with equivalent operations from the MQTRef dialect.

Requirements

  • Input is a valid MLIR module in the LLVM dialect that follows QIR Base Profile conventions.

  • Static or dynamic qubit addressing is supported.

  • The program is expected to have straight-line control flow.

Behavior

  • Replaces llvm.call operations targeting QIR functions with corresponding mqtref operations.

  • The conversion is driven by the QIR function name used by the call.

Operation mapping

  • __quantum__qis__mz__bodymqtref.measure returning an i1 measurement result.

  • The paired __quantum__rt__result_record_output for measurements is removed.

Non-converted constructs

  • llvm.mlir.constant and function declarations are currently not converted and remain in the module.

Limitations

  • Only simple, straight-line programs that follow the QIR Base Profile are supported.

  • QIR calls without a known mapping in mqtref cause the conversion to fail.

Obtaining the input module

  • Import an LLVM IR file as MLIR with: mlir-translate –import-llvm input.ll -o output.mlir