wai-quantum 0.3.26: tensor-network contraction, hyper-optimised, sliced, bit-identical #144

Merged
dcharlot merged 1 commit from wai-quantum-tn into main 2026-10-04 20:40:53 -04:00
Owner

Stacked on #143. Merge #143 first; until then this diff also shows #143's commit.

What

wai-quantum 0.3.26 adds tensor-network contraction. A circuit's amplitude is a network, and the order of contraction decides whether it costs 2³⁰ operations or 2⁶⁰. quantum_tn finds that order, slices it to fit memory, and contracts it to the same bits on every machine.

  • Build. Network::amplitude turns any unitaries on any qubits into the network of one amplitude, or of an open-output batch. simplify absorbs vectors and one-qubit gates into their neighbours.

  • Order. find_path is a seeded hyper-optimiser over two tree families:

    • randomised greedy, scoring size(out)/c − c·(size(a)+size(b)) with Gumbel noise;
    • recursive bipartition, multilevel (heavy-edge coarsening, several initial cuts, refinement at every level), with greedy leaves.

    Families alternate until one leads, and later trials sample near the best parameters. The best few trees are reconfigured: subtrees of up to eight tensors are re-contracted optimally by subset dynamic programming, until nothing improves.

  • Slice. slice fixes, one at a time, the index that leaves the least total work, pricing each candidate incrementally. A second search round then finds a tree for the network with the first round's slices fixed.

  • Contract. contract_plan runs every slice in a fixed accumulation order and sums the slices in order. Threads are bounded by an 8 GiB budget; WASI runs sequentially. The bits are identical either way.

  • CLI. wai-quantum tn --file CIRCUIT.jsonl [--bits --open --trials --seed --cap-log2 --plan-only --json]

Evidence

Path quality on identical networks. Single amplitudes of random circuits on the 54-qubit advantage-experiment grid (√X/√Y/√W layers and fSim(π/2, π/6) on staggered couplers), simplified to 174–395 tensors. Figures are log₁₀ operations, unsliced:

cycles this module (256 trials) independent hyper-optimiser (64 trials, greedy + hypergraph partitioning + reconfiguration)
10 10.48 (4 s) 10.49 (82 s)
12 13.91 (7 s) 14.28 (148 s)
14 14.63 (8 s) 14.27–14.44 (683–1194 s)
16 17.60 (10 s) 17.32 (498 s)
20 18.77 (10 s) 18.94 (541 s)

Slicing at m = 10. Both cap the largest intermediate at 2²⁴ elements, 16× below the unsliced intermediate:

  • this module: 10.48 in 16 slices, the same work as unsliced;
  • the independent tool: 10.66 in 16 slices.

Correctness at full size. The 54-qubit, 10-cycle amplitude agrees to 12 significant figures with an independent contraction of the same circuit, which used its own path search and a BLAS backend:

contraction amplitude time
this module (16 slices) −8.130144653823e−9 − 7.507630273949e−11i 5 s search + 24 s contraction, 6 GB peak
independent −8.130144653822e−9 − 7.507630274107e−11i 1361 s

Tests

  • Amplitudes match a dense state vector:

    • for every tree family;
    • after reconfiguration;
    • with slicing;
    • for open-output batches.
  • Reconfiguration reaches the exact optimum on 40 random small networks, checked by an independent brute-force search.

  • Incremental slice pricing matches a full recount.

  • The same seed gives the same plan.

  • Mutation testing: breaking any of these fails a named test:

    • the permutation odometer;
    • the complex product;
    • the contraction's summed indices;
    • slice pricing;
    • the slice offset;
    • the reconfiguration DP's choice;
    • the reconfiguration DP's output set.

    An earlier miss, where reconfiguration was silently disabled, is what the optimum test now catches.

  • bit_identity pins a plan and its sliced, threaded amplitude. All 11 pins pass natively and under wasm32-wasip2.

  • tn output is byte-identical natively and as a WASI component. That covers a sliced, open-output batch.

  • cargo test --locked --features full --lib --tests: 363 + 11 + 2 + 3 passed. Every feature builds alone with zero warnings, and clippy is clean on the new code.

