open-standards/wai/wai-quantum/examples/tracker/guided.rs
Transaction Science c96538934d
Some checks failed
wai-quantum contract / does this change touch it (push) Successful in 17s
wai-quantum docs, course and locales / does this change touch it (push) Successful in 42s
wai-quantum editors / does this change touch it (push) Successful in 44s
wai-quantum for JavaScript / does this change touch it (push) Successful in 33s
wai-quantum pulse and dynamics / does this change touch it (push) Successful in 16s
wai-quantum error correction and mitigation / does this change touch it (push) Successful in 16s
wai-quantum for Python / does this change touch it (push) Successful in 18s
wai-quantum qudit jobs / does this change touch it (push) Successful in 22s
wai-quantum extension points / does this change touch it (push) Successful in 18s
wai-quantum service / does this change touch it (push) Successful in 21s
wai-quantum studio and desktop / does this change touch it (push) Successful in 24s
wai-quantum verdicts and repairs / does this change touch it (push) Successful in 14s
wai-quantum variational and algorithm library / does this change touch it (push) Successful in 21s
wai-quantum views in agent hosts / does this change touch it (push) Successful in 24s
WAI operation catalogue / does this change touch it (push) Successful in 3m10s
wai-sink-android native sink library / does this change touch it (push) Successful in 17s
wai-audit collector and player integration / does this change touch it (push) Successful in 3m16s
wai-quantum command line / does this change touch it (push) Successful in 3m7s
wai-sink-swift native sink package / does this change touch it (push) Successful in 17s
wai-quantum clippy / does this change touch it (push) Successful in 3m15s
WAI Studio / does this change touch it (push) Successful in 22s
wai-quantum on Windows / does this change touch it (push) Successful in 24s
wai-quantum other formats / does this change touch it (push) Successful in 4m44s
wai-quantum-landscape-fpga reference design / does this change touch it (push) Successful in 4m36s
wai-quantum OpenQASM reader / does this change touch it (push) Successful in 4m12s
wai-quantum resource estimation / does this change touch it (push) Successful in 4m46s
wai-quantum service / service energy · linux packages (push) Successful in 2m57s
WAI examples / WAI examples · does this change touch them (push) Successful in 12s
WAI breaking changes and the conformance runner / WAI breaking · does this change touch WAI (push) Successful in 21s
wai-quantum landscape energy to solution / does this change touch it (push) Successful in 27s
wai-quantum landscape stage 0, the sampler against the exact law / does this change touch it (push) Successful in 32s
wai-quantum energy-landscape jobs / does this change touch it (push) Successful in 20s
wai-quantum contract / the policy is linked, and the deprecations page reads (push) Successful in 10s
wai-quantum docs, course and locales / the Studio's words in every locale · linux (push) Successful in 18s
wai-quantum contract / API compatibility · linux (push) Successful in 7m20s
wai-quantum contract / schemas and the committed tool lists · linux (push) Successful in 11m22s
wai-quantum docs, course and locales / the course and the command line's languages · linux (push) Successful in 8m38s
wai-quantum wasmQ / does this change touch it (push) Successful in 13s
wai-quantum editors / editors · linux (push) Successful in 8m48s
wai-quantum pulse and dynamics / reader, simulator and pulse jobs under wasm32-wasip2 (wasmtime) (push) Successful in 1m4s
wai-quantum pulse and dynamics / reader, simulator and pulse jobs · linux, release (push) Successful in 4m9s
wai-quantum qudit jobs / the module and the conformance set under wasm32-wasip2 (wasmtime) (push) Successful in 2m39s
wai-quantum for JavaScript / javascript · linux (push) Successful in 11m39s
wai-quantum qudit jobs / the module, the job, the conformance set, the referee and the verb · linux (push) Successful in 4m48s
wai-quantum error correction and mitigation / codes, decoders, texts and mitigation · linux, release (push) Failing after 6m51s
wai-quantum extension points / the registry under wasm32-wasip2 (wasmtime) (push) Successful in 4m34s
wai-quantum verdicts and repairs / the intent set and the verdict under wasm32-wasip2 (wasmtime) (push) Successful in 3m43s
wai-quantum for Python / python · linux (push) Successful in 11m18s
wai-quantum variational and algorithm library / parameters, gradients, optimisers, VQE, QAOA and builders · linux, release (push) Successful in 2m11s
wai-quantum extension points / the registry and the example · linux (push) Successful in 10m27s
wai-quantum studio and desktop / desktop app · linux (push) Successful in 6m42s
wai-quantum verdicts and repairs / verdicts, repairs and the intent set · linux (push) Successful in 5m7s
WAI Studio / the catalogue's actions, the unit tests and the core · linux (push) Successful in 1m28s
wai-quantum studio and desktop / studio · browser (push) Successful in 8m22s
wai-quantum other formats / the set under wasm32-wasip2 (wasmtime) (push) Successful in 2m30s
wai-quantum OpenQASM reader / corpus under wasm32-wasip2 (wasmtime) (push) Successful in 1m36s
wai-audit collector and player integration / collector · linux (push) Successful in 5m46s
wai-quantum other formats / readers, writers and the set · linux (push) Successful in 4m51s
wai-quantum OpenQASM reader / reader and corpus · linux (push) Successful in 5m9s
wai-quantum clippy / clippy, warnings denied, every feature set · linux (push) Successful in 7m33s
wai-quantum views in agent hosts / views · the page and its engine (push) Successful in 9m39s
wai-quantum service / service · linux (push) Successful in 17m55s
wai-quantum views in agent hosts / views · a scripted host (push) Successful in 13m3s
wai-quantum resource estimation / estimation and calibration · linux, release (push) Successful in 13m42s
WAI operation catalogue / the catalogue and every door · linux (push) Successful in 20m26s
WAI Studio / Studio in WebKit · linux (push) Successful in 29m26s
WAI breaking changes and the conformance runner / WAI breaking · wire, record and API against main · linux (push) Successful in 3m30s
wai-quantum command line / command line · linux (push) Successful in 41m26s
wai-quantum landscape stage 0, the sampler against the exact law / the small tier, to the byte · linux (push) Successful in 1m8s
wai-quantum landscape energy to solution / the small tier, to the byte · linux (push) Successful in 3m35s
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 45m21s
WAI breaking changes and the conformance runner / WAI breaking and conform · their tests, and the independent verifiers through wai conform · linux (push) Successful in 16m23s
WAI examples / WAI examples · portable · linux (push) Successful in 24m45s
wai-quantum energy-landscape jobs / native against WebAssembly, over many seeds (push) Successful in 8m9s
wai-quantum docs, course and locales / every command and snippet in the docs · linux (push) Failing after 1h22m54s
wai-quantum energy-landscape jobs / reader, kernels, answers and the stated result · linux, release (push) Successful in 22m28s
wai-quantum energy-landscape jobs / the module under wasm32-wasip2 (wasmtime) (push) Successful in 23m26s
wai-quantum wasmQ / the reference modules rebuild to their modules of record · linux (push) Successful in 48s
wai-quantum wasmQ / interpreter and vectors under wasm32-wasip2 (wasmtime) (push) Successful in 6m6s
wai-quantum wasmQ / profile, engines, reference modules, adversarial, vectors · linux (push) Successful in 8m13s
repository checks / lockfiles, advisories, tests in CI, workflow hygiene, spec and section references, public text (push) Successful in 8m9s
wai-quantum pulse and dynamics / the same bits · linux-arm64 (push) Successful in 2m52s
wai-quantum editors / editors · macos (push) Successful in 2m31s
wai-quantum-landscape-fpga reference design / the board's code on the board's processor's architecture · linux-arm64, release (push) Successful in 2m37s
wai-quantum extension points / the registry and the example · linux-arm64 (push) Successful in 8m1s
wai-quantum variational and algorithm library / parameters, gradients, optimisers, VQE, QAOA and builders · linux-arm64, release (push) Successful in 4m42s
wai-quantum pulse and dynamics / the same bits · macos (push) Successful in 1m51s
wai-sink-android native sink library / the JNI layer and the platform-free half on the host JVM · linux-arm64 (push) Successful in 9m20s
wai-quantum for Python / python · macos (push) Successful in 5m34s
wai-quantum qudit jobs / the same bits · macos (push) Successful in 4m39s
wai-audit collector and player integration / collector, player integration and the browser end to end · macos (push) Successful in 2m54s
wai-quantum service / service · macos (push) Successful in 7m41s
wai-quantum studio and desktop / desktop app · macos (push) Successful in 7m29s
wai-quantum command line / command line · macos (push) Successful in 3m43s
WAI Studio / Studio in Chromium and Firefox · macos (push) Successful in 8m57s
wai-sink-android native sink library / every ABI, the AAR, and the instrumented tests in a headless emulator · macos (push) Successful in 13m11s
wai-sink-swift native sink package / libwai slices, desktop tests, simulator tests · macos (push) Successful in 16m31s
wai-quantum landscape energy to solution / the small tier, to the byte · macos (push) Successful in 1m45s
WAI examples / WAI examples · android-app · linux-arm64 (push) Successful in 11m51s
wai-quantum landscape stage 0, the sampler against the exact law / the small tier, to the byte · macos (push) Successful in 28s
wai-quantum energy-landscape jobs / the same bits · linux-arm64 (push) Successful in 20m52s
WAI examples / WAI examples · the archive, the readiness check, the browser and Apple · macos (push) Successful in 24m32s
wai-quantum energy-landscape jobs / the same bits · macos (push) Successful in 12m52s
wai-quantum wasmQ / profile, engines, reference modules, adversarial, vectors · macos (push) Successful in 4m39s
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: published quantum-advantage instances reproduced, with an echo method and a loop readout
A public tracker of quantum-advantage candidates (Apache-2.0, commit 4d27f882)
publishes circuits and Hamiltonians with device values and submitted classical
values. Its instances are now reproduced as examples that read each input at
that commit, hold it to its SHA-256 and seal a receipt per run, with the wall
time and the energy figure the platform gives.

