Re-landed from PR #659 (branch wai/quantum-wasmq, head 39fdb517a) as one
commit on main, under the land-it model. Five review rounds; the last had
no high or critical finding, and its mediums were fixed on the branch.
A hybrid quantum program runs classical code between its gates. OpenQASM 3
declares such a function with `extern` and leaves its body and linking
outside the language. wasmQ (wai.quantum.wasmq) packs the program and the
WebAssembly that defines its externs into one content-addressed WAI
envelope; a run gives the same result bytes and fuel on every host and
seals the engine's job receipt.
- extensions/quantum-wasmq.md (normative) and quantum-wasmq.wit.
- wai/wai-wasmq: the profile (Lime1, nothing imported, bounded memory,
refusal codes W001-W017); what a run asks of its host, bounded from the
bundle alone before anything runs; fuel defined on the module as written;
a weighted stack; two engines (the pinned wasmtime 50.0.1 and an
interpreter of the crate's own that also runs on wasm32); the envelope,
runner, receipts, transcript replay, reference programs and vectors.
- wai-quantum: engine::wasmq (built with quantum_receipt), the job form
beside its receipts; the estimate verifier answers a request no host
re-runs with a verdict carrying rerun_error, combined here with main's
reaction clock (clock_of).
- wai/quantum-conformance/wasmq: envelopes, refusals and receipts.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2.4 KiB
wai-wasmq
wasmQ: a deterministic, metered, receipted WebAssembly profile for hybrid quantum-classical
programs (../extensions/quantum-wasmq.md).
An OpenQASM 3 program declares the classical functions it calls between gates with
extern. A wasmQ envelope carries the program, the WebAssembly modules that define those
functions and their priors, pinned by BLAKE3. This crate:
- holds a module to the profile (
profile): Lime1, nothing imported, memory, size and stack bounded, each rule a refusal code; and reads a program within bounds it is held to as it is read, so that no short program makes a host hold or do more than it has; - prepares it (
meter) so that it meters its own fuel, weighs its own stack and returns only canonical NaNs, for an engine that does not hold those rules itself; - runs it on two engines (
engine): the pinned wasmtime release, and an interpreter of its own (interp) that also runs on wasm32; - packs and opens envelopes (
envelope), bounding from the bundle alone what a run asks of its host that fuel does not count, runs a bundle of Clifford gates shot by shot on a stabilizer tableau with each callout metered (run), in whole numbers throughout, and seals the job receipt every verifier of a job checks: the engine holds a wasmQ job to its form (wai-quantum,engine::wasmq), and this crate takes the profile's constants from there, so a run writes what a verifier holds it to; - replays a record of calls through the modules alone (
run::replay), and gives its digest (run::transcript_blake3); - builds the reference programs (
reference) and checks the conformance vectors (vectors, and thewasmq_vectorsbinary).
The reference modules, the engine's qLDPC decoder and atom rearrangement planner built as
wasmQ modules, are in modules/; their modules of record are in
../quantum-conformance/wasmq/modules/.
wai-quantum pack-wasmq memory.qasm --callout decode64=qldpc_decoder.wasm \
--prior qldpc_decoder.wasm=checks.bin --shots 1000 -o memory.wai
wai-quantum run memory.wai --json > job.json
wai-quantum verify job.json --bundle memory.wai
cargo run --release --bin wasmq_vectors -- verify ../quantum-conformance/wasmq
mutations.py removes each of the crate's checks in turn, and says which test then fails:
a check whose tests all still pass is one no test is of. It builds the crate once for each,
so it runs on a build host, not in CI.