Honest boundaries

  • Slicing on deep circuits. Slicing deep circuits far below their natural intermediate size costs real work. At m = 14 with a 2³⁰ cap, a plan costs about 12× its unsliced cost.
  • The executor is scalar. It runs about 10⁹ complex multiply-adds per second per core, with no SIMD kernels or GPU. Plans of 10¹³ operations or more are for planning and verification arithmetic here, not for contraction.
  • Simple graphs only. Every index joins at most two tensors; diagonal-gate hyperedges are not exploited.

🤖 Generated with Claude Code

**Stacked on #143.** Merge #143 first; until then this diff also shows #143's commit. ## What `wai-quantum` 0.3.26 adds **tensor-network contraction**. A circuit's amplitude is a network, and the order of contraction decides whether it costs 2³⁰ operations or 2⁶⁰. `quantum_tn` finds that order, slices it to fit memory, and contracts it to the same bits on every machine. - **Build.** `Network::amplitude` turns any unitaries on any qubits into the network of one amplitude, or of an open-output batch. `simplify` absorbs vectors and one-qubit gates into their neighbours. - **Order.** `find_path` is a seeded hyper-optimiser over two tree families: - randomised greedy, scoring `size(out)/c − c·(size(a)+size(b))` with Gumbel noise; - recursive bipartition, multilevel (heavy-edge coarsening, several initial cuts, refinement at every level), with greedy leaves. Families alternate until one leads, and later trials sample near the best parameters. The best few trees are reconfigured: subtrees of up to eight tensors are re-contracted optimally by subset dynamic programming, until nothing improves. - **Slice.** `slice` fixes, one at a time, the index that leaves the least total work, pricing each candidate incrementally. A second search round then finds a tree for the network with the first round's slices fixed. - **Contract.** `contract_plan` runs every slice in a fixed accumulation order and sums the slices in order. Threads are bounded by an 8 GiB budget; WASI runs sequentially. The bits are identical either way. - **CLI.** `wai-quantum tn --file CIRCUIT.jsonl [--bits --open --trials --seed --cap-log2 --plan-only --json]` ## Evidence **Path quality on identical networks.** Single amplitudes of random circuits on the 54-qubit advantage-experiment grid (√X/√Y/√W layers and fSim(π/2, π/6) on staggered couplers), simplified to 174–395 tensors. Figures are log₁₀ operations, unsliced: | cycles | this module (256 trials) | independent hyper-optimiser (64 trials, greedy + hypergraph partitioning + reconfiguration) | |---|---|---| | 10 | 10.48 (4 s) | 10.49 (82 s) | | 12 | 13.91 (7 s) | 14.28 (148 s) | | 14 | 14.63 (8 s) | 14.27–14.44 (683–1194 s) | | 16 | 17.60 (10 s) | 17.32 (498 s) | | 20 | 18.77 (10 s) | 18.94 (541 s) | **Slicing at m = 10.** Both cap the largest intermediate at 2²⁴ elements, 16× below the unsliced intermediate: - this module: 10.48 in 16 slices, the same work as unsliced; - the independent tool: 10.66 in 16 slices. **Correctness at full size.** The 54-qubit, 10-cycle amplitude agrees to 12 significant figures with an independent contraction of the same circuit, which used its own path search and a BLAS backend: | contraction | amplitude | time | |---|---|---| | this module (16 slices) | −8.130144653823e−9 − 7.507630273949e−11i | 5 s search + 24 s contraction, 6 GB peak | | independent | −8.130144653822e−9 − 7.507630274107e−11i | 1361 s | **Tests** - Amplitudes match a dense state vector: - for every tree family; - after reconfiguration; - with slicing; - for open-output batches. - Reconfiguration reaches the exact optimum on 40 random small networks, checked by an independent brute-force search. - Incremental slice pricing matches a full recount. - The same seed gives the same plan. - Mutation testing: breaking any of these fails a named test: - the permutation odometer; - the complex product; - the contraction's summed indices; - slice pricing; - the slice offset; - the reconfiguration DP's choice; - the reconfiguration DP's output set. An earlier miss, where reconfiguration was silently disabled, is what the optimum test now catches. - `bit_identity` pins a plan and its sliced, threaded amplitude. All 11 pins pass natively and under `wasm32-wasip2`. - `tn` output is byte-identical natively and as a WASI component. That covers a sliced, open-output batch. - `cargo test --locked --features full --lib --tests`: 363 + 11 + 2 + 3 passed. Every feature builds alone with zero warnings, and clippy is clean on the new code. ## Honest boundaries - **Slicing on deep circuits.** Slicing deep circuits far below their natural intermediate size costs real work. At m = 14 with a 2³⁰ cap, a plan costs about 12× its unsliced cost. - **The executor is scalar.** It runs about 10⁹ complex multiply-adds per second per core, with no SIMD kernels or GPU. Plans of 10¹³ operations or more are for planning and verification arithmetic here, not for contraction. - **Simple graphs only.** Every index joins at most two tensors; diagonal-gate hyperedges are not exploited. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
wai-quantum 0.3.25: error correction at circuit level, sampled, modelled and decoded exactly
All checks were successful
no-vanity-metrics / WAI public text names no comparison (pull_request) Successful in 3s
no-vanity-metrics / WAI public text names no company or product (pull_request) Successful in 3s
standards workspaces build + test / eoc-rs (pull_request) Successful in 1m54s
standards workspaces build + test / jcp-rs (pull_request) Successful in 1m26s
standards workspaces build + test / openpay (pull_request) Successful in 4m53s
standards workspaces build + test / proof-rs (pull_request) Successful in 1m12s
standards workspaces build + test / sandbox-rs (pull_request) Successful in 2m11s
standards workspaces build + test / smart-byte-rs (pull_request) Successful in 3m38s
WAI conformance / cargo-class corpora · linux-arm64 (pull_request) Successful in 7m57s
WAI conformance / cross-arch byte-equality · linux-arm64 (pull_request) Successful in 54s
WAI conformance / cargo-class corpora · linux (pull_request) Successful in 3m59s
WAI conformance / v2 vocabulary · manifests validate as stated (pull_request) Successful in 12s
WAI energy receipts / energy receipts · linux-arm64 (pull_request) Successful in 2m15s
WAI conformance / independent verifiers · claims, JWP, key discovery and integer payloads (Python) (pull_request) Successful in 2m10s
WAI conformance / cross-arch byte-equality · linux (pull_request) Successful in 26s
WAI conformance / C2PA manifest emission · signed, read back, validated (pull_request) Successful in 48s
WAI energy receipts / energy receipts · linux (pull_request) Successful in 1m13s
WAI JPEG-AI whole decode (pinned inputs, required) / fetch pinned JPEG-AI inputs → whole decode + pixel hash, required (pull_request) Successful in 1m2s
WAI neural sink gates / model-free refusals of the neural sink (pull_request) Successful in 1m3s
WAI mbt2018_mean integer decode (regenerated vectors) / regenerate mbt2018_mean integer vectors → Rust decode, required (pull_request) Successful in 3m55s
wai-web wasm32 / wai-web wasm32 build · corpus, menu and writers (pull_request) Successful in 1m44s
standards workspaces build + test / arl-rs (pull_request) Successful in 22m23s
standards workspaces build + test / joule-ui-rs (pull_request) Successful in 20m55s
standards workspaces build + test / jouledesk-rs (pull_request) Successful in 19m6s
standards workspaces build + test / joulehook-rs (pull_request) Successful in 10m16s
standards workspaces build + test / sense-rs (pull_request) Successful in 7m52s
standards workspaces build + test / macOS energy backends (pull_request) Successful in 9m59s
WAI conformance / cargo-class corpora · macos (pull_request) Successful in 6m11s
WAI conformance / cross-arch byte-equality · macos (pull_request) Successful in 31s
WAI energy receipts / energy receipts · macos (pull_request) Successful in 2m21s
ed592d76f9
quantum_frame takes an error-correction experiment as what it is: a noisy
Clifford circuit with detectors and observables.

