demos/ directory contains complete, runnable examples that show how b01t programs are structured in practice. Each demo pairs a @coherent or @adaptive circuit with its classical driver, covering algorithms from introductory textbook problems through to multi-layer coherent pipelines. Reading these alongside the source code in b01t/zoo/ is the fastest way to understand how the DSL components fit together.
Grover search (demos/grover_search/)
Grover search (demos/grover_search/)
Implements Grover’s algorithm to find Run it:
|11⟩ in a 2-qubit space. The demo shows how to inline the oracle and diffusion operator inside a @parametric step, then drive two iterations from a @adaptive top-level circuit.What it demonstrates: @adaptive + @parametric composition, repeat, measure_all, ancilla discipline in a broad-IR context.Deutsch's algorithm (demos/deutsch/)
Deutsch's algorithm (demos/deutsch/)
Determines whether a 1-bit Boolean function The algorithm prepares Run it:
f: {0,1} → {0,1} is constant or balanced using a single quantum query. Classically you need two evaluations; Deutsch’s algorithm needs one.What it demonstrates: @coherent oracle construction, @adaptive algorithm, phase kickback with |−⟩ target, measure on a single qubit.The oracle make_deutsch_oracle(f0, f1) implements U_f|x,y⟩ = |x, y ⊕ f(x)⟩ using only permutation gates (X, CX):|+⟩ on the input and |−⟩ on the target, queries once, then measures. The result is 0 for constant functions and 1 for balanced functions:Bernstein-Vazirani (demos/bernstein_vazirani/)
Bernstein-Vazirani (demos/bernstein_vazirani/)
Recovers a hidden binary string The algorithm applies Hadamard on all inputs, queries the oracle, applies Hadamard again, and measures — the output is the hidden string Run it:
s from the function f(x) = s·x (mod 2) using a single quantum query, where a classical algorithm needs n queries.What it demonstrates: @coherent oracle with a secret parameter, @adaptive algorithm, measure_all, for_each-style Hadamard layers.The oracle implements U_f|x,y⟩ = |x, y ⊕ (s·x)⟩ by applying CX(x_i, target) for each i where s_i = 1:s directly:Simon's algorithm (demos/simon/)
Simon's algorithm (demos/simon/)
Finds a hidden XOR-mask Run it:
s satisfying f(x) = f(x ⊕ s) for all x, using O(n) quantum rounds followed by classical Gaussian elimination. Classically the problem requires exponentially many queries.What it demonstrates: multi-register @coherent oracle, repeated @adaptive rounds, classical post-processing to recover a hidden period.Each quantum round produces a random string y satisfying y·s = 0 (mod 2). After n − 1 linearly independent samples, s is recovered classically:Shor's algorithm (demos/shor/)
Shor's algorithm (demos/shor/)
Factors an integer The measurement is then decoded classically using continued fractions. The demo includes helper utilities for this post-processing step:Run it:
N by finding the period of a^x mod N using Quantum Phase Estimation with a modular exponentiation oracle.What it demonstrates: @adaptive top-level circuit, @parametric modular exponentiation inlined for broad-IR, inverse_qft from zoo.qft, and classical continued-fraction post-processing.make_shor_circuit(a_val, N, num_counting_bits) returns an @adaptive function that:- Initialises the work register to
|1⟩. - Applies Hadamard to the counting register.
- Runs the modular exponentiation oracle.
- Applies
inverse_qfton the counting register. - Measures the counting register.
Rollout oracle (demos/rollout/)
Rollout oracle (demos/rollout/)
Implements coherent rollout oracles for sequential decision problems, where a quantum circuit simulates multiple rounds of a stochastic environment in superposition.What it demonstrates: multi-register Run it:
@coherent state-preparation, rank_select_binary from zoo.rank_select, complex ancilla discipline across many sub-circuits.Two environments are provided:sway/— a two-player stochastic board game where black and white alternate placing stones on a grid, with stochastic rule transitions.epidemic/— an SIR epidemic intervention model where a policy selects interventions over time.
- Placing selector registers in uniform superposition (
Hon each bit). - Using
rank_select_binaryto coherently map a selector index to the corresponding legal move. - Applying the transition and terminal evaluation circuits.
Best arm (demos/best_arm/)
Best arm (demos/best_arm/)
A full coherent pipeline that identifies the highest-payoff action in a decision problem using quantum maximum finding. It composes three layers: a rollout oracle, coherent amplitude estimation, and Dürr–Høyer maximum finding.What it demonstrates: end-to-end composition of Each “arm” is a different first action for the player. The arm oracle fixes the first-round selector to a specific action index while leaving the rest of the game randomness in superposition:Run it:
zoo.qae.make_coherent_ae, zoo.max_finding.make_comparison_oracle, and zoo.max_finding.DurrHoyerRunner. This is the most complex demo and shows how the zoo modules stack together.The pipeline is: