microquantum.ir.passes¶
IR transformation passes.
Provides the IRPass / IRPassManager abstraction and a
small initial set of correct structural transformations:
RemoveIdentityGates— drops gates that are structurally identity (identity gates, zero-angle rotations, empty conditional blocks).CancelAdjacentInverse— cancels adjacent U, U-dagger pairs on the same qubits (self-inverse gates, known inverse pairs, opposite rotations).CombineRotations— merges adjacent same-axis rotation gates on one qubit into a single rotation (R(a) R(b) -> R(a + b)).BindParameters— substitutes symbolic parameters with numeric values, producing an executable (bound) IR.GateDecomposition— expands a gate into a supported basis gate set (exact, standard identities only).
All passes are NumPy-free and produce new IRCircuit objects,
leaving the input untouched.
Module Contents¶
- class microquantum.ir.passes.IRPass[source]¶
Bases:
abc.ABCAbstract base class for IR transformation passes.
A pass inspects and transforms an
IRCircuitinto a newIRCircuit. Passes never mutate their input.
- class microquantum.ir.passes.IRPassManager(passes=None)[source]¶
Runs an ordered pipeline of IR passes.
Example:
pm = IRPassManager([RemoveIdentityGates(), CancelAdjacentInverse()]) optimized = pm.run(ir)
- append_pass(pass_)[source]¶
Append a single pass and return self.
- Parameters:
pass_ (IRPass)
- Return type:
- run(ir)[source]¶
Run all passes sequentially, feeding each output into the next.
- Parameters:
ir (microquantum.ir.circuit_ir.IRCircuit) – The input IR circuit.
- Returns:
The IR after all passes have been applied.
- Return type:
- class microquantum.ir.passes.RemoveIdentityGates[source]¶
Bases:
IRPassRemove structurally-identity operations.
Drops
idgates, zero-angle rotation gates, and empty conditional blocks (recursively).
- class microquantum.ir.passes.CancelAdjacentInverse[source]¶
Bases:
IRPassCancel adjacent inverse gate pairs on the same qubits.
Recognizes self-inverse gates (H, X, Y, Z, CNOT, CZ, SWAP), the standard inverse pairs (S/Sdg, T/Tdg) and opposite rotations (R(a) R(-a)). Barriers and non-gate nodes act as separators.
- class microquantum.ir.passes.CombineRotations[source]¶
Bases:
IRPassFuse adjacent same-axis rotations on one qubit: R(a) R(b) -> R(a+b).
- class microquantum.ir.passes.BindParameters(param_map)[source]¶
Bases:
IRPassBind symbolic parameters to numeric values.
- Parameters:
param_map (Mapping[Union[str, microquantum.core.parameter.Parameter], float]) – Mapping from
Parameter(or parameter name) to a numeric value. Parameters absent from the mapping remain symbolic in the output IR.
- class microquantum.ir.passes.GateDecomposition(basis_gates)[source]¶
Bases:
IRPassExpand gates not in the target basis.
Only standard, exact identities are used:
cz(c, t) -> h(t), cnot(c, t), h(t)(basis has h and cnot)swap(a, b) -> cnot(a,b), cnot(b,a), cnot(a,b)(basis has cnot)
Gates that cannot be decomposed are left in place; use the compiler’s diagnostics to detect them.
The basis is normalized to MicroQuantum IR gate names, so a
Targetspelling the controlled-NOT as"cx"is equivalent to the IR’s"cnot".- Parameters:
basis_gates (Union[microquantum.core.device.Target, Iterable[str]]) – The supported gate-name set (e.g. a
Target’snative_gates).
- microquantum.ir.passes.optimize(ir, level=1)[source]¶
Run the standard optimization pipeline on ir.
- Parameters:
ir (microquantum.ir.circuit_ir.IRCircuit) – The IR circuit to optimize.
level (int) – 0 = returns input unchanged, 1 = identity removal + inverse cancellation, 2 = additionally fuses same-axis rotations.
- Returns:
The optimized IR circuit.
- Return type: