Weyl’s trusted computing base (TCB) is organized around a small trusted kernel, independent oracles, and deterministic replay. Because physical derivations span symbolic algebra, multi-precision numerical perturbation theory, and universal theorem proving, no single testing layer suffices. Weyl structures verification as a five-layer pyramid—from millisecond PR checks to nightly end-to-end physics runs—reinforced by mutation testing, replay auditing, and performance regression gates.
Five-Layer Verification Pyramid
The first three layers run on every Pull Request for fast feedback; the top two run nightly and before releases to validate full physical workflows:
| Layer | Scope | Tooling & Harness | Cadence |
|---|---|---|---|
| L1 Unit & Property | Algebra axioms, arithmetic, CRT/Wang reconstruction, error-lattice laws | proptest, dense matrices ( qubits) | Every PR |
| L2 Frontend & Types | Parser fuzzing, diagnostic snapshots, positive/negative T-rule tests, type-checker matrix oracle | cargo-fuzz, insta, random programs ( qubits) | Every PR |
| L3 Differential Kernel | weyl-cas sort-merge vs naive hash table; spill vs RAM; -thread byte equality | Custom differential driver | Every PR (small scale) |
| L4 Physical Gold Standards | Stage A free-fermion exact comparison to order 14; literature pCUT tables; modular data | Canonical text + SHA-256 hashes | Nightly |
| L5 Oracles & Theorems | Stage B double-double ED residual slopes; end-to-end weylc run; Lean 4 proof re-checking | weyl-oracle, weyl-lean | Nightly / Release |
Static Type Checking and Frontend Testing (L2)
Frontend verification tests the behavior and physics diagnostics of rules on concrete cases (note that static type checking is incomplete by design, and testing does not replace a formal soundness proof; see Type System §8). Every typing rule in weyl-types (T-Ham, T-Bdy, T-Pcut, T-Braid, T-Solve, and others) is exercised by both positive tests and at least one rejected program—such as anti-Hermitian products triggering E0301, non-commuting triggering E0413, or extrapolated scalars in exact claims triggering E0330—with both human diagnostics and machine-readable JSON proof chains locked by insta snapshots. Beyond hand-crafted cases, a differential matrix oracle expands randomly generated small programs ( qubits, plus non-abelian ) into dense matrices to independently verify every static claim of Hermiticity, commutation, anyon charge, and conserved stabilizer set . In parallel, cargo-fuzz continuously feeds arbitrary byte streams into the lexer and parser to ensure panic-free recovery and valid UTF-8 span slicing.
#[test]
fn type_checker_soundness_vs_dense_matrix_oracle() {
for seed in 0..256u64 {
let prog = random_local_hamiltonian(/*n_qubits=*/ 8, seed);
let typed = weyl_types::check_program(&prog).expect("well-typed random model");
let h_mat = expand_to_dense_matrix(&prog.hamiltonian);
// Static Herm guarantee => exact matrix equality H == H†
if typed.herm == Herm::Herm {
assert_eq!(h_mat, h_mat.conjugate_transpose());
}
// Static Cons(H) => exact zero commutator with H
for stab in typed.conserved_stabilizers() {
let s_mat = expand_to_dense_matrix(stab);
assert!(is_zero_matrix(&(h_mat.mul(&s_mat) - s_mat.mul(&h_mat))));
}
}
}Property-Based Testing of Algebraic Normal Forms (L1)
Core algebraic laws in weyl-canonical and weyl-num are tested across thousands of randomly generated words and coefficient vectors using proptest:
proptest! {
#[test]
fn graded_algebra_axioms(a in arb_pauli_word(6), b in arb_pauli_word(6), c in arb_pauli_word(6)) {
// 1. Associativity: (a * b) * c == a * (b * c) including Z_4 global phase
prop_assert_eq!(mul_word(&mul_word(&a, &b), &c), mul_word(&a, &mul_word(&b, &c)));
// 2. Adjoint involution: (a * b)† == b† * a†
prop_assert_eq!(adjoint(&mul_word(&a, &b)), mul_word(&adjoint(&b), &adjoint(&a)));
// 3. Exact element-wise agreement with 2^6 × 2^6 dense matrix multiplication
prop_assert_eq!(to_dense(&mul_word(&a, &b)), dense_matmul(&to_dense(&a), &to_dense(&b)));
}
}For linear combinations under the Lie bracket , property tests additionally verify distributivity and the Jacobi identity:
In weyl-num, property suites validate 63-bit prime-field () axioms, centered multi-prime CRT recovery, and uniqueness of Wang’s rational reconstruction whenever .
Cross-Backend Differential Testing (L3–L5)
Weyl requires outputs to be independent of execution path and concurrency level, and differential testing enforces this requirement across three boundaries. At Layer 3, weyl-cas maintains a simple hash-table reference normalize_naive; for any generated multiset of terms, the differential driver compares normalize_naive against pure in-memory radix sort-merge, a tiny MemBudget forcing multi-way NVMe disk spills, and -thread parallel runs, asserting byte-for-byte identical output streams across all four.
At Layer 4, the 2D Toric Code Stage A benchmark serves as an exact analytical oracle: its free-fermion solution gives dispersion and ground-state energy , against which all pCUT rational series coefficients and up to order 14 are compared term-by-term with zero tolerance. For non-integrable Stage B perturbations at Layer 5, weyl-oracle constructs an independent double-double (~106-bit significand) Lanczos MatVec directly from the raw HIR Hamiltonian without reusing pCUT stabilizer maps; along fixed rays , it checks that the log-log residual slope matches the first omitted order within a tolerance of , returning Inconclusive whenever numerical noise or finite-size wrapping interferes.
Below is the L3 differential driver comparing naive, pure-RAM, spilled, and multi-threaded runs, followed by L5 oracle telemetry:
#[test]
fn differential_sort_merge_vs_naive_spill_and_threads() {
let raw = generate_random_terms(50_000, /*n_primes=*/ 4, /*seed=*/ 0x5745_594c);
let expected = normalize_naive(&raw);
// 1. Pure in-memory sort-merge (1 thread vs 8 threads)
let ram_1t = normalize_with(&raw, MemBudget { max_bytes: 256 << 20 }, None, 1);
let ram_8t = normalize_with(&raw, MemBudget { max_bytes: 256 << 20 }, None, 8);
// 2. Tiny budget (64 KiB) forcing multi-way NVMe disk spill + loser-tree merge
let spilled = normalize_with(&raw, MemBudget { max_bytes: 64 << 10 }, Some(tmp_dir()), 4);
assert_eq!(ram_1t.as_wire_bytes(), expected.as_wire_bytes());
assert_eq!(ram_8t.as_wire_bytes(), expected.as_wire_bytes());
assert_eq!(spilled.as_wire_bytes(), expected.as_wire_bytes());
}When an L5 oracle detects a mismatch, it emits structured telemetry with deterministic hints (generated strictly by compiler rules such as newly appearing cluster lengths, never by an LLM):
{
"schema": "weyl.telemetry",
"run_id": "r-000173",
"node": "cluster.eval",
"status": "oracle_failed",
"ir": { "layer": "KIR", "terms_peak": 48211033, "bytes_peak": 21474836480, "spill_bytes": 0 },
"oracle": {
"kind": "ed",
"verdict": "fail",
"observable": "gap",
"residual_slope": 8.9,
"expected_slope": 13.0,
"precision": "double-double",
"size_L": 16,
"first_bad_order": 8
},
"hints": ["terms at order 8 involve clusters of length 9 for the first time"]
}Error-Lattice Soundness Checks
Dedicated property suites audit the error lattice . They verify reflexivity, antisymmetry, and transitivity of , together with monotonicity of and valuation-aware , and confirm that monomial ideals remain minimal Dickson-basis antichains with no redundant generators after every merge. Crucially, the suites enforce a no-silent-downgrade invariant: passing an ED oracle, Padé extrapolation, or e-graph rewrite can never downgrade Trunc or Epi back to Exact, and any value carrying a non-empty epistemic set is statically rejected by exact claim a = b (E0330).
proptest! {
#[test]
fn error_lattice_no_silent_downgrade(e1 in arb_err(), e2 in arb_err(), v1 in 0u32..4, v2 in 0u32..4) {
let sum = add_err(&e1, &e2);
let prod = mul_err(&e1, v1, &e2, v2);
// Epistemic provenance sets are monotonically non-decreasing under all ops
prop_assert!(e1.epi.is_subset(&sum.epi) && e2.epi.is_subset(&sum.epi));
prop_assert!(e1.epi.is_subset(&prod.epi) && e2.epi.is_subset(&prod.epi));
// Any non-Exact input prevents the sum from ever collapsing back to Exact
if !e1.is_exact() || !e2.is_exact() {
prop_assert!(!sum.is_exact());
}
}
}Mutation Testing: Auditing the Oracles
To verify that the oracles genuinely detect subtle kernel bugs, weyl/crates/weylc/tests/mutations.rs injects controlled faults and asserts that Layer 4 or Layer 5 fails with an accurate first_bad_order diagnostic:
| Injected Fault | Algebraic / Physical Breakage | Catching Layer | Diagnostic Requirement |
|---|---|---|---|
| Flip sign of a single pCUT | Corrupts order- effective Hamiltonian | L4 / L5 | oracle_failed with first_bad_order == k |
| Drop all clusters of length | Breaks linked-cluster additivity at order | L4 / L5 | first_bad_order matches first order using |
| Corrupt one Pauli phase entry | Breaks local commutation & adjoint phase | L1 / L4 | Fails both dense-matrix and free-fermion checks |
| Omit one stabilizer generator | Corrupts sector energy function | L4 / L5 | ED residual slope deviates from expected |
Scheduler Equivalence & Deterministic Replay
Running the same derivation under the built-in heuristic scheduler, a random scheduler, and the LLM MCP scheduler must produce byte-identical published results. Nightly CI also replays every append-only action log via weylc replay <log> to confirm identical output hashes, and re-checks all Lean 4 theorem certificates against pinned Mathlib revisions.
Performance Regression Benchmarks (weyl/benches/)
Weyl tracks three hot-path metrics via criterion, recorded in weyl/benches/baseline.json; any PR regressing a core metric by more than 10% blocks merge:
| Benchmark | Target Crate | Reference Baseline | Throughput / Memory Ceiling |
|---|---|---|---|
merge/normalize_1M_terms_single_core | weyl-cas stream sort-merge | 82.89 ms | terms/s single-core (target /s); terms RAM |
pcut/tables_dq_2_order_8 | weyl-series flow recursion | 1.71 ms | Exact memoized table generation + disk cache |
lanczos/step_L10_W2_dd | weyl-oracle double-double MatVec | 6.28 ms | 106-bit significand single-sector Lanczos iteration |
# Run all unit and proptest property suites (L1–L3)
cargo test --workspace
# Run mutation tests to verify oracle fault detection
cargo test -p weylc --test mutations
# Replay a nightly action log and verify byte-identical output hashes
weylc replay logs/nightly-stage-b.jsonl --verify-hash
# Run Criterion benchmarks against weyl/benches/baseline.json (>10% regression blocks merge)
cargo bench --workspaceCI and Release Gate Checklist
Every merge and release enforces tiered verification gates. Pull requests must clear the merge gate, which runs the L1 property suites, L2 positive and negative type snapshots, L3 term-stream differential tests, and Criterion benchmarks with regressions bounded by . The nightly gate escalates to the L4 Stage A 14th-order free-fermion zero-tolerance check, L5 Stage B double-double ED residual slopes, the full mutation suite, and the weylc replay determinism audit. Finally, the release gate requires full Lean 4 re-verification of all built-in theorems (modular_relations, ssb_boundary, twisted_boundary) on pinned Mathlib, alongside byte-identical equivalence across the heuristic, random, and LLM schedulers.