- quantum_spd::echo and echo_split: the infinite-temperature echo
  2^-n Tr(O W† O W). A circuit written T^-1 M T is split gate for gate and
  only T and M are propagated (A = T† O T, value <A|M† A M>), with a bound on
  what truncation moved. The propagation loop is shared with expectation,
  arithmetic and order unchanged (bit_identity holds).
- quantum_bptn::Tns::expect_loop_bp: Paulis on one loop of the graph, the loop
  contracted exactly and the other bonds closed by belief-propagation
  messages; exact where that loop is the only one.
- examples tracker_guided (DMRG), tracker_su2 (sparse Pauli dynamics),
  tracker_ole (sparse Pauli dynamics or the purified echo as a tensor
  network), tracker_peaked (state network, or the operator grown from the
  circuit's middle on a chain).
- tests/tracker_reference.rs: DMRG reaches the published ground energy of the
  49-qubit guided sparse problem to 6e-13, and stalls from the guiding state
  at the value one selected-CI submission reports; the SU(2) charge is 60 with
  a bound of 7.4e-15; the cheapest echo receipts re-run bit for bit; every
  receipt's seal holds. Fixtures (four unmodified files, 388 KB) and the
  licence in tests/data/tracker/.

The operator Loschmidt echoes and the peaked circuits are not matched yet:
sparse Pauli dynamics truncates the evolved observable to nothing, the
tensor-network sweep on 49 qubits has not converged by chi = 64, and neither
peaked method shows the peak. Their receipts are kept as the evidence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-11 21:49:12 -05:00

146 lines
6.3 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! The tracker's guided sparse ground-state problem: its Hamiltonian, a list of
//! (Pauli string, coefficient) pairs, and its guiding basis state, each as a
//! `.npy` array file; read here, and written as the operator sum DMRG takes.
#![allow(dead_code)]
use wai_quantum::quantum_dmrg::{Mps, Op, OpSum};
/// One term: the factors as (qubit, letter), and the coefficient.
pub type Term = (Vec<(usize, char)>, f64);
/// The header of a version 1 or 2 `.npy` file, and the bytes after it.
fn npy(bytes: &[u8]) -> (String, &[u8]) {
assert!(bytes.len() > 12 && &bytes[..6] == b"\x93NUMPY", "not a .npy file"); // allow-name: the .npy format's magic bytes
let (len, at) = match bytes[6] {
1 => (u16::from_le_bytes([bytes[8], bytes[9]]) as usize, 10),
2 | 3 => (u32::from_le_bytes([bytes[8], bytes[9], bytes[10], bytes[11]]) as usize, 12),
v => panic!(".npy version {v}"),
};
let header = String::from_utf8(bytes[at..at + len].to_vec()).expect("an ASCII header");
(header, &bytes[at + len..])
}
/// The Hamiltonian file: a `(rows, 2)` array of `<U64` strings, each row a Pauli
/// string in the tracker's order (its last letter is qubit 0) and a complex
/// coefficient written `(re+imj)`. Refused unless every imaginary part is 0.
pub fn hamiltonian(bytes: &[u8]) -> (usize, Vec<Term>) {
let (header, body) = npy(bytes);
assert!(header.contains("'descr': '<U64'") && header.contains("'fortran_order': False"), "unexpected array: {header}");
let shape = header.split("'shape': (").nth(1).and_then(|s| s.split(')').next()).expect("a shape");
let dims: Vec<usize> = shape.split(',').filter(|s| !s.trim().is_empty()).map(|s| s.trim().parse().expect("a dimension")).collect();
assert!(dims.len() == 2 && dims[1] == 2, "shape ({shape})");
let cell = |i: usize| -> String {
body[i * 256..(i + 1) * 256].chunks(4).map(|c| u32::from_le_bytes([c[0], c[1], c[2], c[3]])).take_while(|&u| u != 0).map(|u| char::from_u32(u).expect("a character")).collect()
};
let mut n = 0;
let terms = (0..dims[0])
.map(|r| {
let (p, c) = (cell(2 * r), cell(2 * r + 1));
n = p.len();
let factors = p.chars().rev().enumerate().filter(|(_, l)| *l != 'I').collect::<Vec<_>>();
assert!(factors.iter().all(|(_, l)| matches!(l, 'X' | 'Y' | 'Z')), "a letter in {p}");
(factors, coefficient(&c))
})
.collect();
(n, terms)
}
/// `(re+imj)` with `im` zero, as the double `re` reads as.
fn coefficient(s: &str) -> f64 {
let s = s.trim().trim_start_matches('(').trim_end_matches(')');
let body = s.strip_suffix('j').expect("a complex number");
// The imaginary part starts at the last sign that does not follow an exponent.
let cut = body.char_indices().rev().find(|&(i, ch)| (ch == '+' || ch == '-') && i > 0 && !matches!(body.as_bytes()[i - 1], b'e' | b'E')).map(|(i, _)| i).expect("a real and an imaginary part");
let (re, im) = body.split_at(cut);
let im: f64 = im.parse().expect("an imaginary part");
assert_eq!(im, 0.0, "a coefficient with an imaginary part: {s}");
re.parse().expect("a real part")
}
/// The guiding state file: a `<i8` scalar, the basis state's index, bit `q`
/// qubit `q`.
pub fn guide(bytes: &[u8]) -> u64 {
let (header, body) = npy(bytes);
assert!(header.contains("'descr': '<i8'") && header.contains("'shape': ()"), "unexpected array: {header}");
let v = i64::from_le_bytes(body[..8].try_into().unwrap());
assert!(v >= 0, "a negative index");
v as u64
}
/// The Hamiltonian as DMRG takes it, its qubits placed on the chain by
/// `order` (`order[site]` is the qubit there). `Y` is `−i·J` with `J` real, so
/// a term with an even number of `Y`s is real: `(−1)^{k/2}` times the product
/// with each `Y` replaced by `J`. A term with an odd number is refused.
pub fn op_sum(n: usize, terms: &[Term], order: &[usize]) -> OpSum {
let site = |q: usize| order.iter().position(|&s| s == q).expect("every qubit on the chain");
let j = Op([0.0, 1.0, -1.0, 0.0]);
let mut h = OpSum::new(n);
for (factors, c) in terms {
let ys = factors.iter().filter(|(_, l)| *l == 'Y').count();
assert!(ys.is_multiple_of(2), "a term with an odd number of Y is not real");
let sign = if ys.is_multiple_of(4) { 1.0 } else { -1.0 };
let ops: Vec<(usize, Op)> = factors
.iter()
.map(|&(q, l)| (site(q), match l {
'X' => Op::x(),
'Y' => j,
_ => Op::z(),
}))
.collect();
h.add(sign * c, &ops);
}
h
}
/// The basis state `index` (bit `q` qubit `q`, `1` the `−1` eigenstate of `Z`)
/// as a product MPS on the chain `order`.
pub fn basis_mps(index: u64, order: &[usize]) -> Mps {
let sites = order.iter().map(|&q| if (index >> q) & 1 == 1 { vec![0.0, 1.0] } else { vec![1.0, 0.0] }).collect();
Mps { dims: vec![1; order.len() + 1], sites }
}
/// `⟨index| H |index⟩`: the diagonal terms' signs on the basis state.
pub fn diagonal_energy(terms: &[Term], index: u64) -> f64 {
terms
.iter()
.filter(|(f, _)| f.iter().all(|(_, l)| *l == 'Z'))
.map(|(f, c)| if f.iter().filter(|(q, _)| (index >> q) & 1 == 1).count().is_multiple_of(2) { *c } else { -*c })
.sum()
}
/// A chain order for the qubits: breadth first through the coupling graph the
/// two-qubit terms draw, from qubit 0, each vertex's neighbours in increasing
/// order (a bandwidth-reducing order, so the MPO's bonds stay small).
pub fn bfs_order(n: usize, terms: &[Term]) -> Vec<usize> {
let mut adj = vec![Vec::new(); n];
for (f, _) in terms {
if let [(a, _), (b, _)] = f.as_slice() {
adj[*a].push(*b);
adj[*b].push(*a);
}
}
for a in &mut adj {
a.sort_unstable();
a.dedup();
}
let mut seen = vec![false; n];
let mut order = Vec::with_capacity(n);
for start in 0..n {
if seen[start] {
continue;
}
seen[start] = true;
let mut queue = std::collections::VecDeque::from([start]);
while let Some(v) = queue.pop_front() {
order.push(v);
for &w in &adj[v] {
if !seen[w] {
seen[w] = true;
queue.push_back(w);
}
}
}
}
order
}