open-standards/wai/wai-quantum/examples/qec_frame.rs
Transaction Science 8ccc374966
Some checks failed
joule-moq-room room service / joule-moq-room · does this change touch it (push) Successful in 42s
wai-audit collector and player integration / does this change touch it (push) Successful in 32s
joule-moq-remote host agent / joule-moq-remote · does this change touch it (push) Successful in 47s
wai-app and Create / wai-app · does this change touch it (push) Successful in 40s
wai-quantum command line / does this change touch it (push) Successful in 22s
wai-fleet service / does this change touch it (push) Successful in 35s
wai-ledger service / does this change touch it (push) Successful in 35s
WAI operation catalogue / does this change touch it (push) Successful in 35s
wai-quantum clippy / does this change touch it (push) Successful in 47s
wai-quantum contract / does this change touch it (push) Successful in 37s
wai-quantum docs, course and locales / does this change touch it (push) Successful in 37s
wai-quantum editors / does this change touch it (push) Successful in 37s
wai-quantum resource estimation / does this change touch it (push) Successful in 15s
wai-quantum other formats / does this change touch it (push) Successful in 29s
wai-quantum OpenQASM reader / does this change touch it (push) Successful in 39s
wai-quantum for JavaScript / does this change touch it (push) Successful in 42s
WAI breaking changes and the conformance runner / WAI breaking · does this change touch WAI (push) Successful in 17s
wai-quantum pulse and dynamics / does this change touch it (push) Successful in 28s
wai-quantum for Python / does this change touch it (push) Successful in 29s
wai-quantum qudit jobs / does this change touch it (push) Successful in 21s
wai-quantum error correction and mitigation / does this change touch it (push) Successful in 22s
wai-quantum wasmQ / does this change touch it (push) Successful in 18s
wai-quantum extension points / does this change touch it (push) Successful in 24s
wai-sink-swift native sink package / does this change touch it (push) Successful in 33s
wai-quantum views in agent hosts / does this change touch it (push) Successful in 36s
wai-app and Create / wai-app · tests, clippy, the line language's verifier (linux) (push) Successful in 31s
joule-moq-web browser client / joule-moq-web · does this change touch it (push) Successful in 4m4s
joule-moq-http live HTTP egress / joule-moq-http · does this change touch it (push) Successful in 4m13s
wai-audit collector and player integration / collector · linux (push) Successful in 2m13s
wai-fleet service / service · linux (push) Successful in 2m14s
wai-quantum contract / the policy is linked, and the deprecations page reads (push) Successful in 8s
wai-ledger service / service · linux (push) Successful in 2m34s
wai-quantum docs, course and locales / the Studio's words in every locale · linux (push) Successful in 21s
wai-quantum clippy / clippy, warnings denied, every feature set · linux (push) Successful in 3m14s
wai-quantum service / does this change touch it (push) Successful in 7m26s
wai-quantum service / service energy · linux packages (push) Failing after 5s
wai-quantum studio and desktop / does this change touch it (push) Successful in 7m56s
WAI Studio / does this change touch it (push) Successful in 7m38s
wai-quantum variational and algorithm library / does this change touch it (push) Successful in 7m56s
wai-sink-android native sink library / does this change touch it (push) Successful in 7m45s
wai-quantum verdicts and repairs / does this change touch it (push) Successful in 7m48s
wai-quantum docs, course and locales / the course and the command line's languages · linux (push) Successful in 4m17s
wai-quantum OpenQASM reader / corpus under wasm32-wasip2 (wasmtime) (push) Successful in 1m31s
wai-quantum OpenQASM reader / reader and corpus · linux (push) Successful in 2m41s
wai-quantum other formats / the set under wasm32-wasip2 (wasmtime) (push) Successful in 3m29s
wai-quantum editors / editors · linux (push) Successful in 5m35s
wai-quantum pulse and dynamics / reader, simulator and pulse jobs under wasm32-wasip2 (wasmtime) (push) Successful in 1m45s
WAI breaking changes and the conformance runner / WAI breaking · wire, record and API against main · linux (push) Successful in 1m45s
wai-quantum pulse and dynamics / reader, simulator and pulse jobs · linux, release (push) Successful in 2m26s
wai-quantum resource estimation / estimation and calibration · linux, release (push) Successful in 6m45s
joule-moq-remote host agent / joule-moq-remote, every target (linux-arm64) (push) Successful in 2m5s
wai-quantum other formats / readers, writers and the set · linux (push) Successful in 7m0s
wai-quantum for JavaScript / javascript · linux (push) Successful in 4m27s
wai-quantum qudit jobs / the module and the conformance set under wasm32-wasip2 (wasmtime) (push) Successful in 1m14s
wai-quantum wasmQ / the reference modules rebuild to their modules of record · linux (push) Successful in 29s
wai-quantum contract / API compatibility · linux (push) Successful in 10m36s
wai-quantum contract / schemas and the committed tool lists · linux (push) Successful in 10m38s
wai-quantum extension points / the registry under wasm32-wasip2 (wasmtime) (push) Successful in 2m10s
wai-quantum wasmQ / profile, engines, reference modules, adversarial, vectors · linux (push) Successful in 4m13s
wai-quantum error correction and mitigation / codes, decoders, texts and mitigation · linux, release (push) Successful in 5m12s
wai-quantum extension points / the registry and the example · linux (push) Successful in 4m20s
wai-quantum wasmQ / interpreter and vectors under wasm32-wasip2 (wasmtime) (push) Successful in 3m33s
WAI Studio / the catalogue's actions, the unit tests and the core · linux (push) Successful in 53s
wai-quantum pulse and dynamics / the same bits · linux-arm64 (push) Successful in 7m20s
WAI operation catalogue / the catalogue and every door · linux (push) Successful in 16m4s
WAI breaking changes and the conformance runner / WAI breaking and conform · their tests, and the independent verifiers through wai conform · linux (push) Successful in 10m4s
repository checks / lockfiles, advisories, tests in CI, workflow hygiene, spec and section references, public text (push) Successful in 10m57s
wai-quantum for Python / python · linux (push) Successful in 8m53s
wai-quantum qudit jobs / the module, the job, the conformance set, the referee and the verb · linux (push) Successful in 8m50s
wai-quantum variational and algorithm library / parameters, gradients, optimisers, VQE, QAOA and builders · linux, release (push) Successful in 2m29s
wai-quantum views in agent hosts / views · the page and its engine (push) Successful in 6m52s
joule-moq-room room service / joule-moq-room, every target (push) Successful in 11m36s
wai-quantum verdicts and repairs / verdicts, repairs and the intent set · linux (push) Successful in 3m8s
wai-quantum verdicts and repairs / the intent set and the verdict under wasm32-wasip2 (wasmtime) (push) Successful in 3m3s
joule-moq-http live HTTP egress / joule-moq-http, every target (push) Successful in 3m20s
wai-quantum studio and desktop / studio · browser (push) Successful in 5m43s
wai-quantum variational and algorithm library / parameters, gradients, optimisers, VQE, QAOA and builders · linux-arm64, release (push) Successful in 2m43s
wai-quantum studio and desktop / desktop app · linux (push) Successful in 6m59s
wai-quantum extension points / the registry and the example · linux-arm64 (push) Successful in 5m34s
wai-quantum views in agent hosts / views · a scripted host (push) Successful in 10m23s
wai-sink-android native sink library / the JNI layer and the platform-free half on the host JVM · linux-arm64 (push) Successful in 5m23s
wai-quantum service / service · linux (push) Successful in 9m57s
wai-quantum command line / command line · linux (push) Successful in 25m50s
wai-quantum docs, course and locales / every command and snippet in the docs · linux (push) Successful in 24m41s
joule-moq-remote host agent / joule-moq-remote, every target (macos) (push) Successful in 52s
wai-quantum command line / command line · macos (push) Successful in 2m44s
wai-fleet service / service · macos (push) Successful in 50s
wai-audit collector and player integration / collector, player integration and the browser end to end · macos (push) Successful in 3m20s
WAI Studio / Studio in WebKit · linux (push) Successful in 19m4s
wai-ledger service / service · macos (push) Successful in 1m12s
wai-quantum editors / editors · macos (push) Successful in 2m25s
wai-quantum pulse and dynamics / the same bits · macos (push) Successful in 2m50s
wai-quantum for Python / python · macos (push) Successful in 3m22s
wai-quantum qudit jobs / the same bits · macos (push) Successful in 1m55s
wai-app and Create / wai-app · Create, browser end-to-end (macos) (push) Successful in 9m53s
wai-quantum wasmQ / profile, engines, reference modules, adversarial, vectors · macos (push) Successful in 3m6s
wai-quantum service / service · macos (push) Successful in 7m32s
wai-quantum studio and desktop / desktop app · macos (push) Successful in 4m12s
joule-moq-web browser client / joule-moq-web · browser end-to-end (macos) (push) Successful in 15m5s
wai-sink-swift native sink package / libwai slices, desktop tests, simulator tests · macos (push) Successful in 17m31s
wai-sink-android native sink library / every ABI, the AAR, and the instrumented tests in a headless emulator · macos (push) Successful in 9m55s
WAI Studio / Studio in Chromium and Firefox · macos (push) Successful in 14m11s
wai-quantum studio and desktop / desktop app · windows (push) Successful in 12m31s
WAI Quantum: measurement records from the frame simulator, the same bits on every machine, and cultivation circuits
The frame simulator gives every measurement's result (sample_measurements):
one noiseless run found by an inverse tableau, and each shot's frame over it.
The samples are specified (extensions/quantum-sim.md section 10) and pinned in
the conformance set with two digests a circuit. A noise draw whose skip passes
the batch takes no logarithm; a rate below 2^-53 no longer flips every shot.
Distance 7, 7 rounds, p = 0.001, one thread of the build host: 6.0 million
shots a second of detection events (4.0 million before), 6.2 million of records.

