open-standards/wai/wai-quantum/tests/cuda_sv.rs
Transaction Science 157dcb1cc5
All checks were successful
wai-quantum CUDA member / member · CUDA (jetson-hub) (pull_request) Successful in 16s
wai-quantum OpenCL member / member · OpenCL GPU and CPU (jetson-hub) (pull_request) Successful in 37s
wai-quantum WebGPU member / member · discrete GPU, Vulkan (jetson-hub) (pull_request) Successful in 12m24s
spec citations resolve / Code cites no section its SPEC lacks (pull_request) Successful in 5s
standards workspaces build + test / arl-rs (pull_request) Successful in 1m12s
standards workspaces build + test / eoc-rs (pull_request) Successful in 2m4s
standards workspaces build + test / jcp-rs (pull_request) Successful in 1m38s
standards workspaces build + test / joule-ui-rs (pull_request) Successful in 1m29s
standards workspaces build + test / joulehook-rs (pull_request) Successful in 1m19s
standards workspaces build + test / proof-rs (pull_request) Successful in 1m59s
standards workspaces build + test / sandbox-rs (pull_request) Successful in 2m39s
standards workspaces build + test / sense-rs (pull_request) Successful in 1m8s
standards workspaces build + test / jouledesk-rs (pull_request) Successful in 1m27s
standards workspaces build + test / smart-byte-rs (pull_request) Successful in 4m13s
lockfiles / every Cargo.lock is current (pull_request) Successful in 32s
no-vanity-metrics / Scan committed Markdown for vanity metrics (pull_request) Successful in 4s
no-vanity-metrics / WAI public text names no comparison (pull_request) Successful in 4s
no-vanity-metrics / WAI public text names no company or product (pull_request) Successful in 4s
no-vanity-metrics / No new orphan source files (pull_request) Successful in 6s
WAI conformance / quantum core and corpus under wasm32-wasip2 (wasmtime) (pull_request) Successful in 2m17s
WAI conformance / v2 vocabulary · manifests validate as stated (pull_request) Successful in 14s
standards workspaces build + test / macOS energy backends (pull_request) Successful in 6m31s
standards workspaces build + test / jouleclaw-rs (pull_request) Successful in 3m44s
WAI conformance / cargo-class corpora · linux (pull_request) Successful in 9m40s
standards workspaces build + test / joule-code-rs (pull_request) Successful in 1m37s
WAI conformance / delivery telemetry · CMCD and CMSD against an independent library (pull_request) Successful in 9s
WAI conformance / cross-arch byte-equality · linux (pull_request) Successful in 28s
standards workspaces build + test / aac-rs (pull_request) Successful in 2m58s
standards workspaces build + test / joulecontract-rs (pull_request) Successful in 58s
WAI conformance / C2PA manifest emission · signed, read back, validated (pull_request) Successful in 50s
standards workspaces build + test / map-rs (pull_request) Successful in 58s
standards workspaces build + test / mesh-rs (pull_request) Successful in 59s
tests in CI / every test file is run by a job or listed with its reason (pull_request) Successful in 5s
WAI energy receipts / energy receipts · linux (pull_request) Successful in 2m7s
WAI HTTP delivery / WAI HTTP · does this change touch it (pull_request) Successful in 5s
WAI HTTP delivery / HTTP corpus · falsify mutations 0/3 (pull_request) Has been skipped
WAI HTTP delivery / HTTP corpus · falsify mutations 1/3 (pull_request) Has been skipped
WAI HTTP delivery / HTTP corpus · falsify mutations 2/3 (pull_request) Has been skipped
WAI HTTP delivery / HTTP corpus · falsify patches 0/3 (pull_request) Has been skipped
WAI HTTP delivery / HTTP corpus · falsify patches 1/3 (pull_request) Has been skipped
WAI HTTP delivery / HTTP corpus · falsify patches 2/3 (pull_request) Has been skipped
WAI HTTP delivery / HTTP corpus · every patch and mutation in exactly one shard (pull_request) Has been skipped
WAI HTTP delivery / HTTP corpus · verified both ways, and the differential (pull_request) Has been skipped
WAI HTTP delivery / cache rules · controls and labelled caches (pull_request) Has been skipped
standards workspaces build + test / openpay (pull_request) Successful in 3m0s
WAI JPEG-AI whole decode (pinned inputs, required) / fetch pinned JPEG-AI inputs → whole decode + pixel hash, required (pull_request) Successful in 1m25s
WAI conformance / cross-arch byte-equality · linux-arm64 (pull_request) Successful in 26s
WAI conformance / cargo-class corpora · macos (pull_request) Successful in 7m48s
WAI neural sink gates / model-free refusals of the neural sink (pull_request) Successful in 1m15s
wai-pack / wai-pack · does this change touch it (pull_request) Successful in 5s
WAI conformance / cross-arch byte-equality · macos (pull_request) Successful in 21s
wai-quantum CUDA member / member · CUDA absent (linux) (pull_request) Successful in 20s
wai-quantum FPGA member / member · FPGA simulation absent (linux) (pull_request) Successful in 17s
WAI conformance / codec wrappers · fuzz smoke, text decode limits, C entry points, provenance, the semantic path (pull_request) Successful in 43s
WAI energy receipts / energy receipts · linux-arm64 (pull_request) Successful in 2m10s
workflow hygiene / every workflow supersedes its own queue (pull_request) Successful in 5s
wai-quantum OpenCL member / member · OpenCL absent (linux) (pull_request) Successful in 20s
wai-quantum-qpu / clients against their contracts (linux) (pull_request) Successful in 19s
WAI energy receipts / energy receipts · macos (pull_request) Successful in 1m42s
wai-quantum FPGA member / member · FPGA datapath, simulated (macos) (pull_request) Successful in 1m11s
wai-quantum WebGPU member / shader checks · browser build · wasip2 inertness · MSRV (pull_request) Successful in 2m43s
wai-quantum OpenCL member / member · OpenCL GPU (macos) (pull_request) Successful in 21s
WAI conformance / cargo-class corpora · linux-arm64 (pull_request) Successful in 9m10s
wai-quantum WebGPU member / member · software Vulkan (linux) (pull_request) Successful in 1m57s
WAI conformance / independent verifiers · claims, JWP, key discovery and integer payloads (Python) (pull_request) Successful in 17m29s
wai-web reach builds / wai-web reach · does this change touch it (pull_request) Successful in 5s
wai-quantum WebGPU member / member · Metal (macos) (pull_request) Successful in 6m8s
wai-web wasm32 / wai-web wasm32 build · corpus, menu and writers (pull_request) Successful in 3m22s
WAI mbt2018_mean integer decode (regenerated vectors) / regenerate mbt2018_mean integer vectors → Rust decode, required (pull_request) Successful in 5m25s
wai-quantum WebGPU member / member · browser WebGPU (macos) (pull_request) Successful in 3m46s
wai-pack / wai-pack · linux (pull_request) Successful in 1m40s
wai-pack / wai-pack · the floor through a media prober (pull_request) Successful in 33s
wai-pack / wai-pack · linux-arm64 (pull_request) Successful in 2m23s
wai-pack / wai-pack · dependency licences (pull_request) Successful in 1m34s
wai-pack / wai-pack · independent verifier (Python) (pull_request) Successful in 4m47s
wai-pack / wai-pack · macos (pull_request) Successful in 3m30s
wai-web reach builds / wai-web reach builds · the package of record, every output as recorded (pull_request) Successful in 2m57s
wai-web reach builds / wai-web reach builds · this tree's wai-web, every rung on its engine line (pull_request) Successful in 5m3s
wai-quantum 0.5.0: provenance, sampling members, device programs, OpenCL, a simulated FPGA, f64 on accelerators, and QPU clients
Breaking: Certificate gains a public field, provenance; a silicon
certificate hashes exactly as before, and every pinned digest is unchanged.
quantum_fabric now includes quantum_toolchain.

