//! 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 = [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."); }