b01t.kit.routing provide a single set of names that work correctly inside both exact (@coherent, @primitive) and broad (@parametric, @adaptive) build contexts. You write the same ancilla, compute, phase, uncompute, par, and adjoint calls regardless of decorator, and b01t routes to the appropriate implementation automatically. Import them from b01t directly.
ancilla
size fresh qubits. Use with a with statement; the returned register is only valid inside the block.
Number of ancilla qubits to allocate.
@coherent), the block enforces the full compute / phase (or apply) / uncompute discipline and certifies ancilla cleanliness. In a broad context (@parametric), it records an AncillaBlockOp in the IR.
Nested ancilla blocks are not supported and raise DSLValidationError.
compute
fn is called immediately; any gates emitted inside it are captured as compute ops.
A zero-argument callable that emits gates. In exact context, only permutation gates are allowed (
x, cx, ccx, swap, mcx). In broad context, only gates from _ALLOWED_COMPUTE are accepted.compute must be the first section inside an ancilla block. Calling it outside a block raises DSLValidationError.
phase
fn is called immediately; gates emitted inside it are captured as phase ops and must all be diagonal.
A zero-argument callable that emits diagonal gates. In exact context, only
z, cz, ccz, s, sdg, t, tdg, mcz are allowed. In broad context, only gates from _ALLOWED_PHASE (which also includes rz) are accepted.phase must follow compute. Calling it before compute or outside a block raises DSLValidationError.
apply
apply allows any exact gate, but all wires used must be disjoint from the wires used in the compute block. In a broad context, apply falls through to phase semantics.
A zero-argument callable that emits gates on wires disjoint from the compute block’s wires.
apply is an alternative to phase when you want to run gates that are not diagonal — for example, applying a gate to system qubits while ancilla holds a value. The wire-disjointness constraint (the PreservesFirst condition) is checked at block finalization.
uncompute
uncompute must follow a phase or apply section. Calling it before either raises DSLValidationError. After uncompute, you can start a new compute / phase / uncompute cycle within the same ancilla block.
par
fn1 and fn2 are executed in separate capture contexts, and b01t verifies that they operate on disjoint wire sets. If any wire is shared, DSLValidationError is raised.
First sub-program. Emits gates on one subset of wires.
Second sub-program. Emits gates on a disjoint subset of wires.
adjoint
fn is re-executed in a capture context, and all its ops are reversed and inverted. The result is appended to the current program’s op sequence.
The coherent function whose inverse to emit. Must be decorated with
@coherent (exact context) or @parametric with Effect.COHERENT (broad context). Passing an @adaptive function raises DSLValidationError.The register arguments to pass to
fn when capturing its ops. These must match fn’s parameter signature.adjoint cannot be called inside an ancilla compute / phase block.