- Provenance (silicon / emulator / simulator) inside the certificate hash;
  placement ranks silicon first.
- Sampling members: the sample kernels, the Sampler trait, statistical
  certification on the qpu-v1 corpus, a virtual QPU, and a virtual device
  that compiles each circuit for its coupling map and native basis.
- quantum_toolchain::device: OpenQASM 2/3 in standard gates only, multi-
  controlled gates lowered exactly, every qubit measured; counts read back.
  quantum_toolchain::native: rz/sx/x/cz, prx/cz and gpi/gpi2/zz (turns), routed
  over a coupling map and verified against the circuit by simulation.
  from_qasm reads ch.
- The OpenCL member (quantum_fabric_opencl), bit-exact on GPUs and CPUs.
- The FPGA member, simulated (quantum_fabric_fpga): a Verilog datapath
  compiled by Verilator at run time; certificates say simulator.
- The dense f64 state vector on accelerators (quantum_fabric::sv64): the
  CPU's own launches with no fused multiply-add, on CUDA and on OpenCL devices
  with binary64, certified against a pinned digest.
- wai-quantum-qpu 0.1.0: clients for three quantum processing protocols, the
  wai-qpu command, curl transport with secrets off command lines.
- CI: OpenCL, FPGA and QPU-client workflows; the CUDA and OpenCL hardware jobs
  certify the f64 state vector; the hardware host declares its devices.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-14 09:02:11 -04:00

112 lines
4.7 KiB
Rust

