Shared Passes
The following passes are not tied to a single dialect.
-drop-global-phases
Discard final-program QC and QCO global phases
Erases direct global phases in the function marked mqt.entry_point,
including its classical execution paths. Phases in helper functions and
quantum modifier bodies are retained: they can become observable relative
phases under coherent control or non-integer powers. Modules without an
entry point are unchanged.
This pass preserves measurement probabilities, not exact statevectors or
unitaries. Run it only when the final program’s global phase is irrelevant.
It does not remove angle producers; subsequent dead-code elimination may
remove unused pure computations. Normalize modifiers separately to expose
further disposable phases while retaining relative phases.
-legalize-control-flow
Adapt SCF control flow to the selected execution format
Uses an explicit payload-spec attribute when set, otherwise reads
mqt.target_env. Retains covered SCF branches and loops, lowers unsupported
index switches to nested forward branches when possible, and rejects
unsupported residual control flow. Loop bounds and steps must be literal
constants when the execution format requires a known trip count. Switch expansion
respects the forward-branching depth limit and a maximum generated nesting
depth of 256.
Run after constant propagation and cleanup. For QCO programs, use
legalize-qco-control-flow, which also checks quantum state and handles
QCO branches.
Options
-payload-spec : Explicit #mqt.payload_spec; defaults to mqt.target_env.
-lower-quantum-modifiers
Lower quantum modifiers to supported gate forms
Lowers nested controls, inverses and supported powers, preserving controlled
relative phase and folding generated arithmetic. Fixed single-qubit QCO
gates support runtime powers; other powers require constant parameters.
Unsupported powers remain for the consuming conversion to diagnose.
Run after inlining and modifier unrolling to prepare gates for conversion.
Adjacent-gate optimization and CFG cleanup are separate passes.
-normalize-global-phases
Normalize scoped QC and QCO global phases
Combines direct qc.gphase and qco.gphase operations into at most one
operation per basic block, placed at the last phase contribution.
Nested regions are normalized independently, except power subtrees, which
remain unchanged: phase rounding can be amplified by a large exponent.
A normalized phase is moved out of inv, negating its angle. A phase in a
ctrl body becomes a relative phase on the control register: p for one
control or a smaller controlled p for multiple controls. Eager classical
computations in verified modifier bodies move once, in source order, before
the outermost enclosing inv or ctrl.
Constant angles are reduced modulo 2π. Symbolic sums are balanced and
reduced with 2 * atan(tan(angle / 2)) to keep runtime phases in range.
Function, CFG, structured-control-flow, and unknown region boundaries are
preserved. The pass does not scan an enclosing module from individual
rewrite patterns.
-remove-unused-qubits
Remove unused quantum allocation and release pairs
Removes unused QC and QCO qubits and QTensor registers. Gate-set targets
retain their program qubits. Run after canonicalization and before device
placement to avoid counting idle allocations against device capacity.
Register shrinking is handled by the corresponding QC and QTensor passes.
-simplify-classical-control
Propagate known QCO branch conditions
Within each QCO if branch, replaces uses of its condition with the known
boolean value. A following canonicalizer folds the exposed expressions and
static branches. Run after inlining and again after static loop unrolling.
-simplify-quantum
Simplify quantum gates and modifiers
Eliminates identity gates, cancels inverse pairs, combines rotations and
specializes gates and modifiers in QC or QCO programs. Generated arithmetic
is folded. Rotation elimination uses an absolute parameter tolerance of
1e-15, not a circuit error bound.
Use this pass when the gate sequence may change. Use canonicalization for
classical and structural cleanup. CFG simplification is separate.
-unroll-modifiers
Unroll multi-operation modifiers into single-operation ones
Expands unitary function calls inside quantum modifiers and normalizes
exposed global phases before splitting modifiers. Calls outside modifiers
remain reusable. Functions marked no_inline remain calls.
Splits ctrl and inv modifiers whose body holds more than one unitary
operation into a sequence of modifiers that each hold a single operation.
For inv, the order of the operations is reversed. Classical operations of
the body are moved in front of the new modifiers.
A pow modifier is only unrolled if its exponent is a compile-time known
integer and its operations act on disjoint qubits. Otherwise, pow(r) { a; b } is generally not equivalent to pow(r) { a }; pow(r) { b }: the
operations do not commute if they share a qubit, and for a non-integer
exponent, the principal branch of the matrix power does not distribute over
them. Modifiers nested in a pow body are unrolled either way.
If a modifier cannot be unrolled, the modifier is left untouched. Such
modifiers are skipped silently.