open-standards/wai/wai-quantum/examples/equiv_bench/common.rs
Transaction Science 4346fc0931
Some checks failed
WAI conformance / does this change touch it (push) Has been skipped
WAI conformance / cargo-class corpora · linux (push) Has been skipped
WAI conformance / cargo-class corpora · linux-arm64 (push) Has been skipped
WAI conformance / cargo-class corpora · macos (push) Has been skipped
WAI conformance / cargo-class corpora · windows (push) Has been skipped
WAI conformance / fast integer kernels, every x86_64 kernel set (AVX-512 silicon) (push) Has been skipped
WAI conformance / quantum core and corpus under wasm32-wasip2 (wasmtime) (push) Has been skipped
WAI conformance / faces from keypoints under wasm32-wasip2 (wasmtime) (push) Has been skipped
WAI conformance / v2 vocabulary · manifests validate as stated (push) Has been skipped
WAI conformance / independent verifiers · claims, JWP, key discovery and integer payloads (Python) (push) Has been skipped
WAI conformance / independent verifiers · every verifier step, each corpus's Rust side (push) Has been skipped
WAI conformance / each feature of the independent verifiers' steps compiles alone (push) Has been skipped
WAI conformance / delivery telemetry · CMCD and CMSD against an independent library (push) Has been skipped
WAI conformance / cross-arch byte-equality · linux (push) Has been skipped
WAI conformance / cross-arch byte-equality · linux-arm64 (push) Has been skipped
WAI conformance / cross-arch byte-equality · macos (push) Has been skipped
WAI conformance / codec wrappers · fuzz smoke, text decode limits, C entry points, provenance, the semantic path (push) Has been skipped
WAI conformance / C2PA manifest emission · signed, read back, validated (push) Has been skipped
WAI conformance / independent verifiers · each needs= is what a run without packages shows (nightly) (push) Has been skipped
wai-quantum clippy / does this change touch it (push) Successful in 2m1s
wai-quantum resource estimation / does this change touch it (push) Successful in 1m59s
wai-quantum contract / does this change touch it (push) Successful in 2m17s
WAI operation catalogue / does this change touch it (push) Successful in 2m29s
wai-quantum for Python / does this change touch it (push) Successful in 26s
wai-quantum error correction and mitigation / does this change touch it (push) Successful in 36s
wai-quantum service / does this change touch it (push) Successful in 44s
wai-quantum extension points / does this change touch it (push) Successful in 1m1s
wai-quantum studio and desktop / does this change touch it (push) Successful in 57s
wai-quantum service / service energy · linux packages (push) Failing after 18s
wai-quantum variational and algorithm library / does this change touch it (push) Successful in 42s
wai-sink-swift native sink package / does this change touch it (push) Successful in 30s
wai-quantum verdicts and repairs / does this change touch it (push) Successful in 52s
wai-quantum views in agent hosts / does this change touch it (push) Successful in 38s
wai-sink-android native sink library / does this change touch it (push) Successful in 35s
wai-quantum docs, course and locales / does this change touch it (push) Successful in 4m5s
wai-quantum for JavaScript / does this change touch it (push) Successful in 4m18s
WAI Studio / does this change touch it (push) Successful in 27s
wai-quantum editors / does this change touch it (push) Successful in 4m20s
wai-quantum pulse and dynamics / does this change touch it (push) Successful in 4m20s
wai-audit collector and player integration / does this change touch it (push) Successful in 4m35s
wai-quantum other formats / does this change touch it (push) Successful in 4m22s
wai-quantum OpenQASM reader / does this change touch it (push) Successful in 4m22s
wai-quantum command line / does this change touch it (push) Successful in 4m30s
WAI breaking changes and the conformance runner / WAI breaking · does this change touch WAI (push) Successful in 11s
WAI conformance / a push to main · corpus provenance and sidecars, signer ids, the registry export (push) Successful in 55s
WAI examples / WAI examples · does this change touch them (push) Successful in 10s
wai-quantum wasmQ / does this change touch it (push) Successful in 13s
wai-quantum contract / the policy is linked, and the deprecations page reads (push) Successful in 1m58s
wai-quantum clippy / clippy, warnings denied, every feature set · linux (push) Successful in 5m52s
wai-quantum for Python / python · macos (push) Successful in 5m42s
wai-quantum studio and desktop / desktop app · macos (push) Successful in 4m45s
wai-quantum extension points / the registry under wasm32-wasip2 (wasmtime) (push) Successful in 3m42s
wai-quantum command line / command line · macos (push) Successful in 2m40s
wai-quantum service / service · macos (push) Successful in 7m42s
wai-quantum resource estimation / estimation and calibration · linux, release (push) Successful in 9m43s
wai-quantum studio and desktop / desktop app · windows (push) Successful in 12m23s
wai-quantum pulse and dynamics / the same bits · macos (push) Successful in 1m30s
wai-quantum editors / editors · macos (push) Successful in 1m56s
wai-audit collector and player integration / collector, player integration and the browser end to end · macos (push) Successful in 2m25s
wai-quantum contract / API compatibility · linux (push) Successful in 11m24s
wai-quantum studio and desktop / studio · browser (push) Successful in 6m33s
wai-quantum verdicts and repairs / the intent set and the verdict under wasm32-wasip2 (wasmtime) (push) Successful in 2m53s
wai-quantum docs, course and locales / the Studio's words in every locale · linux (push) Successful in 18s
wai-quantum variational and algorithm library / parameters, gradients, optimisers, VQE, QAOA and builders · linux, release (push) Successful in 5m33s
wai-quantum OpenQASM reader / corpus under wasm32-wasip2 (wasmtime) (push) Successful in 1m50s
wai-quantum verdicts and repairs / verdicts, repairs and the intent set · linux (push) Successful in 6m59s
wai-quantum error correction and mitigation / codes, decoders, texts and mitigation · linux, release (push) Successful in 12m54s
wai-quantum views in agent hosts / views · the page and its engine (push) Successful in 7m33s
wai-quantum OpenQASM reader / reader and corpus · linux (push) Successful in 4m29s
WAI Studio / the catalogue's actions, the unit tests and the core · linux (push) Successful in 1m32s
wai-quantum views in agent hosts / views · a scripted host (push) Successful in 7m27s
wai-quantum for Python / python · linux (push) Successful in 14m47s
wai-quantum extension points / the registry and the example · linux (push) Successful in 13m13s
wai-sink-android native sink library / every ABI, the AAR, and the instrumented tests in a headless emulator · macos (push) Successful in 15m9s
wai-quantum pulse and dynamics / reader, simulator and pulse jobs under wasm32-wasip2 (wasmtime) (push) Successful in 2m55s
wai-quantum pulse and dynamics / reader, simulator and pulse jobs · linux, release (push) Successful in 4m19s
wai-quantum docs, course and locales / the course and the command line's languages · linux (push) Successful in 9m34s
wai-quantum contract / schemas and the committed tool lists · linux (push) Successful in 21m17s
wai-quantum for JavaScript / javascript · linux (push) Successful in 10m16s
wai-quantum other formats / the set under wasm32-wasip2 (wasmtime) (push) Successful in 4m50s
wai-audit collector and player integration / collector · linux (push) Successful in 5m26s
wai-quantum studio and desktop / desktop app · linux (push) Successful in 17m38s
wai-quantum editors / editors · linux (push) Successful in 6m32s
wai-quantum wasmQ / profile, engines, reference modules, adversarial, vectors · macos (push) Successful in 2m8s
WAI Studio / Studio in Chromium and Firefox · macos (push) Successful in 17m41s
wai-quantum other formats / readers, writers and the set · linux (push) Successful in 8m0s
wai-quantum service / service · linux (push) Successful in 25m26s
wai-sink-swift native sink package / libwai slices, desktop tests, simulator tests · macos (push) Successful in 29m33s
WAI examples / WAI examples · the archive, the readiness check, the browser and Apple · macos (push) Successful in 18m31s
WAI operation catalogue / the catalogue and every door · linux (push) Successful in 39m2s
WAI Studio / Studio in WebKit · linux (push) Successful in 27m0s
wai-quantum wasmQ / the reference modules rebuild to their modules of record · linux (push) Successful in 1m7s
WAI breaking changes and the conformance runner / WAI breaking · wire, record and API against main · linux (push) Successful in 2m47s
wai-quantum wasmQ / profile, engines, reference modules, adversarial, vectors · linux (push) Successful in 6m50s
wai-quantum wasmQ / interpreter and vectors under wasm32-wasip2 (wasmtime) (push) Successful in 8m31s
wai-quantum docs, course and locales / every command and snippet in the docs · linux (push) Successful in 42m24s
wai-quantum command line / command line · linux (push) Successful in 37m48s
WAI breaking changes and the conformance runner / WAI breaking and conform · their tests, and the independent verifiers through wai conform · linux (push) Successful in 14m23s
WAI examples / WAI examples · portable · linux (push) Successful in 18m41s
repository checks / lockfiles, advisories, tests in CI, workflow hygiene, spec and section references, public text (push) Successful in 13m15s
wai-quantum variational and algorithm library / parameters, gradients, optimisers, VQE, QAOA and builders · linux-arm64, release (push) Successful in 4m41s
wai-quantum pulse and dynamics / the same bits · linux-arm64 (push) Successful in 5m7s
wai-sink-android native sink library / the JNI layer and the platform-free half on the host JVM · linux-arm64 (push) Successful in 12m21s
wai-quantum extension points / the registry and the example · linux-arm64 (push) Successful in 24m5s
WAI examples / WAI examples · android-app · linux-arm64 (push) Successful in 16m5s
wai-quantum: the compilation flow's renaming test holds each exchange it names, and the benchmark note says what was measured
An independent check of ba1cbb557 found its test and change note saying more
than was measured. No verdict or receipt changes.

