Skip to main content
The types in this reference are the data structures you create, inspect, and pass between b01t APIs. You rarely construct most of them directly — decorators and build methods produce them for you — but understanding their fields lets you inspect compiled programs, check safety properties, and serialize or lower them correctly.

QReg

A quantum register: a named, contiguous block of qubits.
name
str
required
Register name. Must be unique within a program.
size
int
required
Number of qubits in this register.
kind
str
default:"\"sys\""
Register kind. "sys" for user-declared registers, "anc" for ancilla registers allocated by ancilla(...).

Methods and indexing

__getitem__(idx: int)
Wire
Returns the Wire at position idx. Raises IndexError if out of bounds.
wires()
list[Wire]
Returns a list of all wires in the register, in order.
__len__()
int
Returns the number of qubits (size).
__iter__()
Iterator[Wire]
Iterates over all wires in the register.

Wire

A reference to a single qubit within a register. Wires are frozen dataclass instances and are used everywhere gates accept qubit arguments.
reg
str
The name of the register this wire belongs to.
index
int
Zero-based index within the register.
kind
str
Kind of the parent register: "sys" or "anc".
You typically obtain Wire objects by indexing a QReg rather than constructing them directly.

ExactProgram

The result of calling .build_exact() on a @coherent or @primitive function. Represents a certified exact program.
name
str
The function name from the decorator.
regs
tuple[QReg, ...]
All registers in the program, including any ancilla registers allocated during the build. System registers appear first.
ops
tuple[ExactOp, ...]
The compiled op sequence. Contains ExactGateOp, ExactAncillaBlock, or ExactParOp instances.
certification
Certification
Certification.SAFE for @coherent programs; Certification.PRIMITIVE for @primitive programs.

IRProgram

The result of calling .build() on a @parametric or @adaptive function, or of calling lower_exact_program() on an ExactProgram.
name
str
The function name from the decorator.
effect
Effect
Effect.COHERENT for @parametric; Effect.ADAPTIVE for @adaptive.
regs
list[QReg]
Declared registers in the order they were passed to .build().
ops
list[Op]
The compiled op sequence. Contains GateOp, MeasureOp, MeasureAllOp, IfOp, AncillaBlockOp, or ParOp instances.
is_safe
bool
True if the program passed the safety checker (coherent effect + well-formed ancilla blocks with exact-safe gates only). Always False for adaptive programs.

Certification

Enum marking the safety level of an ExactProgram.

Effect

Enum describing the computational effect of an IRProgram.

DSLValidationError

Raised whenever a b01t rule is violated. Inherits from RuntimeError. Common causes:
  • Using a forbidden gate in a context (e.g., rx in @coherent)
  • Calling a gate outside a build context
  • Ancilla discipline violations (missing uncompute, nested blocks)
  • Duplicate register names
  • Measurement in a @coherent function
  • if_then in a non-adaptive function
  • Calling .build_exact() or .build() with wrong argument types

is_safe_program

Checks whether a list of broad IR ops satisfies the safety predicate: coherent effect, only exact-safe gates at the top level, and well-formed ancilla blocks with correct compute / phase / uncompute structure.
effect
Effect
required
The effect of the program. Returns False immediately if effect is Effect.ADAPTIVE.
ops
Sequence[Op]
required
The list of ops to check.
Returns: boolTrue if all ops satisfy the safety conditions.

dump_ir

Pretty-prints an IRProgram as a human-readable text string. Useful for debugging and inspecting compiled programs.
ir
IRProgram
required
The IR program to print.
Returns: a multi-line string with the program name, effect, safety flag, register declarations, and indented op listing.