open-standards/wai/wai-quantum/examples/otoc_tn.rs
Transaction Science c76061846f
Some checks failed
WAI operation catalogue / does this change touch it (push) Successful in 31s
wai-audit collector and player integration / does this change touch it (push) Successful in 32s
wai-quantum command line / does this change touch it (push) Successful in 28s
wai-quantum clippy / does this change touch it (push) Successful in 20s
wai-quantum contract / does this change touch it (push) Successful in 21s
wai-quantum docs, course and locales / does this change touch it (push) Successful in 21s
wai-quantum resource estimation / does this change touch it (push) Successful in 28s
wai-quantum other formats / does this change touch it (push) Successful in 28s
wai-quantum editors / does this change touch it (push) Successful in 30s
wai-quantum service / does this change touch it (push) Successful in 24s
wai-quantum-landscape-fpga reference design / does this change touch it (push) Successful in 1m5s
wai-quantum error correction and mitigation / does this change touch it (push) Successful in 1m1s
wai-quantum for Python / does this change touch it (push) Successful in 1m3s
wai-quantum verdicts and repairs / does this change touch it (push) Successful in 51s
wai-quantum studio and desktop / does this change touch it (push) Successful in 53s
wai-quantum variational and algorithm library / does this change touch it (push) Successful in 52s
WAI Studio / does this change touch it (push) Successful in 12s
wai-quantum views in agent hosts / does this change touch it (push) Successful in 43s
wai-quantum OpenQASM reader / does this change touch it (push) Successful in 1m48s
wai-quantum for JavaScript / does this change touch it (push) Successful in 1m57s
wai-quantum pulse and dynamics / does this change touch it (push) Successful in 1m52s
wai-quantum extension points / does this change touch it (push) Successful in 1m49s
wai-quantum qudit jobs / does this change touch it (push) Successful in 1m50s
wai-quantum on Windows / does this change touch it (push) Successful in 1m35s
wai-sink-swift native sink package / does this change touch it (push) Successful in 1m38s
wai-sink-android native sink library / does this change touch it (push) Successful in 1m41s
wai-quantum service / service energy · linux packages (push) Successful in 3m15s
WAI breaking changes and the conformance runner / WAI breaking · does this change touch WAI (push) Successful in 9s
WAI examples / WAI examples · does this change touch them (push) Successful in 13s
wai-quantum landscape energy to solution / does this change touch it (push) Successful in 13s
wai-quantum landscape stage 0, the sampler against the exact law / does this change touch it (push) Successful in 20s
wai-quantum energy-landscape jobs / does this change touch it (push) Successful in 20s
wai-quantum wasmQ / does this change touch it (push) Successful in 14s
wai-audit collector and player integration / collector · linux (push) Successful in 4m9s
wai-quantum contract / the policy is linked, and the deprecations page reads (push) Successful in 12s
wai-quantum clippy / clippy, warnings denied, every feature set · linux (push) Successful in 7m54s
wai-quantum docs, course and locales / the Studio's words in every locale · linux (push) Successful in 24s
wai-quantum contract / API compatibility · linux (push) Successful in 11m51s
wai-quantum docs, course and locales / the course and the command line's languages · linux (push) Successful in 7m35s
WAI operation catalogue / the catalogue and every door · linux (push) Successful in 16m57s
wai-quantum contract / schemas and the committed tool lists · linux (push) Successful in 20m8s
wai-quantum other formats / the set under wasm32-wasip2 (wasmtime) (push) Successful in 3m45s
wai-quantum other formats / readers, writers and the set · linux (push) Successful in 8m6s
wai-quantum verdicts and repairs / the intent set and the verdict under wasm32-wasip2 (wasmtime) (push) Successful in 3m9s
wai-quantum resource estimation / estimation and calibration · linux, release (push) Successful in 13m15s
wai-quantum editors / editors · linux (push) Successful in 7m53s
WAI Studio / the catalogue's actions, the unit tests and the core · linux (push) Successful in 1m11s
wai-quantum verdicts and repairs / verdicts, repairs and the intent set · linux (push) Successful in 6m13s
wai-quantum variational and algorithm library / parameters, gradients, optimisers, VQE, QAOA and builders · linux, release (push) Successful in 4m2s
wai-quantum error correction and mitigation / codes, decoders, texts and mitigation · linux, release (push) Successful in 9m51s
wai-quantum studio and desktop / studio · browser (push) Successful in 8m6s
wai-quantum command line / command line · linux (push) Successful in 37m32s
wai-quantum OpenQASM reader / corpus under wasm32-wasip2 (wasmtime) (push) Successful in 1m39s
wai-quantum for Python / python · linux (push) Successful in 12m5s
wai-quantum pulse and dynamics / reader, simulator and pulse jobs under wasm32-wasip2 (wasmtime) (push) Successful in 1m58s
wai-quantum OpenQASM reader / reader and corpus · linux (push) Successful in 5m25s
wai-quantum views in agent hosts / views · the page and its engine (push) Successful in 7m52s
wai-quantum service / service · linux (push) Successful in 16m45s
wai-quantum pulse and dynamics / reader, simulator and pulse jobs · linux, release (push) Successful in 4m8s
wai-quantum studio and desktop / desktop app · linux (push) Successful in 12m55s
wai-quantum qudit jobs / the module and the conformance set under wasm32-wasip2 (wasmtime) (push) Successful in 2m25s
wai-quantum views in agent hosts / views · a scripted host (push) Successful in 9m38s
wai-quantum extension points / the registry under wasm32-wasip2 (wasmtime) (push) Successful in 4m26s
wai-quantum qudit jobs / the module, the job, the conformance set, the referee and the verb · linux (push) Successful in 9m53s
wai-quantum for JavaScript / javascript · linux (push) Successful in 11m55s
wai-quantum extension points / the registry and the example · linux (push) Successful in 9m7s
wai-quantum docs, course and locales / every command and snippet in the docs · linux (push) Failing after 53m44s
WAI Studio / Studio in WebKit · linux (push) Successful in 27m8s
wai-quantum-landscape-fpga reference design / the member against the model of the logic, and the logic against the model · linux, release (push) Successful in 44m24s
repository checks / lockfiles, advisories, tests in CI, workflow hygiene, spec and section references, public text (push) Failing after 8m24s
wai-quantum-landscape-fpga reference design / the board's code on the board's processor's architecture · linux-arm64, release (push) Successful in 2m35s
wai-quantum variational and algorithm library / parameters, gradients, optimisers, VQE, QAOA and builders · linux-arm64, release (push) Successful in 3m51s
wai-quantum pulse and dynamics / the same bits · linux-arm64 (push) Successful in 3m9s
wai-quantum extension points / the registry and the example · linux-arm64 (push) Successful in 11m19s
wai-sink-android native sink library / the JNI layer and the platform-free half on the host JVM · linux-arm64 (push) Successful in 10m59s
wai-audit collector and player integration / collector, player integration and the browser end to end · macos (push) Successful in 2m10s
wai-quantum command line / command line · macos (push) Successful in 2m28s
wai-quantum editors / editors · macos (push) Successful in 1m29s
WAI breaking changes and the conformance runner / WAI breaking · wire, record and API against main · linux (push) Successful in 3m33s
wai-quantum for Python / python · macos (push) Successful in 3m54s
wai-quantum service / service · macos (push) Successful in 7m14s
wai-quantum pulse and dynamics / the same bits · macos (push) Successful in 2m16s
wai-quantum qudit jobs / the same bits · macos (push) Successful in 1m52s
wai-quantum landscape energy to solution / the small tier, to the byte · linux (push) Successful in 3m24s
WAI breaking changes and the conformance runner / WAI breaking and conform · their tests, and the independent verifiers through wai conform · linux (push) Successful in 14m37s
wai-quantum studio and desktop / desktop app · macos (push) Successful in 5m54s
wai-quantum landscape stage 0, the sampler against the exact law / the small tier, to the byte · linux (push) Successful in 1m11s
wai-sink-android native sink library / every ABI, the AAR, and the instrumented tests in a headless emulator · macos (push) Successful in 7m24s
wai-quantum wasmQ / the reference modules rebuild to their modules of record · linux (push) Successful in 47s
wai-quantum wasmQ / profile, engines, reference modules, adversarial, vectors · linux (push) Successful in 4m43s
WAI examples / WAI examples · portable · linux (push) Successful in 24m24s
wai-quantum wasmQ / interpreter and vectors under wasm32-wasip2 (wasmtime) (push) Successful in 4m19s
WAI Studio / Studio in Chromium and Firefox · macos (push) Successful in 19m5s
wai-quantum energy-landscape jobs / native against WebAssembly, over many seeds (push) Successful in 12m30s
wai-quantum energy-landscape jobs / the module under wasm32-wasip2 (wasmtime) (push) Successful in 17m45s
wai-quantum energy-landscape jobs / reader, kernels, answers and the stated result · linux, release (push) Successful in 21m58s
wai-sink-swift native sink package / libwai slices, desktop tests, simulator tests · macos (push) Failing after 46m7s
WAI examples / WAI examples · android-app · linux-arm64 (push) Successful in 16m40s
wai-quantum landscape energy to solution / the small tier, to the byte · macos (push) Successful in 2m2s
wai-quantum landscape stage 0, the sampler against the exact law / the small tier, to the byte · macos (push) Successful in 31s
wai-quantum wasmQ / profile, engines, reference modules, adversarial, vectors · macos (push) Successful in 3m4s
wai-quantum energy-landscape jobs / the same bits · macos (push) Successful in 14m59s
wai-quantum energy-landscape jobs / the same bits · linux-arm64 (push) Successful in 15m17s
WAI examples / WAI examples · the archive, the readiness check, the browser and Apple · macos (push) Successful in 46m1s
wai-quantum on Windows / engine · windows (push) Has been cancelled
wai-quantum on Windows / command line · windows (push) Has been cancelled
wai-quantum on Windows / job service · windows (push) Has been cancelled
wai-quantum on Windows / python · windows (push) Has been cancelled
wai-quantum studio and desktop / desktop app · windows (push) Has been cancelled
WAI Quantum: OTOC(1) and OTOC(2) of the published echo circuits, on the state vector and by propagation, each run sealed in a receipt
The circuits and values published as doi:10.5281/zenodo.15640503 (CC BY 4.0;
arXiv:2506.10191) are fetched against their pins, converted, run by the engine
and held to the published values.

- src/quantum_otoc.rs (with quantum_sv and quantum_spd_receipt): the sets in a
  text form, the gates as the published library defines them (checked against
  its source), both correlators on the dense state vector, the echoes lowered
  to Pauli rotations (Z rotations carried through the iSWAP-type gates, dropped
  where they are a phase; held to the state vector at threshold 0), OTOC(2)'s
  off-diagonal estimate from seeded insertion strings, belief-propagation
  tensor networks and matrix-product states on the same echoes, and
  OtocReceipt: every circuit's result, every instance among them, with the wall
  time and this process's CPU energy (OnChipCounter where the counter advanced,
  unmetered with the reason elsewhere); re-run whole or one circuit at a time.
- examples otoc_sv, otoc_spd, otoc_tn; wai/tools/quantum-otoc/ fetches the
  record (DOI, URL, size, md5, sha256) and converts it. Its 40-, 65- and
  95-qubit sets are Python pickles: read by a static opcode reader that imports
  and calls nothing, inside a sandbox with no network.
- tests/otoc_reference.rs, with two converted circuits and four receipts:
  - 18 qubits, 50 circuits, 200 insertion instances each (894 s, 6.36 kJ of CPU
    energy on the build host): every sign agrees, r = 0.965 against the
    published ΔC4, 32 of 50 within three standard errors of the two Monte Carlo
    estimates; 18 are not, beyond what 20 instances can explain. Reported, not
    explained. Circuit 0 is re-run in the test, bit for bit.
  - 40 qubits, OTOC(1), sparse Pauli dynamics at 1e-2, 1e-3 and 1e-4: the
    propagation does not reach the published exact values (mean 1.5e-3); at the
    two coarser thresholds every value is exactly 0, and every bound is above 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-11 22:27:35 -05:00

108 lines
5.5 KiB
Rust

//! Out-of-time-order correlators of the published circuits by tensor networks,
//! as a measured exploration of the 65- and 95-qubit circuits against the
//! processor's values, and held to the exact state vector where that exists.
//! Two kinds, each sealed in a receipt per run:
//!
//! - `--chi X`: a state on the circuits' coupling graph, evolved by simple
//! update with bonds of at most X, read through belief-propagation
//! environments;
//! - `--bond X`: a matrix-product state along the qubits' index order, bonds of
//! at most X, gates between non-neighbours applied through swaps.
//!
//! ```text
//! cargo run --release --example otoc_tn --features quantum_sv,quantum_spd_receipt,quantum_bptn,quantum_mpsim -- SET.txt --chi X|--bond X [options]
//! ```
//!
//! Other options as `otoc_spd` takes them. Each circuit prints its value, the
//! weight its truncations discarded (a diagnostic, not a bound), the widest
//! bond, the published value and the difference.
use std::time::Instant;
use wai_quantum::ed25519_dalek::SigningKey;
use wai_quantum::quantum_otoc::{EchoSet, Method, OtocJob, Quantity, published_for, seal_metered};
fn main() {
let args: Vec<String> = std::env::args().skip(1).collect();
let path = args.first().expect("usage: otoc_tn SET.txt --chi X|--bond X [--circuits A-B] [--instances N] [--receipt PATH]");
let opt = |k: &str| args.iter().position(|a| a == k).map(|i| args[i + 1].clone());
let mut set = EchoSet::parse(&std::fs::read_to_string(path).expect("the set reads")).expect("a valid set");
if let Some(sel) = opt("--circuits") {
set = set.subset(&indices(&sel));
}
if opt("--kind").as_deref() == Some("otoc1") {
// Exploration: the OTOC(1) of the same blocks, which nothing published.
set.kind = wai_quantum::quantum_otoc::Kind::Otoc1;
set.name += "-as-otoc1";
}
let method = match (opt("--chi"), opt("--bond")) {
(Some(x), None) => Method::Bptn { chi: x.parse().expect("a bond") },
(None, Some(x)) => Method::Mps { max_bond: x.parse().expect("a bond") },
_ => panic!("give one of --chi X and --bond X"),
};
let quantity = match opt("--instances") {
Some(n) => Quantity::OffDiagonal { instances: n.parse().expect("a count"), seed: opt("--seed").map_or(1, |s| s.parse().expect("a seed")) },
None => Quantity::Plain,
};
let (key, id) = signer();
let published = published_for(&set.name);
println!("set {} · {} qubits · {} cycles · {} circuits · {quantity:?} · {method:?}", set.name, set.n, set.cycles, set.circuits.len());
if let Some((_, what)) = published {
println!("published: {what}");
}
let job = OtocJob { set, quantity, method };
let mut last = Instant::now();
let mut pairs = Vec::new();
let (receipt, json) = seal_metered(&key, &id, &job, |o| {
let secs = last.elapsed().as_secs_f64();
last = Instant::now();
let ours = o.value();
let p = published.and_then(|(p, _)| p.get(o.index as usize)).copied();
let tail = p.map_or(String::new(), |p| {
pairs.push((ours, p));
format!(" published {p:+.6} diff {:+.6}", ours - p)
});
println!("{:4} value {ours:+.6} plain {:+.6} discarded {:.3e} bond {:>4}{tail} {secs:.1}s", o.index, o.plain, o.plain_bound, o.peak);
})
.expect("the job runs");
if pairs.len() > 1 {
let k = pairs.len() as f64;
let mad = pairs.iter().map(|(a, b)| (a - b).abs()).sum::<f64>() / k;
let (ma, mb) = (pairs.iter().map(|p| p.0).sum::<f64>() / k, pairs.iter().map(|p| p.1).sum::<f64>() / k);
let cov: f64 = pairs.iter().map(|(a, b)| (a - ma) * (b - mb)).sum();
let (va, vb): (f64, f64) = (pairs.iter().map(|(a, _)| (a - ma) * (a - ma)).sum(), pairs.iter().map(|(_, b)| (b - mb) * (b - mb)).sum());
let rms_pub = (pairs.iter().map(|(_, b)| b * b).sum::<f64>() / k).sqrt();
println!("mean |diff| {mad:.3e} · rms published {rms_pub:.3e} · correlation {:.3} · means {ma:+.3e} / {mb:+.3e}", cov / (va * vb).sqrt());
}
let work: u64 = receipt.outcomes.iter().map(|o| o.work).sum();
let peak = receipt.outcomes.iter().map(|o| o.peak).max().unwrap_or(0);
println!("work {work} (rotations or chain work) · widest bond {peak} · {:.1} s · {} µJ (this process's CPU energy)", receipt.elapsed_ms as f64 / 1000.0, receipt.joules_micro);
if let Some(out) = opt("--receipt") {
std::fs::write(&out, json + "\n").expect("the receipt writes");
println!("receipt {out} (receipt hash {})", hex(&receipt.receipt_hash()));
}
}
fn indices(s: &str) -> Vec<u32> {
s.split(',')
.flat_map(|part| match part.split_once('-') {
Some((a, b)) => (a.parse::<u32>().expect("an index")..=b.parse::<u32>().expect("an index")).collect::<Vec<_>>(),
None => vec![part.parse().expect("an index")],
})
.collect()
}
fn signer() -> (SigningKey, String) {
match std::env::var("OTOC_SIGNING_KEY") {
Ok(p) => {
let h = std::fs::read_to_string(&p).expect("the key file reads");
let h = h.trim();
let b: Vec<u8> = (0..32).map(|i| u8::from_str_radix(&h[2 * i..2 * i + 2], 16).expect("hex")).collect();
(SigningKey::from_bytes(&b.try_into().expect("32 bytes")), "wai-quantum otoc reproduction".into())
}
Err(_) => (SigningKey::from_bytes(&[0x0e; 32]), "wai-quantum otoc example (demonstration key)".into()),
}
}
fn hex(b: &[u8]) -> String {
b.iter().map(|x| format!("{x:02x}")).collect()
}