#!/usr/bin/env bash # smoke.sh: the command line as a reader uses it, every check exact. # # bash smoke.sh path/to/wai-quantum [SERVICE_URL] # # With SERVICE_URL, `submit` sends one job to the service there and its # receipt is checked here. Each command's output is written to a file before # it is read, so no check depends on a pipe closing early. set -euo pipefail W="$1" SVC="${2:-}" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT export XDG_CONFIG_HOME="$tmp/config" unset WAI_QUANTUM_KEY fail() { echo "smoke: $*" >&2; exit 1; } has() { grep -q -- "$2" "$1" || { echo "--- $1:" >&2; cat "$1" >&2; fail "expected: $2"; }; } cat > "$tmp/ghz.qasm" <<'EOF' OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; bit[3] c; h q[0]; cx q[0], q[1]; cx q[1], q[2]; c = measure q; EOF "$W" lint "$tmp/ghz.qasm" > "$tmp/lint" has "$tmp/lint" "ok — 3 qubits, 3 gates, 3 bits measured" printf 'OPENQASM 3.0;\nqubit[1] q;\nfoo q[0];\n' > "$tmp/bad.qasm" if "$W" lint "$tmp/bad.qasm" > "$tmp/lint-bad"; then fail "lint passed a program with an unknown gate"; fi has "$tmp/lint-bad" "bad.qasm:3: unknown gate foo" echo "lint: ok" "$W" plan "$tmp/ghz.qasm" --json > "$tmp/plan.json" python3 -c 'import json,sys; p=json.load(open(sys.argv[1])); assert p["method"]=="stabilizer" and p["qubits"]==3, p' "$tmp/plan.json" echo "plan: ok, stabilizer" "$W" run "$tmp/ghz.qasm" --shots 1000 -o "Z0 Z2" --json > "$tmp/job.json" 2> "$tmp/run.err" has "$tmp/run.err" "made a signing key" python3 - "$tmp/job.json" <<'EOF' import json, sys j = json.load(open(sys.argv[1])) r = j["result"] assert j["status"] == "done" and j["method"] == "stabilizer", j assert set(r["counts"]) <= {"000", "111"} and sum(r["counts"].values()) == 1000, r["counts"] assert r["expectations"][0]["value"] == 1.0, r["expectations"] assert r["receipt"]["alg"] == "ed25519" and len(r["receipt"]["key"]) == 64, r["receipt"] assert j["request"] == {"qasm": j["request"]["qasm"], "shots": 1000, "observables": ["Z0 Z2"]}, j["request"] EOF "$W" verify "$tmp/job.json" > "$tmp/verify" has "$tmp/verify" "^signature VALID" python3 -c 'import json,sys; j=json.load(open(sys.argv[1])); j["result"]["counts"]={"000":1000}; json.dump(j,open(sys.argv[2],"w"))' "$tmp/job.json" "$tmp/forged.json" if "$W" verify "$tmp/forged.json" > "$tmp/verify-forged"; then fail "a changed result verified"; fi has "$tmp/verify-forged" "^signature INVALID" # The same user, the same key; the signer is the key's did:key. "$W" key > "$tmp/key" 2> /dev/null has "$tmp/key" "^did:key:z6Mk" has "$tmp/verify" "^signer $(cat "$tmp/key")" echo "run, verify, key: ok, signed by $(cat "$tmp/key")" "$W" run "$tmp/ghz.qasm" > "$tmp/run-text" has "$tmp/run-text" "^method stabilizer" has "$tmp/run-text" "^receipt verifies" if "$W" run "$tmp/ghz.qasm" --shot 5 > /dev/null 2> "$tmp/typo"; then fail "an unknown flag was accepted"; fi has "$tmp/typo" "unexpected argument '--shot'" if "$W" run "$tmp/ghz.qasm" --noise depolarizing=0.1 > /dev/null 2> "$tmp/noise"; then fail "an unknown noise channel was accepted"; fi has "$tmp/noise" "no such channel" echo "refusals: ok" "$W" draw "$tmp/ghz.qasm" > "$tmp/draw" has "$tmp/draw" "^q0: .*H.*●" has "$tmp/draw" "^q2: .*⊕.*M2" echo "draw: ok" printf 'OPENQASM 3.0;\nqubit[2] q;\nbit[2] c;\nh q[0];\nh q[0];\nh q[0];\ncx q[0], q[1];\nc = measure q;\n' > "$tmp/twice.qasm" "$W" critique "$tmp/twice.qasm" > "$tmp/critique" has "$tmp/critique" "2 qubits, 4 gates (3 one-qubit, 1 two-qubit, 0 three-qubit), depth 4" has "$tmp/critique" "^ cancels: h on qubit 0 twice in a row (lines 4 and 5)" "$W" improve "$tmp/twice.qasm" > "$tmp/better.qasm" 2> "$tmp/improve" has "$tmp/improve" "^gates 4 → 2" "$W" equivalent "$tmp/twice.qasm" "$tmp/better.qasm" > "$tmp/same" has "$tmp/same" "^equivalent: both are Clifford circuits with the same tableau" if "$W" equivalent "$tmp/twice.qasm" "$tmp/ghz.qasm" > "$tmp/differ"; then fail "a 2-qubit and a 3-qubit program were the same"; fi has "$tmp/differ" "^different: one has 2 qubits and the other 3" echo "critique, improve, equivalent: ok" "$W" shortcuts "$tmp/ghz.qasm" > "$tmp/shortcuts" has "$tmp/shortcuts" "^Classically easy at any width" printf 'OPENQASM 3.0;\nqubit[8] q;\nh q;\ncz q[0], q[1];\ncz q[1], q[2];\ncz q[2], q[3];\ncz q[3], q[4];\ncz q[4], q[5];\ncz q[5], q[6];\ncz q[6], q[7];\ncz q[7], q[0];\nrz(0.3) q;\n' > "$tmp/ring.qasm" "$W" shortcuts "$tmp/ring.qasm" --json > "$tmp/ring.json" python3 -c 'import json,sys; v=json.load(open(sys.argv[1])); c=[r for r in v["routes"] if r["route"]=="cutrank"][0]; assert c["applies"] and c["size"]["widest_cut"]==2, c; assert v["cheapest"]["counts"]["route"]=="cutrank", v["cheapest"]' "$tmp/ring.json" echo "shortcuts: ok" printf '%s\n' \ '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18"}}' \ '{"jsonrpc":"2.0","method":"notifications/initialized"}' \ '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' \ '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"run_quantum_circuit","arguments":{"qasm":"OPENQASM 3.0; qubit[2] q; h q[0]; cx q[0], q[1];","observables":["Z0 Z1"]}}}' \ > "$tmp/mcp.in" "$W" mcp < "$tmp/mcp.in" > "$tmp/mcp.out" 2> /dev/null python3 - "$tmp/mcp.out" <<'EOF' import json, sys lines = [json.loads(l) for l in open(sys.argv[1])] assert [m["id"] for m in lines] == [1, 2, 3], lines assert lines[0]["result"]["serverInfo"]["name"] == "wai-quantum" names = [t["name"] for t in lines[1]["result"]["tools"]] assert {"run_quantum_circuit", "critique_qasm", "check_equivalent", "improve_qasm", "classical_shortcuts"} <= set(names), names job = lines[2]["result"]["structuredContent"] assert job["result"]["expectations"][0]["value"] == 1.0, job EOF echo "mcp: ok" "$W" lab list > "$tmp/lab-list" has "$tmp/lab-list" "^ghz " "$W" lab receipt ghz -n 3 > "$tmp/lab-receipt" 2> /dev/null "$W" verify "$tmp/lab-receipt" > "$tmp/lab-verify" has "$tmp/lab-verify" "^signature VALID" has "$tmp/lab-verify" "^signer $(cat "$tmp/key")" echo "lab: ok" if [ -n "$SVC" ]; then "$W" submit "$tmp/ghz.qasm" --shots 500 --service "$SVC" --json > "$tmp/svc.json" "$W" verify "$tmp/svc.json" > "$tmp/svc-verify" has "$tmp/svc-verify" "^signature VALID" echo "submit: ok, the service's receipt verifies here" fi echo "smoke: every check held"