engine::miter::flow::tests::the_renaming_finds_each_exchange_and_changes_nothing
said it held an exchange written, one in three CXs, one in three CZs between
Hadamards and one that absorbed a CX; its one program held a SWAP written and
one exchange found (three CZs between Hadamards after a CX on the pair). It now
holds four programs, each first checked to be its source's compile amplitude
for amplitude: an exchange in three CXs, one in three CZs between Hadamards,
one in two CXs that absorbed the CX before it, and the first program; in each
the exchange is found, no closing exchange is left, every source run is
matched and the plan is the compiled program amplitude for amplitude.

The 2026-11-13 note, corrected from the run's receipts (the aarch64 build host's before and after
runs; the after run's are the receipts in the repository):
- the equal pairs refuted are 59 in both runs, the 49 trapped-ion compilations
  (not the suite's circuits) besides the 10 superconducting ones it named;
- peak memory is now over the 896 checks both runs finished (Grover 129 -> 127
  MB, exact QPE 1080 -> 1009 MB): a stopped check records none, and the after
  figures it gave (140, 2174 MB) came from checks stopped before;
- of the check-seconds' fall, 6595 -> 3907, 2259 s is the 16 checks stopped
  before (counted at the cap) and 429 s the 896 checks both runs finished
  (2755 -> 2326 s); over the checks each run finished the time rose, 2755 s
  (896) to 3187 s (909);
- the ten pairs the change closed are proved in doubles, none exactly: five on
  the dense route alone (every entry within 1e-9, largest differences 9.8e-14
  to 4.8e-13), one on the near-identity rule alone, four on a diagram in
  doubles and the dense route; a receipt's brief form keeps no tolerance or
  near-identity statement, and brief()'s doc and the note say how to read it;
- DENSE_WORK_PER_STEP (256) was chosen with the benchmark in hand: the walk at
  9 on the 54-qubit device takes 50.4% of the bound and would be past 128 by
  0.9%; at the run's median rates (2.3 ns an update, 2.2 us a diagram step)
  the bound is about a quarter of the diagram's time; its doc says so;
- near the cap the outcome is the host's: the QPE at 22 and the QFT at 16 (36
  checks) again on the Linux x86_64 build host (32 cores, load 81 -> 42, built
  there from cd7abe66c, same files, cap and budget): five of the seven checks
  that finished undecided at 181-216 s on the aarch64 host were stopped at the cap, two
  finished undecided at 183 and 184 s, and the other 31 gave the same verdict
  bytes on both hosts.

