//! Cross-tool fixtures for noisy Clifford circuits. //! //! `data/memory_z_d5.circuit` and `data/memory_x_d3.circuit` were written by //! an independent circuit generator. `data/memory_x_d3.dem` is that tool's //! detector error model of the second circuit, flattened, with identical //! mechanisms XOR-combined. Matching them checks three things against an //! implementation that shares no code with this one: //! - the generator, byte for byte; //! - the parser, including the X-basis resets and measurements our generator //! never emits; //! - the backward-sensitivity model, mechanism for mechanism. #![cfg(feature = "quantum_frame")] use std::collections::BTreeMap; use wai_quantum::quantum_frame::{error_model, parse, surface_code_memory}; #[test] fn the_generator_matches_the_reference_text() { let want = include_str!("data/memory_z_d5.circuit"); assert_eq!(surface_code_memory(5, 4, 0.001), want); } /// `"D0 D4 L0"` → probability. fn model_map(text: &str) -> BTreeMap { text.lines() .filter_map(|l| { let rest = l.trim().strip_prefix("error(")?; let (p, syms) = rest.split_once(')')?; let mut s: Vec<&str> = syms.split_whitespace().collect(); s.sort_by_key(|t| (t.as_bytes()[0], t[1..].parse::().unwrap())); Some((s.join(" "), p.parse().unwrap())) }) .collect() } #[test] fn the_model_matches_the_reference_model() { let c = parse(include_str!("data/memory_x_d3.circuit")).unwrap(); let ours = model_map(&error_model(&c).unwrap().to_text()); let theirs = model_map(include_str!("data/memory_x_d3.dem")); assert_eq!(ours.len(), theirs.len()); for (k, p) in &theirs { let q = ours.get(k).unwrap_or_else(|| panic!("missing mechanism {k}")); assert!((q / p - 1.0).abs() < 1e-9, "{k}: {q} vs {p}"); } }