wai-quantum 0.4.3

A deterministic quantum stack in pure Rust: byte-exact circuit simulation (statevector / stabilizer / tensor-network MPS / sparse-Pauli backends), sparse Pauli dynamics at utility scale (arbitrary angles, 1024 qubits), belief-propagation tensor networks on the hardware graph, error mitigation, qLDPC decoding, noise learning, circuit-equivalence proofs, a phasor interference-ML layer, information-theoretic limits, noisy channels and state tomography, and signed energy-accounted receipts. No QPU, no cloud, no system libraries in the default features — identical results native, in the browser, and as a WASI component at the edge; the opt-in WebGPU member reaches the platform's GPU interface.
Documentation
//! 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<String, f64> {
    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::<u32>().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}");
    }
}