microquantum.ir.nodes

MicroQuantum IR node types.

Nodes are immutable (frozen dataclasses) so IR passes can share structure freely and memoize comparisons. Each node understands the qubits, classical bits and symbolic parameters it touches — the minimal data required for inspection, validation and transformation.

The IR is intentionally NumPy-free: gate identity is structural (gate name + qubits + parameters), not matrix-based.

Node hierarchy:

IRNode
├── Gate
├── Measurement
├── Reset
├── Barrier
└── ConditionalBlock   (contains a Condition + nested IRNode list)

Module Contents

microquantum.ir.nodes.IRParam[source]
microquantum.ir.nodes.param_to_dict(param)[source]

Serialize an IR parameter to a JSON-safe dictionary.

Parameters:

param (IRParam)

Return type:

dict[str, Any]

microquantum.ir.nodes.param_to_str(param)[source]

Render a parameter for human-readable IR strings.

Parameters:

param (IRParam)

Return type:

str

class microquantum.ir.nodes.Condition[source]

A classical condition guarding an operation or block.

Variables:
  • bit – Classical bit index tested.

  • value – Value the bit must equal (0 or 1).

  • register – Optional classical register name.

bit: int[source]
value: int = 1[source]
register: str | None = None[source]
to_dict()[source]

Serialize to a JSON-safe dictionary.

Return type:

dict[str, Any]

to_json()[source]

Serialize to a JSON string.

Return type:

str

class microquantum.ir.nodes.IRNode[source]

Bases: abc.ABC

Base class for all MicroQuantum IR nodes.

Every concrete node must provide qubits — either as a dataclass field (Gate, Barrier) or as a property (Measurement, Reset, ConditionalBlock). The cbits / parameters result properties declared here give conservative defaults.

property kind: str[source]
Abstractmethod:

Return type:

str

Node kind identifier (e.g. ‘gate’, ‘measure’, ‘reset’, …).

property cbits: tuple[int, ...][source]

Classical bits this node touches.

Return type:

tuple[int, …]

property parameters: tuple[IRParam, ...][source]

Symbolic/numeric parameters this node carries.

Return type:

tuple[IRParam, …]

to_dict()[source]

Serialize to a JSON-safe dictionary.

Return type:

dict[str, Any]

to_json()[source]

Serialize to a JSON string.

Return type:

str

class microquantum.ir.nodes.Gate[source]

Bases: IRNode

A quantum gate operation in the IR.

Variables:
  • name – Gate name from the SDK gate library (h, x, y, z, s, sdg, t, tdg, rx, ry, rz, cnot, cz, swap) or a custom operator name.

  • qubits – Target qubit indices (deterministic order).

  • params – Gate parameters. Numeric rotation angles are stored as plain floats; symbolic angles as Parameter/ParameterExpression.

  • condition – Optional Condition guarding the gate.

  • source – Optional source/debug metadata (e.g. originating circuit gate index) attached by the builder.

name: str[source]
qubits: tuple[int, ...][source]
params: tuple[IRParam, ...] = ()[source]
condition: Condition | None = None[source]
source: dict[str, Any] | None = None[source]
property kind: str[source]

Node kind identifier (e.g. ‘gate’, ‘measure’, ‘reset’, …).

Return type:

str

property parameters: tuple[IRParam, ...][source]

Symbolic/numeric parameters this node carries.

Return type:

tuple[IRParam, …]

property cbits: tuple[int, ...][source]

Classical bits this node touches.

Return type:

tuple[int, …]

display_name()[source]

Upper-case gate name for human-readable output.

Return type:

str

to_dict()[source]

Serialize to a JSON-safe dictionary.

Return type:

dict[str, Any]

class microquantum.ir.nodes.Measurement[source]

Bases: IRNode

A (mid-circuit or terminal) measurement of one qubit.

Variables:
  • qubit – Qubit index measured.

  • classical – Classical bit index the outcome is stored into, or None when the outcome is only observed.

qubit: int[source]
classical: int | None = None[source]
property kind: str[source]

Node kind identifier (e.g. ‘gate’, ‘measure’, ‘reset’, …).

Return type:

str

property qubits: tuple[int, ...][source]
Return type:

tuple[int, …]

property cbits: tuple[int, ...][source]

Classical bits this node touches.

Return type:

tuple[int, …]

to_dict()[source]

Serialize to a JSON-safe dictionary.

Return type:

dict[str, Any]

class microquantum.ir.nodes.Reset[source]

Bases: IRNode

Reset a qubit to the |0> computational basis state.

Prepares the IR for dynamic-circuit and QEC workflows.

qubit: int[source]
property kind: str[source]

Node kind identifier (e.g. ‘gate’, ‘measure’, ‘reset’, …).

Return type:

str

property qubits: tuple[int, ...][source]
Return type:

tuple[int, …]

to_dict()[source]

Serialize to a JSON-safe dictionary.

Return type:

dict[str, Any]

class microquantum.ir.nodes.Barrier[source]

Bases: IRNode

A synchronization barrier across a set of qubits.

qubits: tuple[int, ...][source]
property kind: str[source]

Node kind identifier (e.g. ‘gate’, ‘measure’, ‘reset’, …).

Return type:

str

to_dict()[source]

Serialize to a JSON-safe dictionary.

Return type:

dict[str, Any]

class microquantum.ir.nodes.ConditionalBlock[source]

Bases: IRNode

A classically-controlled block of IR operations.

Variables:
  • condition – The classical condition that gates the block.

  • operations – Ordered operations executed when the condition holds.

condition: Condition[source]
operations: tuple[IRNode, ...] = ()[source]
property kind: str[source]

Node kind identifier (e.g. ‘gate’, ‘measure’, ‘reset’, …).

Return type:

str

property qubits: tuple[int, ...][source]
Return type:

tuple[int, …]

property cbits: tuple[int, ...][source]

Classical bits this node touches.

Return type:

tuple[int, …]

to_dict()[source]

Serialize to a JSON-safe dictionary.

Return type:

dict[str, Any]

microquantum.ir.nodes.IRNodeSubtype[source]