open-standards/wai/quantum-conformance/receipts/make.sh
Transaction Science 1cf0076e86 Receipts corpus: qudit jobs, and wasmQ and qudit jobs the job service made, judged alike by both verifiers
quantum-conformance/receipts/ had no qudit job and no wasmQ job a service sealed. It gains
eight made receipts, each pinned in made.lock.json and named in MADE:

- cli-qudit-qutrit-bell, -ququarts-phase, -six-levels, -qubits-ghz: `wai-quantum qudit run
  --demo-key --json` (wai.quantum.qudit/1): a qutrit Bell pair with its amplitudes, two
  ququarts under a controlled sum, a phase and a Fourier power, two qudits of six levels
  (F_2 x F_3), and a GHZ state as a qudit job of dimension 2;
- service-wasmq-surface3-decode64, service-wasmq2-t-toffoli, service-wasmq-fault-fuel and
  service-qudit-qutrit-bell: POST /v1/wasmq and POST /v1/qudit on a job service built from
  this checkout (Linux x86_64), each the service's job report sealed with its key; the
  wasmQ/2 run's energy.run the processor packages' reading over the worker's window
  (attribution none), the fault sealed.

make.sh makes them (the service's when WAI_QSVC_BIN names its binary). Both verifiers (the
command line's `verify` and receipt_verify.py) give each new receipt no reason, and
receipt_differential.py --reference agrees three ways on all 421 receipts and on every one
of the 33,184 one-member changes of the 111 valid ones; the plants wasmq-unchecked,
landscape-unchecked and lenient-key are each caught. generate.py --check and --self-test,
and receipt_verify.py --self-test (846 checks), pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-10 23:18:39 -05:00

113 lines
11 KiB
Shell

#!/usr/bin/env bash
# make.sh: the receipts of the corpus that the command line makes (README.md).
#
# bash make.sh PATH/wai-quantum OUT_DIR
#
# Each is made as a person makes one: a run on this machine, a run on the reference
# provider served over a local process, and a run on the free job service (which needs
# the network). The runs here are sealed with the published demo key (--demo-key), so
# anyone can make the same; the service seals with its own. A receipt made again differs
# in its times and, on the service, its key, and verifies all the same: the corpus keeps
# the ones it was given, and never makes them again to pass a test.
set -euo pipefail
B=$(cd "$(dirname "$1")" && pwd -P)/$(basename "$1")
ENVELOPES=$(cd "$(dirname "$0")/../wasmq/envelopes" && pwd -P)
OUT=$(mkdir -p "$2" && cd "$2" && pwd -P)
W=$(mktemp -d)
trap 'rm -rf "$W"' EXIT
cd "$W"
export HOME="$W" XDG_CONFIG_HOME="$W/config" WAI_QUANTUM_CREDENTIALS=file
unset WAI_QUANTUM_KEY WAI_QUANTUM_PROVIDERS
printf 'OPENQASM 3.0;\ninclude "stdgates.inc";\nqubit[2] q;\nbit[2] c;\nh q[0];\ncx q[0], q[1];\nc = measure q;\n' > bell.qasm
printf 'OPENQASM 3.0;\ninclude "stdgates.inc";\nqubit[3] q;\nbit[3] c;\nh q[0];\nt q[0];\ncx q[0], q[1];\nrz(pi/8) q[2];\ncx q[1], q[2];\nc = measure q;\n' > three.qasm
{ printf 'OPENQASM 3.0;\ninclude "stdgates.inc";\nqubit[30] q;\nbit[30] c;\n'; for i in $(seq 0 28); do printf 'rx(0.3) q[%d];\ncx q[%d], q[%d];\n' "$i" "$i" "$((i + 1))"; done; printf 'c = measure q;\n'; } > wide.qasm
printf 'OPENQASM 3.0;\ninclude "stdgates.inc";\nqubit[1] q;\nrx(0.4) q[0];\n' > rx.qasm
"$B" run bell.qasm --shots 1000 --seed 7 -o "Z0 Z1" -o X0 --demo-key --json > "$OUT/cli-run-observables.json"
"$B" run three.qasm --method statevector --shots 500 --seed 3 --demo-key --json > "$OUT/cli-run-statevector.json"
"$B" run bell.qasm --method trajectories --noise depolarizing_2q=0.03 --noise readout=0.02 --shots 300 --seed 5 -o "Z0 Z1" --demo-key --json > "$OUT/cli-run-trajectories.json"
"$B" run wide.qasm --method mps --shots 20 --seed 1 --demo-key --json > "$OUT/cli-run-mps.json"
"$B" compile rx.qasm --demo-key --json > "$OUT/cli-compile.json"
"$B" providers add ref --kind process -- "$B" providers reference --stdio > /dev/null
"$B" run bell.qasm --provider ref --shots 300 --seed 4 --demo-key --json > "$OUT/cli-provider-reference.json"
"$B" providers add priced --kind process -- "$B" providers reference --stdio --price 0.0003 --currency USD > /dev/null
"$B" run bell.qasm --provider priced --shots 300 --seed 4 --yes --demo-key --json > "$OUT/cli-provider-reference-priced.json"
printf 'OPENQASM 3.0;\ninclude "stdgates.inc";\ninput float theta;\nqubit[1] q;\nbit[1] c;\nrx(theta) q[0];\nc = measure q;\n' > theta.qasm
"$B" run bell.qasm --program three.qasm --shots 64 --seed 3 --demo-key --json > "$OUT/cli-set-programs.json"
"$B" run theta.qasm --sweep theta=0.25,0.5,1.5 --shots 64 --seed 9 --demo-key --json > "$OUT/cli-set-sweep.json"
# Jobs under a contract (section 8.7): the cheapest exact route here, under a deadline and a
# ceiling; auto's class kept; every route weighed with the person's providers, the free
# simulator chosen by its class and shadowed (and again with a seed whose shadow's wraps at
# 2^53); any class, where a method here and a free provider tie on money and time and the
# method comes first; a provider named and allowed, under a ceiling, confirmed; bounded, where a single-
# precision route does not meet it; the CPU asked for; a device target beside the person's
# providers; and a pulse program.
printf 'OPENQASM 3.0;\ninclude "stdgates.inc";\nqubit[2] q;\nbit[2] c;\nrx(0.3) q[0];\ncx q[0], q[1];\nc = measure q;\n' > rot.qasm
printf 'OPENQASM 3.0;\ndefcalgrammar "openpulse";\ncal {\n extern port d0;\n extern port a0;\n frame q0 = newframe(d0, 5.0e9, 0);\n frame c0 = newframe(a0, 5.0e9, 0);\n}\ndefcal x $0 { play(q0, drag(0.4, 64dt, 16dt, 0.2)); }\ndefcal measure $0 -> bit { return capture_v2(c0, 100dt); }\nbit c;\nx $0;\nc = measure $0;\n' > pulse.qasm
"$B" run bell.qasm --shots 1000 --seed 7 --exactness exact --deadline 60 --max-cost 1:USD --demo-key --json > "$OUT/cli-contract-local.json"
"$B" run three.qasm --shots 500 --seed 3 --deadline 600 --demo-key --json > "$OUT/cli-contract-auto.json"
"$B" run bell.qasm --shots 300 --seed 4 --exactness simulated --allow-providers --demo-key --json > "$OUT/cli-contract-routed.json"
"$B" run bell.qasm --shots 300 --seed 9007199254740990 --exactness simulated --allow-providers --demo-key --json > "$OUT/cli-contract-routed-seed.json"
"$B" run bell.qasm --shots 100 --seed 2 --exactness any --allow-providers --deadline 60 --demo-key --json > "$OUT/cli-contract-any.json"
"$B" run bell.qasm --provider priced --allow-providers --shots 300 --seed 4 --max-cost 1:USD --yes --demo-key --json > "$OUT/cli-contract-provider-priced.json"
"$B" run rot.qasm --shots 100 --seed 2 --exactness bounded --deadline 60 --demo-key --json > "$OUT/cli-contract-bounded.json"
"$B" run bell.qasm --shots 100 --seed 2 --fabric cpu --deadline 60 --demo-key --json > "$OUT/cli-contract-fabric-cpu.json"
"$B" run bell.qasm --shots 50 --seed 2 --target synthetic-line-5 --allow-providers --deadline 60 --demo-key --json > "$OUT/cli-contract-target.json"
"$B" run pulse.qasm --method pulse --shots 50 --seed 2 --exactness bounded --deadline 60 --demo-key --json > "$OUT/cli-contract-pulse.json"
# wasmQ jobs, each from the profile's own envelope (../wasmq/envelopes/).
for pair in run:surface3-decode64 state-job:surface5-decode64-job fault:fault-fuel fault-run:fault-fuel-run fault-init:fault-in-init fault-prior:fault-in-prior; do
"$B" run "$ENVELOPES/${pair#*:}.wai" --demo-key --json > "$OUT/cli-wasmq-${pair%%:*}.json"
done
# wasmQ/2 jobs (quantum-wasmq section 11), each from the second version's envelopes: the
# exact method, its angle arguments and its feedback, and one Clifford program by each
# method; each run in a process of its own, its energy read where the host meters it.
for pair in t-toffoli:v2-t-toffoli feedback-rotation:v2-feedback-rotation angle-arguments:v2-angle-arguments rotations-and-a-reset:v2-rotations-and-a-reset stabilizer:v2-stabilizer exact-of-a-clifford-program:v2-exact-of-a-clifford-program; do
"$B" run "$ENVELOPES/${pair#*:}.wai" --demo-key --json > "$OUT/cli-wasmq2-${pair%%:*}.json"
done
# Energy-landscape jobs (wai/extensions/quantum-landscape.md), each sealed with the demo key: a
# sampling run, a settle, a quench, a replay, a sweep and a comparison here; and a run on the
# reference provider over a local process (quantum-providers section 11), free, and priced and
# confirmed.
"$B" landscape run --example talks --seed 7 --demo-key --json > "$OUT/cli-landscape-run.json"
"$B" landscape run --example chain --demo-key --json > "$OUT/cli-landscape-settle.json"
"$B" landscape run --example talks --seed 7 --temperature 0 --demo-key --json > "$OUT/cli-landscape-quench.json"
"$B" landscape replay --example talks --seeds 4 --demo-key --json > "$OUT/cli-landscape-replay.json"
"$B" landscape sweep --example clusters --seeds 2 --demo-key --json > "$OUT/cli-landscape-sweep.json"
"$B" landscape compare --example colour-four --seeds 2 --demo-key --json > "$OUT/cli-landscape-compare.json"
"$B" landscape run --example talks --seed 7 --provider ref --demo-key --json > "$OUT/cli-landscape-provider.json"
"$B" landscape run --example talks --seed 7 --provider priced --yes --demo-key --json > "$OUT/cli-landscape-provider-priced.json"
# Qudit jobs (quantum-sim section 9.7), each sealed with the demo key: a qutrit Bell pair
# with its amplitudes, ququarts under a phase, a register of six levels (F_2 x F_3), and qubits.
printf '{"d": 3, "qudits": 2, "gates": [{"gate": "fourier", "qudits": [0]}, {"gate": "csum", "qudits": [0, 1]}], "shots": 1000, "seed": 7, "amplitudes": ["00", "11", "22"]}' > qutrits.json
printf '{"d": 4, "qudits": 2, "gates": [{"gate": "fourier", "qudits": [0]}, {"gate": "csum", "qudits": [0, 1], "power": 3}, {"gate": "phase", "qudits": [1], "powers": [0, 1, 2, 3]}, {"gate": "fourier", "qudits": [1], "power": 3}], "shots": 400, "seed": 5}' > ququarts.json
printf '{"d": 6, "qudits": 2, "gates": [{"gate": "fourier", "qudits": [0]}, {"gate": "shift", "qudits": [1], "power": 5}, {"gate": "csum", "qudits": [0, 1]}, {"gate": "clock", "qudits": [0], "power": 2}], "shots": 600, "seed": 11, "amplitudes": ["05", "34"]}' > six.json
printf '{"d": 2, "qudits": 3, "gates": [{"gate": "fourier", "qudits": [0]}, {"gate": "csum", "qudits": [0, 1]}, {"gate": "csum", "qudits": [1, 2]}], "shots": 256, "seed": 3}' > qubits.json
for pair in qutrit-bell:qutrits ququarts-phase:ququarts six-levels:six qubits-ghz:qubits; do
"$B" qudit run "${pair#*:}.json" --demo-key --json > "$OUT/cli-qudit-${pair%%:*}.json"
done
# wasmQ envelopes and a qudit job on a job service built from this checkout, run as jobs and
# sealed with its key (WAI_QSVC_BIN names its binary; without it they are not made): the
# surface-code round, the second version's exact method with the energy the service read of
# its worker, a fault sealed, and a qutrit Bell pair.
if [ -n "${WAI_QSVC_BIN:-}" ]; then
port=$(( 18900 + RANDOM % 500 ))
WAI_QSVC_KEY="$W/qsvc.key" WAI_QSVC_STORE="$W/qsvc-store" WAI_QSVC_ADDR="127.0.0.1:$port" WAI_QSVC_JOB_GB=2 WAI_QSVC_BUDGET_GB=4 \
WAI_QSVC_WORKERS=1 WAI_QSVC_MIN_FREE_PCT=0 "$WAI_QSVC_BIN" serve > "$W/qsvc.log" 2>&1 &
qsvc=$!
trap 'kill $qsvc 2>/dev/null || true; rm -rf "$W"' EXIT
for _ in $(seq 1 100); do curl -fs -o /dev/null "http://127.0.0.1:$port/v1/health" && break; sleep 0.2; done
ended() { python3 -I -c 'import json,sys,time,urllib.request
job = json.load(sys.stdin)
while job.get("status") in ("queued", "running"):
time.sleep(0.2)
job = json.load(urllib.request.urlopen("http://127.0.0.1:%s/v1/jobs/%s?wait=20" % (sys.argv[1], job["id"])))
assert job["status"] == "done", job
sys.stdout.write(json.dumps(job))' "$port"; }
for pair in service-wasmq-surface3-decode64:surface3-decode64 service-wasmq2-t-toffoli:v2-t-toffoli service-wasmq-fault-fuel:fault-fuel; do
curl -fs "http://127.0.0.1:$port/v1/wasmq" -H 'content-type: application/octet-stream' --data-binary @"$ENVELOPES/${pair#*:}.wai" | ended > "$OUT/${pair%%:*}.json"
done
curl -fs "http://127.0.0.1:$port/v1/qudit" -H 'content-type: application/json' --data-binary @qutrits.json | ended > "$OUT/service-qudit-qutrit-bell.json"
fi
"$B" submit bell.qasm --shots 200 --seed 11 --json > "$OUT/service-run.json"
"$B" submit bell.qasm --shots 200 -o "Z0 Z1" --json > "$OUT/service-run-stabilizer.json"
for f in "$OUT"/cli-*.json "$OUT"/service-*.json; do "$B" verify "$f" > /dev/null || { echo "make.sh: $f does not verify" >&2; exit 1; }; done
echo "make.sh: made $(ls "$OUT"/cli-*.json "$OUT"/service-*.json | wc -l) receipts in $OUT"