- parse reads the ecosystem's circuit text (resets and measurements in Z and
  X, H/S/sqrt(X)/Paulis/CX/CZ/SWAP, flip and depolarizing noise, detectors,
  observables, REPEAT), and refuses anything else rather than skipping it.
- sample is bit-packed Pauli-frame simulation, 64 shots per word, with
  geometric skipping between noise hits; reproducible from
  (circuit, shots, seed).
- error_model derives the detector error model by backward sensitivity
  propagation. It converts depolarizing channels to equivalent independent
  mechanisms exactly, XOR-merges identical ones, and refuses non-deterministic
  detectors. A graphlike mechanism stays one matching edge; otherwise it splits
  into X and Z halves, then into per-qubit parts.
- surface_code_memory generates the rotated surface-code memory experiment.

quantum_match decodes by exact minimum-weight perfect matching: Dijkstra on
integer weights, with boundary paths computed once and dominated pairs cut,
then Edmonds' blossom. memory_experiment and fit_code_model measure
P(d) = a(p/p*)^((d+1)/2): a = 0.023, p* = 0.0100 under uniform circuit
noise, and CodeFit::surface_code feeds that into a resource estimate.

Checked against an independent implementation:
- generated circuits identical byte for byte (135 configurations, d 2-15,
  1-8 rounds);
