wai-quantum 0.4.0: wai.quantum.circuit2 — a correctly rounded phase table, circuit/1 stated exactly, both read by stated rules #207
Loading…
Reference in a new issue
No description provided.
Delete branch "wai-quantum-circuit2"
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?
Why
The
wai.quantum.circuitphase table is built by a recurrence whose floors compound. FromP(8)on, the imaginary part is too large, by up to 7032 units of2^−30, andP(19..32)apply no phase at all, so a QFT past about 14 qubits reconstructs the wrong state. The vectors never caught it: they run the QFT from|0…0⟩, where every controlled phase multiplies zeros.The table is part of the registered payload format, and a registered capability's payload format is fixed for good (SPEC §8). Correcting it in place would change the reconstruction, the
circuit_hashand every receipt of existing content. So the corrected table is a new capability, and circuit/1 stays bit for bit as it was.What
wai.quantum.circuit2(extensions/quantum-sim, SPEC §5)WQC2; contractextwai.quantum.circuit2/1, numericwai.det.amp64, gatesetcliffordT+dyadicP.rn.P(k)holds the integers nearest to2^30·cos(2π/2^k)and2^30·sin(2π/2^k). The literal table is normative (§3.2, Appendix B.2, digestd34cb793…3510). An exact-integer interval procedure certifies every entry; it is informative.wai.quantum.circuit, frozen and stated exactly (§3.1, Appendix B.1, digest3fa9805f…8466)Both capabilities are specified to the bit (§2–§4)
Little-endian integers, overflow-free section bounds, and one section of each known kind.
The contract and the measurement are read as I-JSON (RFC 7493), with every rule stated in full:
The reference reader decides each rule from the section's text, so no build feature can change a verdict. Only the refusal class is normative.
Three refusal classes (malformed, contract, invalid), in the order a reader checks them.
The arithmetic, the gate matrices, the hash layouts and the shot sampler.
A new §8 explains why circuit2 is its own capability and what an older reader does with it: it refuses
WQC2at the magic.wai-quantum 0.4.0 (breaking)
Circuitcarries aGateset { V1, V2 };Circuit::newbuilds V2.to_wqc,circuit_hashandcircuit_idreturn aResult.from_wqcenforces every reader rule.reject_corpus()andaccept_corpus()return the payloads a reader must refuse, each with its class, and must accept, each with its reading.wai-rs and the other consumers
wai.quantum.circuit2, and envelopes carry the circuit's capability.--gateset v1|v2.wai-quantum-serve0.5.0.Compatibility
Gateset::V1. The new V2 pins sit beside them.Conformance
quantum-conformance/adds three vectors that see the phase table. Under either table,dyadic_ladder's hash changes with any ±1 change to aP(1..32)component.v2/holds the same circuits as circuit2.reject/holds at least one payload for each refusal a payload can carry, written fromreject_corpus().accept/holds payloads at the edges of the same rules that a reader must accept, each with how it reads, written fromaccept_corpus().tools/referee.pyis an independent, integer-only Python referee. It:wasm32-wasip2leg that runs the core tests and corpus verification under wasmtime.Review
Three adversarial review rounds; every upheld finding is fixed.
Round 1 upheld nine findings:
Round 2 reviewed those fixes and upheld two real defects:
Both are fixed by the strict reader, the full rule list and the accept tree.
Round 3 reviewed the strict reader and upheld six findings:
f64parse stops reading an exponent at 0x10000, so a literal of about 655,000 offsetting zeros was misjudged;intlimit on a zero-padded exponent;Both readers now decide the range on the digits with saturating exponent arithmetic. The 309-digit limit is derived independently in the test. Both long literals and the padded exponent are in the corpus.
A differential run then compared the Rust reader and the referee on generated payloads placed both as a contract member and as a measurement. The payloads concentrate on each rule's limit:
The two readers agreed on every accept/refuse verdict, every class and every measurement reading. They differ only in which rule they name first when a payload breaks several, which the spec leaves open.
Tested
wai-quantum:cargo test --locked --release --features full --lib --testswai-rs: the energy-receipts feature set,--lib --bins --test video_receiptwai-quantum-serveandwai-webnative testswai_quantum_vectors verify, natively and under wasmtime (wasm32-wasip2)wasm32-wasip2), added to that CI legpython3 -I quantum-conformance/tools/referee.py quantum-conformancescripts/check-comparative-prose.shandscripts/check-no-vanity-metrics.sh🤖 Generated with Claude Code
PHASE_V1 and PHASE_V2 are literal [Amp; 33] constants. PHASE_V1 holds the values of the circuit/1 half-angle recurrence, unchanged, and PHASE_V2 holds the integer nearest to 2^30·cos(2π/2^k) and 2^30·sin(2π/2^k) for k = 1..32. The OnceLock and the runtime recurrence are gone; the recurrence now lives in a test that checks it against PHASE_V1. Gateset { V1, #[default] V2 } is non_exhaustive and names, per variant, the capability, magic, contract ext, numeric identifier, gateset string, table, phase(k), inv_sqrt2, canonical contract bytes (rendered with format!) and a BLAKE3 table digest, with from_magic and from_capability as inverses. The free phase() and inv_sqrt2() still return the circuit/1 values, now read from Gateset::V1, so every existing circuit, hash and pin is unchanged. Their removal comes with the Circuit gateset field. New tests: phase_table_v1_is_frozen (recurrence, digest 3fa9805f…8466, the P(19..32) defect, inv_sqrt2 759250124, the dyadic_ladder statevector hash 9754af24…851d); phase_table_v2_is_certified_nearest (u128 interval enclosures, both ends round alike and sit more than 2^20 ulps from a tie, digest d34cb793…3510, inv_sqrt2 759250125); every_v2_phase_is_within_one_unit_of_ideal (against repro::sin_cos, with circuit/1 failing the same check for every k >= 8 as the negative control); table_identities_per_gateset, which replaces dyadic_table_is_unit_modulus; and gateset_identifiers_are_consistent, which checks the identifiers round-trip and that the V1 contract bytes equal the serializer render for every n_qubits. Co-Authored-By: Claude Opus 5.5 <[email protected]>