#![cfg(feature = "quantum_spd")]
use wai_quantum::quantum_spd::{Pauli, SpdConfig, expect_z, expectation, heavy_hex_127, kicked_ising};
fn theta(k: u32) -> f64 {
f64::from(k) * std::f64::consts::PI / 32.0
}
#[test]
fn five_step_magnetization_matches_the_exact_values() {
let mz: Vec<(f64, Vec<(u32, Pauli)>)> = (0..127).map(|q| (1.0 / 127.0, vec![(q, Pauli::Z)])).collect();
for (k, exact) in [(1, 0.995131), (2, 0.979836)] {
let c = kicked_ising(127, &heavy_hex_127(), theta(k), 5);
let r = expectation(&c, &mz, &[], &SpdConfig { threshold: 1e-7, max_weight: None }).unwrap();
let err = (r.value - exact).abs();
assert!(err <= r.truncation_bound + 5e-7, "k = {k}: error {err:e} exceeds the bound {:e}", r.truncation_bound);
assert!(err < 3e-5, "k = {k}: Mz = {} against {exact}", r.value);
}
}
#[test]
fn twenty_step_z62_lies_among_the_converged_classical_values() {
let c = kicked_ising(127, &heavy_hex_127(), theta(2), 20);
let r = expect_z(&c, 62, &SpdConfig { threshold: 1e-4, max_weight: None }).unwrap();
assert!((0.9776..=0.9796).contains(&r.value), "⟨Z₆₂⟩ = {}", r.value);
}