- error models identical mechanism for mechanism, to 1e-12 in probability
  (41 circuits: rotated and unrotated surface codes in both bases,
  repetition codes);
- decoded logical error rates within 1.4 standard errors on all 12 grid
  points.

tests/frame_reference.rs keeps a circuit and a model from that implementation
as fixtures. Blossom equals brute force on 3000 random graphs. A mirrored
random Clifford circuit over every gate type ties the sampler's forward rules
to the model's backward ones. Mutating the depolarizing conversion, any gate
rule on either side, the determinism check or the decomposition fails a named
test. bit_identity pins sampling, decoding and the fit natively and under
wasm32-wasip2; repro gains an in-crate exp, within an ulp.

CLI: wai-quantum qec [-d --rounds --p --shots --seed --json] | --file |
--circuit | --dem | --fit, and estimate --prefactor/--threshold for a
measured code. Byte-identical natively and under wasm32-wasip2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
wai-quantum 0.3.26: tensor-network contraction, hyper-optimised, sliced, bit-identical
All checks were successful
standards workspaces build + test / proof-rs (pull_request) Successful in 1m12s
standards workspaces build + test / joule-code-rs (pull_request) Successful in 2m14s
standards workspaces build + test / sandbox-rs (pull_request) Successful in 2m11s
standards workspaces build + test / joulecontract-rs (pull_request) Successful in 1m11s
standards workspaces build + test / map-rs (pull_request) Successful in 2m6s
standards workspaces build + test / mesh-rs (pull_request) Successful in 57s
standards workspaces build + test / smart-byte-rs (pull_request) Successful in 3m38s
standards workspaces build + test / openpay (pull_request) Successful in 3m56s
WAI conformance / cargo-class corpora · linux (pull_request) Successful in 3m56s
WAI conformance / v2 vocabulary · manifests validate as stated (pull_request) Successful in 14s
WAI conformance / independent verifiers · claims, JWP, key discovery and integer payloads (Python) (pull_request) Successful in 2m9s
WAI conformance / cross-arch byte-equality · linux (pull_request) Successful in 22s
WAI conformance / C2PA manifest emission · signed, read back, validated (pull_request) Successful in 44s
WAI conformance / cargo-class corpora · linux-arm64 (pull_request) Successful in 5m7s
WAI energy receipts / energy receipts · linux (pull_request) Successful in 1m9s
WAI conformance / cross-arch byte-equality · linux-arm64 (pull_request) Successful in 37s
WAI JPEG-AI whole decode (pinned inputs, required) / fetch pinned JPEG-AI inputs → whole decode + pixel hash, required (pull_request) Successful in 58s
WAI energy receipts / energy receipts · linux-arm64 (pull_request) Successful in 1m28s
WAI neural sink gates / model-free refusals of the neural sink (pull_request) Successful in 1m0s
WAI mbt2018_mean integer decode (regenerated vectors) / regenerate mbt2018_mean integer vectors → Rust decode, required (pull_request) Successful in 3m55s
wai-web wasm32 / wai-web wasm32 build · corpus, menu and writers (pull_request) Successful in 1m47s
standards workspaces build + test / arl-rs (pull_request) Successful in 3m54s
standards workspaces build + test / joule-ui-rs (pull_request) Successful in 5m38s
standards workspaces build + test / jouledesk-rs (pull_request) Successful in 4m46s
standards workspaces build + test / joulehook-rs (pull_request) Successful in 5m49s
standards workspaces build + test / sense-rs (pull_request) Successful in 5m16s
standards workspaces build + test / macOS energy backends (pull_request) Successful in 7m10s
WAI conformance / cargo-class corpora · macos (pull_request) Successful in 7m41s
WAI conformance / cross-arch byte-equality · macos (pull_request) Successful in 40s
WAI energy receipts / energy receipts · macos (pull_request) Successful in 2m19s
ae0d1c4cd4
quantum_tn turns a circuit (any unitary on any qubits, as a matrix) into the
tensor network of one amplitude or an open-output batch, and contracts it.