Flow test and clippy -D warnings in five of the crate's feature sets (two on
wasm32-wasip2) on the macOS arm64 build host. Change note:
wai/changes/2026-11-13-equivalence-compilation-flow-corrections.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-13 18:03:08 -05:00

127 lines
5.4 KiB
Rust

//! What the benchmark run and its test share: how a compile is broken, and
//! what a receipt keeps of each verdict.
#![allow(dead_code)]
use serde_json::{Value, json};
use wai_quantum::quantum_toolchain::native::{self, NativeGate};
/// The text with one gate removed (the `pick`-th gate line, counted among
/// the gate lines outside definitions) or one rotation's first angle turned
/// by π/4.
pub fn break_text(text: &str, how: &str, pick: u64) -> String {
let lines: Vec<&str> = text.lines().collect();
let mut depth = 0i32;
let mut gates = Vec::new();
for (i, l) in lines.iter().enumerate() {
let t = l.trim();
let opens = t.matches('{').count() as i32 - t.matches('}').count() as i32;
if depth == 0 && t.ends_with(';') && !["OPENQASM", "include", "qubit", "bit", "creg", "qreg", "barrier", "gate", "input", "output"].iter().any(|k| t.starts_with(k)) && !t.contains("measure") {
let angled = t.contains('(');
if how == "drop" || angled {
gates.push(i);
}
}
depth += opens;
}
if gates.is_empty() {
return text.to_string();
}
let at = gates[(pick % gates.len() as u64) as usize];
let mut out: Vec<String> = lines.iter().map(|s| s.to_string()).collect();
if how == "drop" {
out.remove(at);
} else {
out[at] = out[at].replacen('(', "(pi/4 + ", 1);
}
out.join("\n") + "\n"
}
pub fn break_native(p: &native::NativeProgram, how: &str, pick: u64) -> native::NativeProgram {
let mut q = p.clone();
let eighth = native::Dyadic::new(1, 3).expect("an eighth");
let idx: Vec<usize> = q
.gates
.iter()
.enumerate()
.filter(|(_, g)| if how == "drop" { true } else { matches!(g, NativeGate::Rz(..) | NativeGate::Prx(..) | NativeGate::Gpi(..) | NativeGate::Gpi2(..)) })
.map(|(i, _)| i)
.collect();
if idx.is_empty() {
return q;
}
let at = idx[(pick % idx.len() as u64) as usize];
if how == "drop" {
q.gates.remove(at);
} else {
q.gates[at] = match q.gates[at] {
NativeGate::Rz(x, t) => NativeGate::Rz(x, t + eighth),
NativeGate::Prx(x, t, f) => NativeGate::Prx(x, t + eighth, f),
NativeGate::Gpi(x, f) => NativeGate::Gpi(x, f + eighth),
NativeGate::Gpi2(x, f) => NativeGate::Gpi2(x, f + eighth),
g => g,
};
}
q
}
/// A verdict without its long members: what the receipt keeps of each check
/// (each route's outcome and its counts, and its reason only where it did
/// not decide). It leaves out the verdict's `tolerance` and a diagram
/// route's `near_identity` statement: in a receipt, a diagram route proved in
/// doubles with a `largest_difference` is one the near-identity rule proved
/// (every entry within the dense route's tolerance), and one without it a
/// diagram whose nodes merged with the identity's within the doubles' own.
pub fn brief(v: &Value) -> Value {
let routes: Vec<Value> = v["routes"]
.as_array()
.into_iter()
.flatten()
.map(|r| {
let mut o = json!({ "route": r["route"], "outcome": r["outcome"] });
for k in ["arithmetic", "strategy", "exchanges_found", "runs_matched", "peak_nodes", "steps", "stimuli", "rewrites", "spiders_left", "contracted", "work", "largest_difference", "equal_up_to_phases_before_measurement"] {
if let Some(x) = r.get(k) {
o[k] = x.clone();
}
}
if !matches!(r["outcome"].as_str(), Some("proved" | "refuted" | "no_difference")) {
for k in ["why", "note"] {
if let Some(x) = r.get(k) {
o[k] = x.clone();
}
}
}
o
})
.collect();
let mut b = json!({ "verdict": v["verdict"], "notion": v["notion"], "routes": routes, "wires": v["wires"]["wires"], "ancillas": v["wires"]["ancillas"].as_array().map_or(0, Vec::len), "gates": v["gates"] });
for k in ["proved_by", "refuted_by", "arithmetic"] {
if let Some(x) = v.get(k) {
b[k] = x.clone();
}
}
if let Some(f) = v["routes"].as_array().into_iter().flatten().find_map(|r| r.get("field")) {
b["field"] = f.clone();
}
if let Some(c) = v.get("counterexample") {
b["counterexample"] = json!(c["found_by"]);
// How large the difference is, where the route that found it measures one.
for k in ["size", "difference", "fidelity", "total_variation"] {
if let Some(x) = c.get(k) {
b[format!("counterexample_{k}")] = x.clone();
}
}
}
if v["verdict"] == "undecided" {
b["why"] = v["why"].clone();
}
b
}
/// Where a check of one unitary refuted the pair on an input whose outcome
/// distributions already differ, the statement up to phases before the
/// measurements is refuted by that input too: that finding, without a second
/// check. `None` where the second check must decide it.
pub fn measured_by_the_same_input(v: &Value) -> Option<Value> {
let t = v["counterexample"]["total_variation"].as_f64()?;
(v["verdict"] != "proved" && t > 1e-8).then(|| json!({ "verdict": "refuted", "notion": "measured", "by": "the same input: its outcome distributions differ", "total_variation": v["counterexample"]["total_variation"] }))
}