wai-quantum 0.3.26: tensor-network contraction, hyper-optimised, sliced, bit-identical #144
Loading…
Reference in a new issue
No description provided.
Delete branch "wai-quantum-tn"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Stacked on #143. Merge #143 first; until then this diff also shows #143's commit.
What
wai-quantum0.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_tnfinds that order, slices it to fit memory, and contracts it to the same bits on every machine.Build.
Network::amplitudeturns any unitaries on any qubits into the network of one amplitude, or of an open-output batch.simplifyabsorbs vectors and one-qubit gates into their neighbours.Order.
find_pathis a seeded hyper-optimiser over two tree families:size(out)/c − c·(size(a)+size(b))with Gumbel noise;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.
slicefixes, 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_planruns 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:
Slicing at m = 10. Both cap the largest intermediate at 2²⁴ elements, 16× below the unsliced intermediate:
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:
Tests
Amplitudes match a dense state vector:
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:
An earlier miss, where reconfiguration was silently disabled, is what the optimum test now catches.
bit_identitypins a plan and its sliced, threaded amplitude. All 11 pins pass natively and underwasm32-wasip2.tnoutput 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
🤖 Generated with Claude Code
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]>