- Network::amplitude builds the network; simplify absorbs vectors and
  one-qubit gates into neighbours.
- find_path is a seeded hyper-optimiser over two tree families:
  - randomised greedy, scoring size(out)/c - c(size(a)+size(b)) with Gumbel
    noise;
  - recursive bipartition, multilevel (heavy-edge coarsening, several
    initial cuts, refinement at every level), with greedy leaves.
  Families alternate until one leads; later trials sample near the best
  parameters. The best few trees are reconfigured: subtrees of up to eight
  tensors are re-contracted optimally by subset dynamic programming, until
  nothing improves.
- slice fixes the index that leaves the least total work until the largest
  intermediate fits the cap, pricing each candidate incrementally. A second
  search round then finds a tree for the network with the first round's
  slices fixed (all, or the more valuable half).
- contract_plan contracts every slice in a fixed accumulation order and sums
  them in order. Threads are bounded by an 8 GiB budget; WASI runs
  sequentially. The bits are the same everywhere.

Measured on single amplitudes of random circuits on the 54-qubit
advantage-experiment grid (fSim(pi/2, pi/6), staggered couplers), 256 trials,
under ten seconds each, in log10 operations:
  m = 10: 10.48   m = 12: 13.91   m = 14: 14.63   m = 16: 17.60   m = 20: 18.77
An independently developed hyper-optimiser, given the identical networks,
lands within 0.4 of these at every depth, in either direction. The 54-qubit,
10-cycle amplitude, contracted here in 16 slices, agrees with an independent
contraction to 12 significant figures.

Tests:
- Amplitudes match a dense state vector for every tree family, with
  reconfiguration and with slicing.
- Reconfiguration reaches the exact optimum on 40 random small networks.
- Incremental slice pricing matches a full recount.
- The same seed gives the same plan.
- Mutating the permutation, the complex product, the contraction's summed
  indices, slice pricing, the slice offset or the reconfiguration DP fails a
  named test.
- bit_identity pins a plan and its sliced, threaded amplitude natively and
  under wasm32-wasip2.

CLI: wai-quantum tn --file CIRCUIT.jsonl [--bits --open --trials --seed
--cap-log2 --plan-only --json], byte-identical natively and under
wasm32-wasip2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Transaction-Science/open-standards!144
No description provided.