//! The dense f64 state vector on the CUDA devices of the machine that runs
//! this: bit for bit the CPU's, or the certificate says not.
//!
//! The machine declares its devices in `WAI_QUANTUM_CUDA_EXPECT` (comma-
//! separated keys, or `none`), as for `cuda_member`; `WAI_QUANTUM_CUDA_REPORT`
//! names a file the established lines are appended to.
#![cfg(not(target_arch = "wasm32"))]
use std::io::Write;
use wai_quantum::gates::Gate;
use wai_quantum::quantum_fabric::sv64::{self, MUTANTS, SV_DEFAULT, SV_DEFAULT_PIN, SvCorpus};
use wai_quantum::quantum_fabric::{Certification, Parity};
use wai_quantum::quantum_fabric_cuda::{CudaMember, discover};
use wai_quantum::quantum_sv::StateVector;
fn report(line: &str) {
println!("{line}");
if let Some(path) = std::env::var_os("WAI_QUANTUM_CUDA_REPORT") {
let mut f = std::fs::OpenOptions::new().create(true).append(true).open(&path).expect("the report file opens");
writeln!(f, "{line}").expect("the report line is written");
}
}
fn members() -> Vec<CudaMember> {
let d = discover();
let mut found: Vec<String> = d.found.iter().map(|m| m.key().to_string()).collect();
found.sort();
let found_list = if found.is_empty() { "none".to_string() } else { found.join(",") };
let expect = std::env::var("WAI_QUANTUM_CUDA_EXPECT").unwrap_or_else(|_| panic!("WAI_QUANTUM_CUDA_EXPECT is not set; found {found_list}"));
assert_eq!(found_list, expect, "the devices found are not the declared ones");
d.found
}
fn hex(b: &[u8]) -> String {
b.iter().map(|x| format!("{x:02x}")).collect()
}
/// The CPU certifying itself on `corpus`: the digest a bit-exact device
/// reproduces.
fn cpu_digest(corpus: SvCorpus) -> String {
let mut cert = Certification::new();
for case in corpus.cases() {
let r = case.reference().unwrap();
cert.add(&case.bytes(), &r, &r);
}
hex(&cert.finish(sv64::KERNEL_SV_RUN, "cpu", "cpu", &corpus.generator()).corpus)
}
#[test]
fn s0_the_state_vector_is_the_cpus_bit_for_bit() {
let cpu = cpu_digest(SV_DEFAULT);
assert_eq!(cpu, SV_DEFAULT_PIN, "this machine's CPU does not reproduce the pin");
for m in members() {
let sv = m.sv().unwrap_or_else(|e| panic!("{}: {e}", m.key()));
let c = sv.certify(SV_DEFAULT).unwrap_or_else(|e| panic!("{}: {e}", m.key()));
assert_eq!(c.parity, Parity::BitExact, "{}", m.key());
assert_eq!(c.cases, SV_DEFAULT.cases as u64);
assert_eq!(hex(&c.corpus), cpu, "{}: the digest is not the CPU's", m.key());
report(&format!("cuda sv certified: key={} member={} kernel={} implementation={} parity=bit-exact cases={} digest={}", m.key(), m.id(), c.kernel, c.implementation, c.cases, hex(&c.corpus)));
}
}
#[test]
fn s1_wide_states_match_the_cpu() {
for m in members() {
let sv = m.sv().unwrap();
for (n, width) in [(16u32, 0usize), (20, 3)] {
let mut gates = Vec::new();
let mut a = 0.1f64;
for layer in 0..6u32 {
for q in 0..n {
a += 0.731;
gates.push(match (q + layer) % 5 {
0 => Gate::rx(q, a),
1 => Gate::ry(q, a),
2 => Gate::rz(q, a),
3 => Gate::sqrt_w(q),
_ => Gate::t(q),
});
}
let mut q = layer % 2;
while q + 1 < n {
gates.push(if q % 3 == 0 { Gate::fsim(q, q + 1, a, 0.5 * a) } else { Gate::cz(q, q + 1) });
q += 2;
}
gates.push(Gate::iswap(0, n - 1));
}
let mut cpu = StateVector::zero(n).unwrap();
cpu.run(&gates, width).unwrap();
let (re, im) = sv.run(n, &gates, width).unwrap();
let same = |a: &[f64], b: &[f64]| a.iter().zip(b).all(|(x, y)| x.to_bits() == y.to_bits());
assert!(same(&re, &cpu.re) && same(&im, &cpu.im), "{}: n={n} width={width}", m.key());
}
report(&format!("cuda sv wide: key={} 16 and 20 qubits match the CPU bit for bit", m.key()));
}
}
#[test]
fn s2_mutants_are_caught() {
let small = SvCorpus { cases: 18, ..SV_DEFAULT };
let cpu = cpu_digest(small);
for m in members() {
let mut killed = 0;
for mutant in &MUTANTS {
let sv = m.sv_with_source(&sv64::mutate(mutant)).unwrap_or_else(|e| panic!("mutant {}: {e}", mutant.name));
let c = sv.certify(small).unwrap();
assert!(c.parity != Parity::BitExact || hex(&c.corpus) != cpu, "{}: mutant {} survived", m.key(), mutant.name);
killed += 1;
}
report(&format!("cuda sv mutants: key={} killed {killed} of {}", m.key(), MUTANTS.len()));
}
}