open-standards/wai/wai-quantum-cli/smoke.sh
Transaction Science 022b02f58e wai-quantum-cli, wai-quantum-service: the engine's components listed on the command line, both MCP servers and the service
`wai-quantum components` (`--json` with each descriptor), the MCP tool
list_components on both servers (its answer tools.v1.json#/$defs/components),
and the service's GET /v1 and quantum_service_info list every method, pass,
noise channel and format with its version, origin and descriptor digest:
the built-ins alone, nothing loaded from a request. The tool lists' tests,
the smoke checks and the second schema checker take the new tool; the agent
docs are blessed from both servers; the command's summary is translated;
the READMEs and the changelog say what the extension points are.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-31 23:30:48 -04:00

505 lines
29 KiB
Shell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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
# The binary as an absolute path, for the steps below that run from another directory.
case "$1" in
*/*) W="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" ;;
*) W="$1" ;;
esac
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 \[Q103\]"
"$W" lint --json "$tmp/bad.qasm" > "$tmp/lint-bad.json" || true
python3 -c 'import json,sys; v=json.load(open(sys.argv[1])); assert (v["code"], v["line"], v["column"], v["length"]) == ("Q103", 3, 1, 3), v' "$tmp/lint-bad.json"
"$W" diagnostics > "$tmp/codes"
has "$tmp/codes" "Q103 refused"
"$W" diagnostics --json > "$tmp/codes.json"
python3 -c 'import json,sys; t=json.load(open(sys.argv[1])); assert any(c["code"]=="Q103" and c["outcome"]=="refused" for c in t["codes"]), t' "$tmp/codes.json"
echo "lint: ok, with codes"
"$W" components > "$tmp/components"
has "$tmp/components" "density_matrix"
"$W" components --json > "$tmp/components.json"
python3 -c 'import json,sys; c=json.load(open(sys.argv[1])); names=lambda k: [x["name"] for x in c[k]]; assert c["format"]=="wai.quantum.components/1" and c["registered"]==0, c; assert names("front_ends")==["qasm","qir","jeff"] and "exact" in names("methods") and "approximate" in names("passes") and names("channels")[0]=="depolarizing_1q", c; assert all(x["origin"]=="built-in" and len(x["digest"])==64 for k in ("methods","passes","channels","front_ends") for x in c[k]), c' "$tmp/components.json"
echo "components: ok, every built-in with its identity"
"$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"]
assert r["engine"]["name"] == "wai-quantum" and r["schema"] == "wai.quantum.job-result/1", r
EOF
# The versions it reports: its own, the engine's (the one its results name),
# each schema's, and where the policy is.
"$W" version --json > "$tmp/version.json"
python3 - "$tmp/version.json" "$tmp/job.json" <<'EOF'
import json, sys
v = json.load(open(sys.argv[1])); r = json.load(open(sys.argv[2]))["result"]
assert v["schema"] == "wai.quantum.versions/1" and v["host"]["name"] == "wai-quantum-cli", v
assert v["engine"] == r["engine"], (v["engine"], r["engine"])
assert v["schemas"]["job_result"] == r["schema"] and v["policy"].endswith("/VERSIONING.md"), v
EOF
echo "version: ok"
"$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"
"$W" draw "$tmp/ghz.qasm" --svg > "$tmp/ghz.svg"
has "$tmp/ghz.svg" "^<svg"
"$W" draw "$tmp/ghz.qasm" --latex > "$tmp/ghz.tex"
has "$tmp/ghz.tex" 'begin{tikzpicture}'
"$W" draw "$tmp/ghz.qasm" --describe > "$tmp/ghz.txt"
has "$tmp/ghz.txt" "Column 2: CNOT, control qubit 0, target qubit 1"
echo "draw: ok, as text, SVG, LaTeX and words"
# The debugger: a position's state, the branches, and the adapter's first answer.
"$W" debug "$tmp/ghz.qasm" --to 3 > "$tmp/debug"
has "$tmp/debug" "^position 3 of 6; next: measure q0 into bit 0"
has "$tmp/debug" "^entangled across {q0}: 1.000000 bits, Schmidt rank 2"
"$W" debug "$tmp/ghz.qasm" --branches > "$tmp/branches"
has "$tmp/branches" "^branches 1"
msg='{"seq":1,"type":"request","command":"initialize","arguments":{}}'
printf 'Content-Length: %d\r\n\r\n%s' "${#msg}" "$msg" | "$W" dap > "$tmp/dap"
has "$tmp/dap" '"supportsStepBack":true'
echo "debug, dap: 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"
# Other formats: OpenQASM written as QIR and jeff, each read back and checked,
# every verb reading them, and a module its profile forbids refused on its line.
"$W" convert "$tmp/twice.qasm" --to qir > "$tmp/twice.ll" 2> "$tmp/convert"
has "$tmp/convert" "^check: equivalent (tableau)"
has "$tmp/twice.ll" '"qir_profiles"="base_profile"'
"$W" convert "$tmp/twice.ll" --to jeff -o "$tmp/twice.jeff" 2> "$tmp/convert"
has "$tmp/convert" "^check: equivalent (tableau)"
"$W" equivalent "$tmp/twice.jeff" "$tmp/twice.qasm" > "$tmp/same" 2>/dev/null
has "$tmp/same" "^equivalent"
"$W" run "$tmp/twice.ll" --shots 64 --json > "$tmp/fromqir.json"
"$W" verify "$tmp/fromqir.json" > /dev/null || fail "a run of a QIR module did not verify"
printf 'define i64 @main() #0 {\nentry:\n call void @__quantum__qis__mz__body(ptr null, ptr writeonly null)\n call void @__quantum__qis__x__body(ptr null)\n ret i64 0\n}\nattributes #0 = { "entry_point" "qir_profiles"="base_profile" "required_num_qubits"="1" "required_num_results"="1" }\n' > "$tmp/forbidden.ll"
if "$W" convert "$tmp/forbidden.ll" --to qasm > /dev/null 2> "$tmp/refused"; then fail "a gate after a measurement under the base profile was read"; fi
has "$tmp/refused" "line 4: the base profile forbids a gate on qubit 0 after its measurement \\[Q704\\]"
echo "convert: QIR and jeff, written, read back and checked; a profile's refusal on its line: 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"
# compile: Clifford+T within the budget, every pass recorded, the certificate
# signed and checked by verify, and a run that compiles first goes bit-exact.
printf 'OPENQASM 3.0;\nqubit[2] q;\nh q[0];\nrz(0.3) q[0];\ncx q[0], q[1];\nry(1.1) q[1];\n' > "$tmp/angles.qasm"
"$W" compile "$tmp/angles.qasm" --epsilon 1e-4 --certificate "$tmp/cert.json" > "$tmp/compiled.qasm" 2> "$tmp/compile"
has "$tmp/compile" "^approximate"
has "$tmp/compile" "^epsilon budget 1e-4, bound"
has "$tmp/compile" "^certificate verifies"
if grep -q "rz(" "$tmp/compiled.qasm"; then fail "a rotation is left in the Clifford+T output"; fi
python3 -c 'import json,sys; b=json.load(open(sys.argv[1])); c=b["result"]["certificate"]; assert c["verdict"]=="approximate" and 0 < c["epsilon"]["bound"] <= 1e-4 and c["whole"]["distance"] <= c["epsilon"]["bound"], c["epsilon"]' "$tmp/cert.json"
"$W" verify "$tmp/cert.json" > "$tmp/cert-verify"
has "$tmp/cert-verify" "^signature VALID"
"$W" run "$tmp/angles.qasm" --compile 1e-4 --shots 200 > "$tmp/compiled-run" 2> /dev/null
has "$tmp/compiled-run" "^accuracy bit-exact"
has "$tmp/compiled-run" "^compiled clifford_t at level 1: within"
echo "compile: ok"
# estimate: a program's counts (a gate under three controls through an
# ancilla, a rotation at its word's T count), the frontier, the seals checked
# and re-run by verify, the counts exported and estimated again, and lab
# estimate still answering as it did.
printf 'OPENQASM 3.0;\nqubit[4] q;\nh q;\nctrl(3) @ x q[0], q[1], q[2], q[3];\nrz(0.3) q[0];\nt q[1];\n' > "$tmp/est.qasm"
"$W" estimate "$tmp/est.qasm" --budget 1e-3 > "$tmp/estimate"
has "$tmp/estimate" "^counts 5 logical qubits (1 ancilla), 4 measurements, 1 T, 3 Toffolis, 1 rotations"
has "$tmp/estimate" "^estimate ns-e4, surface code (fit: exact matching), d = "
has "$tmp/estimate" "^receipts .* they verify and re-run here"
"$W" estimate "$tmp/est.qasm" --json --demo-key > "$tmp/est.json"
python3 -c 'import json,sys; b=json.load(open(sys.argv[1])); r=b["result"]; assert r["format"]=="wai.quantum.estimate/1" and r["counts"]["ladders"]==1 and r["estimate"]["receipt"]["kind"]=="quantum-resource" and len(r["frontier"])>=1 and r["epsilon"]["bound"]<=r["epsilon"]["synthesis"], r["counts"]' "$tmp/est.json"
"$W" verify "$tmp/est.json" > "$tmp/est-verify"
has "$tmp/est-verify" "^signature VALID"
has "$tmp/est-verify" "^reproduced the request re-run here gives every count and figure"
"$W" estimate "$tmp/est.qasm" --export counts > "$tmp/counts.json" 2> /dev/null
python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d=={"numQubits":5,"tCount":1,"rotationCount":1,"rotationDepth":1,"cczCount":3,"ccixCount":0,"measurementCount":4}, d' "$tmp/counts.json"
"$W" estimate --counts "$tmp/counts.json" > "$tmp/est-counts"
has "$tmp/est-counts" "^program counts, digest"
"$W" estimate "$tmp/est.qasm" --export routine > "$tmp/routine.json" 2> /dev/null
"$W" estimate --routine "$tmp/routine.json" --qubit all > "$tmp/est-all"
has "$tmp/est-all" "^meas-e6 "
"$W" lab estimate factoring --qubit ns-e4 --json > "$tmp/lab-est"
python3 -c 'import json,sys; r=json.load(open(sys.argv[1])); assert r[0]["distance"]==13 and r[0]["factories"]==18, r' "$tmp/lab-est"
echo "estimate: 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", "compile_qasm", "estimate_resources"} <= set(names), names
job = lines[2]["result"]["structuredContent"]
assert job["result"]["expectations"][0]["value"] == 1.0, job
EOF
echo "mcp: ok"
# A host that draws views: each tool names its view, and the view's page reads, within its limit.
printf '%s\n' \
'{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{"extensions":{"io.modelcontextprotocol/ui":{"mimeTypes":["text/html;profile=mcp-app"]}}}}}' \
'{"jsonrpc":"2.0","id":2,"method":"tools/list"}' \
'{"jsonrpc":"2.0","id":3,"method":"resources/read","params":{"uri":"ui://wai-quantum/result"}}' \
> "$tmp/mcp-views.in"
"$W" mcp < "$tmp/mcp-views.in" > "$tmp/mcp-views.out" 2> /dev/null
python3 - "$tmp/mcp-views.out" <<'PY'
import json, sys
r = [json.loads(l) for l in open(sys.argv[1])]
tools = {t["name"]: t for t in r[1]["result"]["tools"]}
assert tools["run_quantum_circuit"]["_meta"]["ui"]["resourceUri"] == "ui://wai-quantum/result", tools["run_quantum_circuit"]
c = r[2]["result"]["contents"][0]
assert c["mimeType"] == "text/html;profile=mcp-app" and len(c["text"].encode()) <= 1 << 20 and 'content="result"' in c["text"], c["mimeType"]
PY
echo "mcp views: ok"
# The model harness, the task set's reference programs as a scripted model's answers: every task solved.
python3 -c 'import json,sys; t=json.load(open(sys.argv[1]))["cases"]; print(json.dumps({c["name"]: "```qasm\n" + c["qasm"] + "```" for c in t}))' ../quantum-conformance/eval/tasks.json > "$tmp/eval-answers.json"
"$W" eval run --tasks ../quantum-conformance/eval/tasks.json --scripted "$tmp/eval-answers.json" --out "$tmp/eval-report.json" 2> /dev/null
python3 -c 'import json,sys; s=json.load(open(sys.argv[1]))["summary"]; assert s["tasks"] >= 12 and s["solved"] == s["tasks"] == s["valid"], s' "$tmp/eval-report.json"
echo "eval: ok"
# run --intent: the engine's verdict, sealed by the receipt; the exit status
# says whether the intent holds. repair: the fix on the flagged line alone, and
# a proposal off it rejected.
printf '{"000": 0.5, "111": 0.5}\n' > "$tmp/ghz-dist.json"
"$W" run "$tmp/ghz.qasm" --intent "$tmp/ghz-dist.json" --json > "$tmp/intent.json" 2> /dev/null
python3 -c 'import json,sys; j=json.load(open(sys.argv[1])); v=j["result"]["verdict"]; assert (v["level"], v["holds"]) == ("proof", True), v' "$tmp/intent.json"
"$W" verify "$tmp/intent.json" > "$tmp/intent-verify"
has "$tmp/intent-verify" "^signature VALID"
printf '{"000": 1.0}\n' > "$tmp/wrong-dist.json"
if "$W" run "$tmp/ghz.qasm" --intent "$tmp/wrong-dist.json" > "$tmp/intent-fails" 2> /dev/null; then fail "a failing intent exited 0"; fi
has "$tmp/intent-fails" "^verdict proof: Checked as proof"
"$W" run "$tmp/ghz.qasm" --intent "$tmp/twice.qasm" > "$tmp/intent-shape" 2> /dev/null || true
has "$tmp/intent-shape" "^verdict proof"
printf 'OPENQASM 3.0;\nqubit[2] q\nh q[0];\n' > "$tmp/broken.qasm"
"$W" repair "$tmp/broken.qasm" > "$tmp/repaired.qasm" 2> "$tmp/repair"
has "$tmp/repair" "^repaired Q004"
printf 'OPENQASM 3.0;\nqubit[2] q;\nh q[0];\n' | cmp -s - "$tmp/repaired.qasm" || fail "repair did not add the one ;"
printf 'OPENQASM 3.1;\nqubit[2] q;\nh q[0];\n' > "$tmp/rewrite.qasm"
set +e; "$W" repair "$tmp/broken.qasm" --proposed "$tmp/rewrite.qasm" > /dev/null 2> "$tmp/repair-rejected"; rc=$?; set -e
[ "$rc" = 2 ] || fail "a proposal off the flagged lines exited $rc, not 2"
has "$tmp/repair-rejected" "\[J021\]"
echo "intent, repair: ok"
printf 'OPENQASM 3.0;qubit[2]q;h q[0];cx q[0],q[1];\n' > "$tmp/messy.qasm"
printf 'OPENQASM 3.0;\nqubit[2] q;\nh q[0];\ncx q[0], q[1];\n' > "$tmp/want.qasm"
"$W" fmt "$tmp/messy.qasm" > "$tmp/tidy.qasm"
cmp -s "$tmp/tidy.qasm" "$tmp/want.qasm" || { diff "$tmp/want.qasm" "$tmp/tidy.qasm" >&2 || true; fail "fmt did not give the one layout"; }
"$W" fmt --check "$tmp/tidy.qasm" > "$tmp/fmt-check" || fail "fmt --check refused a formatted program"
if "$W" fmt --check "$tmp/messy.qasm" > "$tmp/fmt-check"; then fail "fmt --check passed an unformatted program"; fi
has "$tmp/fmt-check" "messy.qasm"
printf 'gate g a {\n h a;\n' > "$tmp/open.qasm"
if "$W" fmt "$tmp/open.qasm" > /dev/null 2> "$tmp/fmt-err"; then fail "fmt formatted a program whose brace is not closed"; fi
has "$tmp/fmt-err" 'open.qasm:1: `{` is not closed'
echo "fmt: ok"
# The language server answers initialize, and exits cleanly after shutdown.
python3 - "$W" <<'PY'
import json, subprocess, sys
msgs = [
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"capabilities": {}}},
{"jsonrpc": "2.0", "id": 2, "method": "shutdown"},
{"jsonrpc": "2.0", "method": "exit"},
]
data = b"".join(b"Content-Length: %d\r\n\r\n%s" % (len(b), b) for b in (json.dumps(m).encode() for m in msgs))
p = subprocess.run([sys.argv[1], "lsp", "--demo-key"], input=data, capture_output=True, timeout=60)
assert p.returncode == 0, p
head, rest = p.stdout.split(b"\r\n\r\n", 1)
first = json.loads(rest[: int(head.split(b":")[1])])
assert first["id"] == 1 and first["result"]["capabilities"]["hoverProvider"] is True, first
PY
echo "lsp: 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"
# Error correction: a code's certified distance sealed and verified, a decode at
# code capacity judged, a circuit-level decode, and lab qec as it was; a
# mitigated run carries its mitigation.
"$W" qec code color:5 --json --demo-key > "$tmp/qec-code.json" 2> /dev/null
python3 -c 'import json,sys; v=json.load(open(sys.argv[1])); c=v["result"]["certificate"]; assert c["distance"]==5 and c["x"]["witness"], c' "$tmp/qec-code.json"
"$W" verify "$tmp/qec-code.json" > "$tmp/qec-verify"
has "$tmp/qec-verify" "VALID"
"$W" qec decode --code surface:3 --error 4 --demo-key > "$tmp/qec-decode" 2> /dev/null
has "$tmp/qec-decode" "the logical state is unharmed"
"$W" qec decode --memory 3,3,0.004 --shots 2000 --decoder correlated --demo-key > "$tmp/qec-shots" 2> /dev/null
has "$tmp/qec-shots" "of 2000 shots"
"$W" lab qec -d 3 --p 0.003 --shots 2000 > "$tmp/lab-qec"
has "$tmp/lab-qec" "^failures"
"$W" run "$tmp/ghz.qasm" -o "Z0 Z1" --noise depolarizing_2q=0.02 --mitigate zne --demo-key > "$tmp/mitigated" 2> /dev/null
has "$tmp/mitigated" "^mitigation zne"
echo "qec and mitigation: ok"
# Pulse: a program's schedule drawn, its run as a job (the error bounded and
# stated), its receipt verified, the job checked by running it again, and a
# tolerance the integrator cannot meet refused with its code.
cat > "$tmp/xm.qasm" <<'EOF'
OPENQASM 3.0;
defcalgrammar "openpulse";
cal {
extern port d0;
extern port a0;
frame q0 = newframe(d0, 5.0e9, 0);
frame c0 = newframe(a0, 5.0e9, 0);
}
defcal x $0 { play(q0, gaussian(0.4, 64dt, 16dt)); }
defcal measure $0 -> bit { return capture_v2(c0, 100dt); }
bit c;
x $0;
c = measure $0;
EOF
"$W" pulse schedule "$tmp/xm.qasm" --demo-key > "$tmp/pulse-schedule" 2> /dev/null
has "$tmp/pulse-schedule" "^schedule 164 samples"
has "$tmp/pulse-schedule" "call x [$]0 samples 0–64"
"$W" run "$tmp/xm.qasm" --method pulse --shots 200 --json --demo-key > "$tmp/pulse-run.json" 2> /dev/null
python3 -c 'import json,sys; r=json.load(open(sys.argv[1]))["result"]; a=r["accuracy"]; assert r["method"]=="pulse" and a["class"]=="bounded" and a["bound"] <= 1e-6 and r["pulse"]["captures"][0]["bit"]=="c" and sum(r["counts"].values())==200, r' "$tmp/pulse-run.json"
"$W" verify "$tmp/pulse-run.json" > "$tmp/pulse-verify"
has "$tmp/pulse-verify" "VALID"
"$W" pulse check "$tmp/pulse-run.json" --demo-key > "$tmp/pulse-check" 2> /dev/null
has "$tmp/pulse-check" "^check VERIFIED"
if "$W" run "$tmp/xm.qasm" --method pulse --pulse '{"tolerance": 1e-15}' --demo-key > "$tmp/pulse-tight" 2>&1; then fail "a tolerance past double precision ran"; fi
has "$tmp/pulse-tight" "\[J041\]"
echo "pulse: ok"
# The front door: a project made, its own test run as made, AGENTS.md left as
# it is by a rerun, the MCP entry, and the server's resources and prompts.
"$W" new "$tmp/proj" --template grover > "$tmp/new"
has "$tmp/new" "next: sh "
WAI_QUANTUM="$W" sh "$tmp/proj/test.sh" > "$tmp/proj-test" 2>&1
has "$tmp/proj-test" "both receipts verify"
"$W" verify "$tmp/proj/receipts/grover.intent.json" > "$tmp/proj-verify"
has "$tmp/proj-verify" "^signature VALID"
"$W" setup-agent "$tmp/proj" > "$tmp/agents"
has "$tmp/agents" "unchanged"
"$W" mcp config > "$tmp/mcp-config.json"
python3 -c 'import json,sys; c=json.load(open(sys.argv[1])); assert c["mcpServers"]["wai-quantum"]=={"command":"wai-quantum","args":["mcp"]}, c' "$tmp/mcp-config.json"
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"resources/list"}' '{"jsonrpc":"2.0","id":2,"method":"prompts/list"}' > "$tmp/mcp2.in"
"$W" mcp < "$tmp/mcp2.in" > "$tmp/mcp2.out" 2> /dev/null
python3 - "$tmp/mcp2.out" <<'EOF'
import json, sys
r = [json.loads(l) for l in open(sys.argv[1])]
uris = [x["uri"] for x in r[0]["result"]["resources"]]
assert "wai-quantum://docs/language" in uris and "wai-quantum://docs/diagnostics" in uris, uris
assert len(r[1]["result"]["prompts"]) == 3, r[1]
EOF
echo "new, test, setup-agent, mcp config, resources and prompts: ok"
# Device targets: the built-in ones listed, a snapshot kept under a name, and
# a run on one placed and simulated as the device would, the target's hash in
# the receipt.
"$W" targets list > "$tmp/targets"
has "$tmp/targets" "synthetic-heavy-hex-27"
"$W" targets show synthetic-line-5 --document > "$tmp/line5.json"
"$W" targets import "$tmp/line5.json" --name my-line > "$tmp/import"
has "$tmp/import" "kept my-line (5 qubits, 4 pairs)"
"$W" targets list > "$tmp/targets2"
has "$tmp/targets2" "^ my-line"
"$W" run "$tmp/ghz.qasm" --target my-line --shots 500 --json > "$tmp/device.json"
python3 - "$tmp/device.json" <<'PY'
import json, sys
j = json.load(open(sys.argv[1])); r = j["result"]
assert j["method"] == "density_matrix" and j["request"]["target"]["name"] == "my-line", j["method"]
assert len(r["target"]["hash"]) == 64 and sum(r["counts"].values()) == 500, r["target"]
assert 0 < r["ideal"]["total_variation_distance"] < 0.3, r["ideal"]
PY
"$W" verify "$tmp/device.json" > "$tmp/device-verify"
has "$tmp/device-verify" "^signature VALID"
"$W" run "$tmp/ghz.qasm" --target synthetic-heavy-hex-27 --shots 200 > "$tmp/device.txt"
has "$tmp/device.txt" "^target synthetic-heavy-hex-27"
has "$tmp/device.txt" "^placed on"
if "$W" run "$tmp/ghz.qasm" --target no-such-device > "$tmp/device-bad" 2>&1; then fail "a run on an unknown target ran"; fi
has "$tmp/device-bad" "no target"
echo "targets: list, show, import, run --target and its receipt: ok"
# A set and a sweep, run here: one result per item, one receipt binding them.
cat > "$tmp/rot.qasm" <<'EOF'
OPENQASM 3.0;
input float theta;
qubit q;
rx(theta) q;
EOF
"$W" run "$tmp/ghz.qasm" --program "$tmp/ghz.qasm" --shots 50 --json > "$tmp/set.json"
"$W" verify "$tmp/set.json" > "$tmp/set-verify"
has "$tmp/set-verify" "^signature VALID"
has "$tmp/set-verify" "its root over 2 items"
"$W" run "$tmp/rot.qasm" --sweep theta=0,0.5,1 -o Z0 > "$tmp/sweep.txt"
has "$tmp/sweep.txt" '^set 3 items, 3 done, 0 failed'
has "$tmp/sweep.txt" '{"theta":0.5}'
has "$tmp/sweep.txt" "^receipt verifies, every item sealed"
"$W" plan "$tmp/rot.qasm" --sweep theta=0,1 -o Z0 > "$tmp/sweep-plan.txt"
has "$tmp/sweep-plan.txt" "^set 2 items"
echo "sets and sweeps: run here, each item sealed, one receipt over them: ok"
# The variational and algorithm library: a job's parameter bound, a gradient
# with its bound, an optimisation whose chain and re-run verify, a VQE beside
# the exact ground energy, QAOA beside the maximum cut, a program built,
# checked and run, and a refusal with its code.
cat > "$tmp/ansatz.qasm" <<'EOF'
OPENQASM 3.0;
input float t;
qubit[2] q;
h q[0];
crx(t) q[0], q[1];
EOF
"$W" run "$tmp/ansatz.qasm" --param t=0.4 -o Z1 > "$tmp/param.txt"
has "$tmp/param.txt" "^⟨Z1⟩ 0.96053049"
"$W" gradient "$tmp/ansatz.qasm" --param t=0.4 --term Z1 > "$tmp/grad.txt"
has "$tmp/grad.txt" "^∂/∂t -0.19470917"
has "$tmp/grad.txt" "^method adjoint"
has "$tmp/grad.txt" "^receipt verifies"
"$W" gradient "$tmp/ansatz.qasm" --param t=0.4 --term Z1 --gradient parameter_shift > "$tmp/grad-shift.txt"
has "$tmp/grad-shift.txt" "^∂/∂t -0.19470917"
"$W" optimize "$tmp/ansatz.qasm" --param t=0.4 --term Z1 --optimizer spsa --steps 20 --json > "$tmp/opt.json"
"$W" verify "$tmp/opt.json" > "$tmp/opt-verify"
has "$tmp/opt-verify" "^signature VALID"
has "$tmp/opt-verify" "^chain every step a link from the request: yes"
has "$tmp/opt-verify" "^run again the same bytes: yes"
"$W" vqe --term "X0 X1" --term "Y0 Y1" --term "Z0 Z1" --layers 2 --steps 50 > "$tmp/vqe.txt"
has "$tmp/vqe.txt" "^reference ground energy -3.000000000000 by exact diagonalisation"
printf '{"nodes": 4, "edges": [[0, 1], [1, 2], [2, 3], [3, 0]]}\n' > "$tmp/ring.json"
"$W" qaoa --graph "$tmp/ring.json" --layers 2 --steps 60 > "$tmp/qaoa.txt"
has "$tmp/qaoa.txt" "^max cut 4"
"$W" build adder --bits 3 --a 5 --b 6 > "$tmp/add.qasm" 2> "$tmp/build.err"
has "$tmp/build.err" "^check equivalent (exact)"
"$W" run "$tmp/add.qasm" --shots 8 > "$tmp/add.txt"
has "$tmp/add.txt" "^ 1011 8 1.0000"
if "$W" gradient "$tmp/ansatz.qasm" --term Z1 > "$tmp/grad-bad" 2>&1; then fail "a gradient ran with a parameter left without a value"; fi
has "$tmp/grad-bad" "\[Q114\] \[J050\]"
echo "parameters, gradients, optimisation, vqe, qaoa and build: ok"
# The course: a lesson started, its starter checked and not passed, the
# solution passed and kept on this machine, and the same in Chinese.
(cd "$tmp" && "$W" learn start bell > "$tmp/learn-start")
has "$tmp/learn-start" "wrote bell.qasm"
if "$W" learn check bell "$tmp/bell.qasm" > "$tmp/learn-fail"; then fail "the starter passed its own exercise"; fi
has "$tmp/learn-fail" "^passed not yet"
has "$tmp/learn-fail" "00: your program gives 1, the exercise asks for 0.5"
printf 'OPENQASM 3.0;\nqubit[2] q;\nbit[2] c;\nh q[0];\ncx q[0], q[1];\nc = measure q;\n' > "$tmp/bell.qasm"
"$W" learn check bell "$tmp/bell.qasm" > "$tmp/learn-pass"
has "$tmp/learn-pass" "^passed yes"
python3 -c 'import json,sys; p=json.load(open(sys.argv[1])); assert p["lessons"]["bell"]["passed"] is True and p["lessons"]["bell"]["checks"] == 2, p' "$XDG_CONFIG_HOME/wai/quantum-learn.json"
"$W" learn > "$tmp/learn-list"
has "$tmp/learn-list" "✓ 6. bell"
"$W" learn hint ghz --lang zh-CN > "$tmp/learn-hint"
has "$tmp/learn-hint" "^提示 1/2"
LANG=zh_CN.UTF-8 "$W" learn check bell "$tmp/bell.qasm" > "$tmp/learn-zh"
has "$tmp/learn-zh" "^通过"
LANG=zh_CN.UTF-8 "$W" --help > "$tmp/help-zh"
has "$tmp/help-zh" "量子线路课程"
"$W" docs --lang zh-CN > "$tmp/docs-zh"
has "$tmp/docs-zh" "可离线使用"
echo "learn: started, checked, passed, kept here, and in Chinese: 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"
# A set over the service, its status followed; a dry run; the task commands.
"$W" submit "$tmp/rot.qasm" --sweep theta=0,0.5 -o Z0 --service "$SVC" --json > "$tmp/svc-set.json" 2> "$tmp/svc-set.err"
has "$tmp/svc-set.err" ": done$"
"$W" verify "$tmp/svc-set.json" > "$tmp/svc-set-verify"
has "$tmp/svc-set-verify" "^signature VALID"
"$W" submit "$tmp/ghz.qasm" --shots 10 --dry-run --service "$SVC" > "$tmp/svc-dry.txt"
has "$tmp/svc-dry.txt" "^would run yes, now"
has "$tmp/svc-dry.txt" "^method stabilizer"
printf '{"qasm": "OPENQASM 3.0; qubit q; bit c; h q; c = measure q;", "shots": 20}' > "$tmp/task.json"
(
cd "$tmp"
"$W" task acquire --service "$SVC" > lease.out
id=$("$W" task start task.json --service "$SVC")
"$W" task wait "$id" --service "$SVC" > wait.out 2> wait.err
"$W" task result "$id" --service "$SVC" > result.json
"$W" task release --service "$SVC" > release.out
)
has "$tmp/wait.out" "^done$"
"$W" verify "$tmp/result.json" > "$tmp/task-verify"
has "$tmp/task-verify" "^signature VALID"
has "$tmp/release.out" "^released: 0 task(s) stopped"
echo "submit sets, dry runs and the task commands: ok"
fi
echo "smoke: every check held"