//! 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 //! ``` use wai_quantum::quantum_frame::{error_model, parse, sample, surface_code_memory}; use wai_quantum::quantum_match::MatchingGraph; fn main() { let a: Vec = 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 = 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()); } _ => eprintln!("usage: qec_frame gen D ROUNDS P | dem FILE | sample FILE SHOTS SEED | decode FILE EVENTS | rate FILE SHOTS SEED"), } }