QuantumCircuit — without running a single simulation.
The example is a one-qubit phase oracle: it borrows an ancilla qubit, copies information from the system into it, kicks back a phase, and uncomputes. b01t verifies all three steps automatically.
Import b01t
Start by importing the components you need. The
@coherent decorator marks a function as an exact coherent program. QReg represents a quantum register. The gates (cx, z) come from the closed gate set. Certification is the enum you will check to confirm your program is safe.The ancilla discipline helpers — ancilla, compute, phase, uncompute — come from b01t.kit:Define a @coherent function
Write your quantum program as a regular Python function and decorate it with The
@coherent. The function takes QReg arguments — one per quantum register your program operates on.Inside the function, use ancilla as a context manager to borrow a helper qubit. Then describe what happens in three named blocks:compute— copy system information into the ancilla using permutation gates onlyphase— apply a diagonal rotation to the ancillauncompute— automatically reverse the compute step, returning the ancilla to |0⟩
compute block here uses cx (CNOT), which is a permutation gate — it flips anc[0] if and only if sys[0] is |1⟩. The phase block applies z (a diagonal gate) to kick back a phase. The uncompute() call auto-generates the inverse of the compute block, so the ancilla returns to |0⟩.You do not write the uncompute operations yourself. b01t derives them automatically from the compute block, ensuring the inverse is structurally correct.
Build the program
To produce a certified This call runs the structural checks. If anything in your program violates the ancilla discipline — wrong gate in a compute block, missing uncompute, entangled ancilla — you get a
ExactProgram, call .build_exact() on your decorated function. Pass each register as a (name, size) tuple:DSLValidationError here, before any circuit is created.Check the certification
The returned This is not a runtime check of a simulation result. It is a structural certificate produced by the build process, backed by a machine-checked proof in Lean 4 (the Hero Theorem).
ExactProgram carries a certification field. For a function decorated with @coherent, a successful build always produces Certification.SAFE — a static proof that the program is a unitary channel and the ancilla is clean:Compile to Qiskit
Once you have a certified program, lower it to b01t’s intermediate representation and compile it to a Qiskit The
QuantumCircuit using QiskitBackend:lower_exact_program step converts the ExactProgram AST into the IR that the backend understands. QiskitBackend().emit(ir) then produces a standard Qiskit QuantumCircuit that you can pass to any Qiskit executor or transpiler.Complete example
Here is the full program in one block:Next steps
Ancilla discipline
Learn the rules for compute, phase, and uncompute blocks in depth
Safety model
Understand the Hero Theorem and what Certification.SAFE guarantees
Writing coherent programs
Patterns for larger programs, multiple ancilla cycles, and composition
Qiskit backend
Compilation options, transpilation, and running on real hardware