open-standards/wai/wai-quantum/examples/threshold.rs
Transaction Science c08b9514d7
Some checks failed
no-vanity-metrics / Scan committed Markdown for vanity metrics (push) Has been cancelled
standards workspaces build + test / aac-rs (push) Has been cancelled
standards workspaces build + test / arl-rs (push) Has been cancelled
standards workspaces build + test / eoc-rs (push) Has been cancelled
standards workspaces build + test / jcp-rs (push) Has been cancelled
standards workspaces build + test / joule-code-rs (push) Has been cancelled
standards workspaces build + test / joule-ui-rs (push) Has been cancelled
standards workspaces build + test / jouleclaw-rs (push) Has been cancelled
standards workspaces build + test / joulecontract-rs (push) Has been cancelled
standards workspaces build + test / jouledesk-rs (push) Has been cancelled
standards workspaces build + test / joulehook-rs (push) Has been cancelled
standards workspaces build + test / map-rs (push) Has been cancelled
standards workspaces build + test / mesh-rs (push) Has been cancelled
standards workspaces build + test / openpay (push) Has been cancelled
standards workspaces build + test / proof-rs (push) Has been cancelled
standards workspaces build + test / sandbox-rs (push) Has been cancelled
standards workspaces build + test / sense-rs (push) Has been cancelled
standards workspaces build + test / smart-byte-rs (push) Has been cancelled
wai-quantum 0.3.13: mixed states, and a bound that classical physics cannot reach
Everything in this crate carried a pure state. That runs circuits, but it cannot
do quantum information science, because the interesting objects there are not
pure: throw away half of an entangled pair and what remains is not a state vector
at all. It is a mixture, and its entropy is the entire point.

quantum_info adds the density matrix, the partial trace that produces one, purity,
exact Pauli expectations for arbitrary strings, and CHSH. It stays in the
simulator's fixed point, so a reduced state carries a portable hash like
everything else — two machines agree on the mixture, not on a rendering of it.

The tests are the statements worth making. Half a Bell pair comes back maximally
mixed with purity exactly one half and no off-diagonal coherence, which is the
fact no state vector can express and the reason the module exists. A product
state's half stays pure. And CHSH on the Bell state reaches 2√2: past the bound of
2 that binds any local hidden-variable account of the world, and exactly at
Tsirelson's, which quantum theory itself cannot exceed. It is computed from exact
Pauli expectations rather than sampled, so the violation is arithmetic and not
statistics.

Also adds runnable examples — bell, threshold, receipt — because a crate with 22
features whose entire learning surface was one README snippet is not accessible,
whatever its API docs say.

One test of mine was wrong and is now right: mixing a state with itself returns it
numerically, not bit-for-bit, since halving twice rounds twice. Demanding an
identical hash there was demanding that fixed-point division be lossless.

224 tests pass.

Co-Authored-By: Claude Opus 5 <[email protected]>
2026-09-07 03:47:38 -04:00

32 lines
1.3 KiB
Rust

//! A quantum error correction threshold sweep.
//!
//! Below threshold a bigger code protects better; above it, worse. That crossing
//! is the whole reason error correction is believed to work, and it is a few
//! hundred thousand decodes away.
//!
//! cargo run --release --example threshold --features quantum_qec
use wai_quantum::quantum_qec::{benchmark_uf, x_distance, CssCode};
fn main() {
let trials = 4000;
println!("rotated surface code, union-find decoder, {trials} shots per point\n");
let codes: Vec<CssCode> = [3usize, 5, 7].iter().map(|&d| CssCode::surface(d)).collect();
for c in &codes {
// the distance is computed, not taken on faith from the constructor's name
let d = x_distance(c, 6).map(|d| d.to_string()).unwrap_or_else(|| ">5".into());
println!(" {} : n={} k={} d={}", c.id, c.n, c.k, d);
}
println!("\n p d=3 d=5 d=7");
for p in [0.01f64, 0.02, 0.05, 0.08, 0.12, 0.16] {
print!(" {p:<8}");
for c in &codes {
let (t, f) = benchmark_uf(c, p, trials, 11);
print!(" {:>10.4}", f as f64 / t as f64);
}
println!();
}
println!("\n Read down each column: at low p a larger code wins. Read across the\n bottom rows: past threshold that reverses, and more qubits buy less.");
}