quantum_cultivate generates the core of magic-state cultivation in the
distance-3 and distance-5 colour codes, as OpenQASM 3 and as a Clifford form
with detectors, and checks it by stabilizer simulation and exactly with every
fault and pair of faults. Not the published circuits: no growth, no escape,
and the distance-5 circuit is protected no better than the distance-3 one.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-11 08:46:24 -05:00

115 lines
6.2 KiB
Rust

//! Noisy Clifford circuits from the command line.
//!
//! ```text
//! cargo run --release --example qec_frame --features quantum_frame -- gen 5 5 0.001
//! cargo run --release --example qec_frame --features quantum_frame -- dem circuit.txt
//! cargo run --release --example qec_frame --features quantum_frame -- sample circuit.txt 100000 7
//! cargo run --release --example qec_frame --features quantum_frame -- decode circuit.txt events.txt
//! cargo run --release --example qec_frame --features quantum_frame -- rate circuit.txt 100000 7
//! cargo run --release --example qec_frame --features quantum_frame -- records circuit.txt 100000 7
//! cargo run --release --example qec_frame --features quantum_frame -- speed 7 7 0.001 4000000 7
//! ```
use wai_quantum::quantum_frame::{error_model, parse, reference, sample, sample_measurements, surface_code_memory};
use wai_quantum::quantum_match::MatchingGraph;
fn main() {
let a: Vec<String> = std::env::args().collect();
let read = |p: &str| std::fs::read_to_string(p).expect("read circuit");
match a.get(1).map(String::as_str) {
Some("gen") => {
let d: u32 = a[2].parse().unwrap();
let r: u32 = a[3].parse().unwrap();
let p: f64 = a[4].parse().unwrap();
print!("{}", surface_code_memory(d, r, p));
}
Some("dem") => {
let c = parse(&read(&a[2])).expect("parse");
print!("{}", error_model(&c).expect("model").to_text());
}
Some("sample") => {
let c = parse(&read(&a[2])).expect("parse");
let shots: usize = a[3].parse().unwrap();
let seed: u64 = a[4].parse().unwrap();
let s = sample(&c, shots, seed);
for d in 0..s.detectors {
println!("D{d} {}", s.count(d));
}
let flips = (0..shots).filter(|&i| s.flips(i) & 1 == 1).count();
println!("L0 {flips}");
}
// One line per shot of fired detector indices; prints one predicted
// observable mask per line.
Some("decode") => {
let c = parse(&read(&a[2])).expect("parse");
let g = MatchingGraph::from_model(&error_model(&c).expect("model")).expect("graphlike");
let mut out = String::new();
for line in read(&a[3]).lines() {
let fired: Vec<u32> = line.split_whitespace().map(|t| t.parse().unwrap()).collect();
out += &format!("{}\n", g.decode(&fired).expect("decode"));
}
print!("{out}");
}
// Sample and decode: logical failures out of shots, and the time spent.
Some("rate") => {
let c = parse(&read(&a[2])).expect("parse");
let shots: usize = a[3].parse().unwrap();
let seed: u64 = a[4].parse().unwrap();
let g = MatchingGraph::from_model(&error_model(&c).expect("model")).expect("graphlike");
let t0 = std::time::Instant::now();
let s = sample(&c, shots, seed);
let t1 = t0.elapsed();
let f = g.failures(&s).expect("decode");
let t2 = t0.elapsed() - t1;
println!("{f} {shots} sample_s={:.3} decode_s={:.3}", t1.as_secs_f64(), t2.as_secs_f64());
}
// Every measurement's result: how many shots read 1 at each.
Some("records") => {
let c = parse(&read(&a[2])).expect("parse");
let shots: usize = a[3].parse().unwrap();
let seed: u64 = a[4].parse().unwrap();
let s = sample_measurements(&c, shots, seed);
for r in 0..s.measurements {
println!("M{r} {}", s.count(r));
}
}
// Shots a second on one thread for a rotated surface-code memory
// experiment: detection events, then full measurement records (the
// reference run's time counted in). The digests are of every bit
// sampled, so two machines can be compared.
Some("speed") => {
let d: u32 = a[2].parse().unwrap();
let rounds: u32 = a[3].parse().unwrap();
let p: f64 = a[4].parse().unwrap();
let shots: usize = a[5].parse().unwrap();
let seed: u64 = a[6].parse().unwrap();
let c = parse(&surface_code_memory(d, rounds, p)).expect("parse");
println!("d={d} rounds={rounds} p={p}: {} qubits, {} operations, {} measurements, {} detectors", c.qubits, c.ops.len(), c.measurements, c.detectors.len());
let digest = |words: &mut dyn Iterator<Item = u64>| {
let mut h = blake3::Hasher::new();
for w in words {
h.update(&w.to_le_bytes());
}
h.finalize().to_hex()[..16].to_string()
};
let mut best = (f64::MAX, f64::MAX);
let mut digests = (String::new(), String::new());
for _ in 0..5 {
let t0 = std::time::Instant::now();
let s = sample(&c, shots, seed);
best.0 = best.0.min(t0.elapsed().as_secs_f64());
let t0 = std::time::Instant::now();
let m = sample_measurements(&c, shots, seed);
best.1 = best.1.min(t0.elapsed().as_secs_f64());
digests.0 = digest(&mut (0..s.detectors).map(|k| s.count(k)).chain((0..shots).map(|i| s.flips(i))));
digests.1 = digest(&mut c.detectors.iter().flat_map(|recs| m.parity(recs)).chain((0..m.measurements).map(|r| m.count(r))));
}
let t0 = std::time::Instant::now();
let r = reference(&c);
let reference_s = t0.elapsed().as_secs_f64();
println!("detection events: {shots} shots in {:.4} s, {:.0} shots/s on one thread, digest {}", best.0, shots as f64 / best.0, digests.0);
println!("measurement records: {shots} shots in {:.4} s, {:.0} shots/s on one thread, digest {}", best.1, shots as f64 / best.1, digests.1);
println!("reference run: {:.6} s, {} of {} results random without noise", reference_s, r.random, c.measurements);
}
_ => eprintln!("usage: qec_frame gen D ROUNDS P | dem FILE | sample FILE SHOTS SEED | decode FILE EVENTS | rate FILE SHOTS SEED | records FILE SHOTS SEED | speed D ROUNDS P SHOTS SEED"),
}
}