All checks were successful
standards workspaces build + test / which workspaces this change touches (pull_request) Successful in 5s
wai-audit collector and player integration / does this change touch it (pull_request) Successful in 10s
WAI breaking changes and the conformance runner / WAI breaking · does this change touch WAI (pull_request) Successful in 8s
WAI operation catalogue / does this change touch it (pull_request) Successful in 6s
WAI conformance / does this change touch it (pull_request) Successful in 6s
wai-quantum command line / does this change touch it (pull_request) Successful in 5s
WAI energy receipts / does this change touch it (pull_request) Successful in 9s
wai-quantum contract / does this change touch it (pull_request) Successful in 7s
WAI examples / WAI examples · does this change touch them (pull_request) Successful in 9s
wai-quantum CUDA member / does this change touch it (pull_request) Successful in 5s
wai-quantum signal processor / does this change touch it (pull_request) Successful in 6s
wai-quantum editors / does this change touch it (pull_request) Successful in 6s
wai-quantum docs, course and locales / does this change touch it (pull_request) Successful in 9s
wai-quantum dataflow member / does this change touch it (pull_request) Successful in 12s
wai-quantum resource estimation / does this change touch it (pull_request) Successful in 6s
wai-quantum other formats / does this change touch it (pull_request) Successful in 5s
wai-quantum FPGA member / does this change touch it (pull_request) Successful in 8s
wai-quantum HIP member / does this change touch it (pull_request) Successful in 8s
wai-quantum for JavaScript / does this change touch it (pull_request) Successful in 6s
wai-quantum OpenQASM reader / does this change touch it (pull_request) Successful in 6s
wai-quantum OpenCL member / does this change touch it (pull_request) Successful in 6s
wai-quantum npu-cores member / does this change touch it (pull_request) Successful in 9s
wai-quantum Metal member / does this change touch it (pull_request) Successful in 10s
wai-quantum neural-processor member / does this change touch it (pull_request) Successful in 9s
wai-quantum on every processor / emulated · aarch64-unknown-linux-gnu (pull_request) Successful in 50s
wai-quantum on every processor / emulated · armv7-unknown-linux-gnueabihf (pull_request) Successful in 1m31s
wai-quantum on every processor / emulated · riscv64gc-unknown-linux-gnu (pull_request) Successful in 1m24s
wai-quantum pulse and dynamics / does this change touch it (pull_request) Successful in 5s
wai-quantum for Python / does this change touch it (pull_request) Successful in 5s
wai-quantum error correction and mitigation / does this change touch it (pull_request) Successful in 5s
wai-quantum-qpu / does this change touch it (pull_request) Successful in 5s
wai-quantum extension points / does this change touch it (pull_request) Successful in 5s
wai-quantum service / does this change touch it (pull_request) Successful in 5s
wai-quantum matrix-extension member / does this change touch it (pull_request) Successful in 5s
wai-quantum studio and desktop / does this change touch it (pull_request) Successful in 5s
wai-quantum tensor-engine member / does this change touch it (pull_request) Successful in 5s
wai-quantum portable tensor program / does this change touch it (pull_request) Successful in 5s
wai-quantum variational and algorithm library / does this change touch it (pull_request) Successful in 6s
wai-quantum CPU vector units / does this change touch it (pull_request) Successful in 5s
wai-quantum verdicts and repairs / does this change touch it (pull_request) Successful in 6s
wai-quantum views in agent hosts / does this change touch it (pull_request) Successful in 6s
wai-quantum WebGPU member / does this change touch it (pull_request) Successful in 5s
wai-quantum on every processor / emulated · loongarch64-unknown-linux-gnu (pull_request) Successful in 4m15s
wai-sink-android native sink library / does this change touch it (pull_request) Successful in 6s
WAI Studio / does this change touch it (pull_request) Successful in 5s
wai-sink-swift native sink package / does this change touch it (pull_request) Successful in 12s
wai-web reach builds / wai-web reach · does this change touch it (pull_request) Successful in 5s
wai-web wasm32 / does this change touch it (pull_request) Successful in 6s
wai-quantum on every processor / emulated · powerpc64-unknown-linux-gnu (pull_request) Successful in 4m43s
wai-quantum on every processor / emulated · sparc64-unknown-linux-gnu (pull_request) Successful in 3m13s
wai-quantum on every processor / emulated · s390x-unknown-linux-gnu (pull_request) Successful in 6m53s
wai-quantum on every processor / emulated · i686-unknown-linux-gnu (pull_request) Successful in 6m8s
wai-quantum on every processor / emulated · powerpc64le-unknown-linux-gnu (pull_request) Successful in 9m13s
WAI conformance / fast integer kernels, every x86_64 kernel set (AVX-512 silicon) (pull_request) Successful in 3m53s
wai-quantum HIP member / member · HIP (framework-128gb) (pull_request) Successful in 1m28s
wai-quantum OpenCL member / member · OpenCL GPU (framework-128gb) (pull_request) Successful in 33s
wai-quantum npu-cores member / member · npu-cores, neural processor (framework-128gb silicon) (pull_request) Successful in 1m51s
wai-quantum portable tensor program / tensor program · integrated GPU (framework-128gb) (pull_request) Successful in 17s
wai-quantum CPU vector units / member · vector units, avx2 and avx512 (framework-128gb silicon) (pull_request) Successful in 26s
wai-audit collector and player integration / collector, player integration and the browser end to end · macos (pull_request) Successful in 1m42s
WAI conformance / cross-arch byte-equality · macos (pull_request) Successful in 28s
wai-quantum CUDA member / member · CUDA (thor) (pull_request) Successful in 2m3s
wai-quantum OpenCL member / member · OpenCL GPU and CPU (thor) (pull_request) Successful in 50s
WAI conformance / codec wrappers · fuzz smoke, text decode limits, C entry points, provenance, the semantic path (pull_request) Successful in 1m29s
wai-quantum WebGPU member / member · integrated GPU, Vulkan (framework-128gb) (pull_request) Successful in 9m0s
wai-quantum command line / command line · macos (pull_request) Successful in 2m50s
standards workspaces build + test / macOS energy backends (pull_request) Successful in 12m29s
wai-quantum CUDA member / member · CUDA (jetson-hub) (pull_request) Successful in 2m58s
wai-quantum OpenCL member / member · OpenCL GPU and CPU (jetson-hub) (pull_request) Successful in 1m13s
wai-audit collector and player integration / collector · linux (pull_request) Successful in 1m24s
wai-quantum editors / editors · macos (pull_request) Successful in 3m47s
wai-quantum service / service energy · linux packages (pull_request) Successful in 2m35s
wai-quantum portable tensor program / tensor program · GPUs (jetson-hub) (pull_request) Successful in 37s
wai-quantum dataflow member / member · dataflow device absent (macos) (pull_request) Successful in 45s
WAI breaking changes and the conformance runner / WAI breaking and conform · their tests, and the independent verifiers through wai conform · linux (pull_request) Successful in 3m27s
WAI conformance / cargo-class corpora · macos (pull_request) Successful in 16m11s
WAI breaking changes and the conformance runner / WAI breaking · wire, record and API against main · linux (pull_request) Successful in 4m2s
WAI conformance / quantum core and corpus under wasm32-wasip2 (wasmtime) (pull_request) Successful in 3m23s
wai-quantum OpenCL member / member · OpenCL GPU (macos) (pull_request) Successful in 38s
wai-quantum FPGA member / member · FPGA datapath, simulated (macos) (pull_request) Successful in 2m16s
WAI conformance / cross-arch byte-equality · linux (pull_request) Successful in 1m5s
wai-quantum Metal member / member · Metal (macos) (pull_request) Successful in 38s
WAI conformance / faces from keypoints under wasm32-wasip2 (wasmtime) (pull_request) Successful in 2m10s
wai-quantum pulse and dynamics / the same bits · macos (pull_request) Successful in 1m6s
wai-quantum contract / the policy is linked, and the deprecations page reads (pull_request) Successful in 6s
WAI energy receipts / energy receipts · macos (pull_request) Successful in 9m10s
wai-quantum-qpu / credentials in the keychain (macos) (pull_request) Successful in 30s
WAI operation catalogue / the catalogue and every door · linux (pull_request) Successful in 6m29s
wai-quantum matrix-extension member / member · matrix extension absent (macos) (pull_request) Successful in 14s
wai-quantum command line / command line · linux (pull_request) Successful in 3m6s
wai-quantum CUDA member / member · CUDA absent (linux) (pull_request) Successful in 1m27s
wai-quantum for Python / python · macos (pull_request) Successful in 2m31s
wai-quantum portable tensor program / tensor program · Metal and the arm64 CPU (macos) (pull_request) Successful in 17s
wai-quantum CPU vector units / member · vector unit absent (macos) (pull_request) Successful in 17s
wai-quantum editors / editors · linux (pull_request) Successful in 2m26s
wai-quantum docs, course and locales / the Studio's words in every locale · linux (pull_request) Successful in 9s
wai-quantum neural-processor member / member · neural processor (macos) (pull_request) Successful in 5m53s
wai-quantum service / service · macos (pull_request) Successful in 4m1s
wai-quantum docs, course and locales / the course and the command line's languages · linux (pull_request) Successful in 2m50s
wai-quantum WebGPU member / member · Metal (macos) (pull_request) Successful in 2m40s
WAI examples / WAI examples · the archive, the readiness check, the browser and Apple · macos (pull_request) Successful in 13m47s
wai-quantum studio and desktop / desktop app · macos (pull_request) Successful in 4m46s
wai-quantum WebGPU member / member · browser WebGPU (macos) (pull_request) Successful in 1m49s
wai-quantum contract / schemas and the committed tool lists · linux (pull_request) Successful in 6m55s
repository checks / lockfiles, advisories, tests in CI, workflow hygiene, spec and section references, public text (pull_request) Successful in 1m8s
wai-quantum resource estimation / estimation and calibration · linux, release (pull_request) Successful in 2m39s
wai-quantum FPGA member / member · FPGA simulation absent (linux) (pull_request) Successful in 26s
wai-quantum other formats / the set under wasm32-wasip2 (wasmtime) (pull_request) Successful in 1m27s
wai-quantum dataflow member / member · dataflow device, simulated (pci 1e52:401e) (pull_request) Successful in 3m53s
wai-quantum dataflow member / member · dataflow device, simulated (pci 1e52:b140) (pull_request) Successful in 4m24s
wai-quantum contract / API compatibility · linux (pull_request) Successful in 9m31s
wai-quantum OpenCL member / member · OpenCL absent (linux) (pull_request) Successful in 26s
wai-quantum neural-processor member / member · neural processor absent (linux) (pull_request) Successful in 21s
wai-quantum Metal member / member · Metal absent (linux) (pull_request) Successful in 1m7s
wai-quantum OpenQASM reader / reader and corpus · linux (pull_request) Successful in 1m52s
wai-quantum other formats / readers, writers and the set · linux (pull_request) Successful in 3m35s
wai-quantum OpenQASM reader / corpus under wasm32-wasip2 (wasmtime) (pull_request) Successful in 2m0s
wai-quantum pulse and dynamics / reader, simulator and pulse jobs · linux, release (pull_request) Successful in 1m23s
WAI examples / WAI examples · portable · linux (pull_request) Successful in 11m41s
wai-quantum for JavaScript / javascript · linux (pull_request) Successful in 3m5s
wai-quantum extension points / the registry under wasm32-wasip2 (wasmtime) (pull_request) Successful in 1m5s
wai-quantum pulse and dynamics / reader, simulator and pulse jobs under wasm32-wasip2 (wasmtime) (pull_request) Successful in 2m7s
wai-quantum-qpu / clients against their contracts (linux) (pull_request) Successful in 1m40s
wai-sink-android native sink library / every ABI, the AAR, and the instrumented tests in a headless emulator · macos (pull_request) Successful in 7m39s
wai-quantum matrix-extension member / member · matrix extension, emulated (aarch64 Linux) (pull_request) Successful in 32s
WAI energy receipts / energy receipts · linux (pull_request) Successful in 14m6s
WAI conformance / cargo-class corpora · linux (pull_request) Successful in 17m58s
wai-quantum signal processor / processor and member · signal processor, emulated (pull_request) Successful in 12m0s
wai-quantum error correction and mitigation / codes, decoders, texts and mitigation · linux, release (pull_request) Successful in 2m43s
wai-quantum CPU vector units / member · vector unit, rvv 1024-bit (riscv64, emulated) (pull_request) Successful in 7s
wai-quantum extension points / the registry and the example · linux (pull_request) Successful in 2m19s
wai-quantum for Python / python · linux (pull_request) Successful in 2m55s
wai-quantum CPU vector units / member · vector unit, sve 128-bit (aarch64, emulated) (pull_request) Successful in 14s
wai-quantum WebGPU member / member · GPU, Vulkan (thor) (pull_request) Successful in 24m50s
wai-quantum CPU vector units / member · vector unit, rvv 128-bit (riscv64, emulated) (pull_request) Successful in 18s
wai-quantum portable tensor program / tensor program · CPU, mutants, GPU builds (pull_request) Successful in 45s
wai-quantum CPU vector units / member · vector unit, sve 2048-bit (aarch64, emulated) (pull_request) Successful in 19s
wai-quantum CPU vector units / member · vector unit, avx2 (x86_64 silicon) (pull_request) Successful in 21s
wai-quantum CPU vector units / member · vector unit, sve 512-bit (aarch64, emulated) (pull_request) Successful in 20s
wai-quantum variational and algorithm library / parameters, gradients, optimisers, VQE, QAOA and builders · linux, release (pull_request) Successful in 1m51s
wai-quantum verdicts and repairs / the intent set and the verdict under wasm32-wasip2 (wasmtime) (pull_request) Successful in 1m25s
wai-quantum verdicts and repairs / verdicts, repairs and the intent set · linux (pull_request) Successful in 2m11s
WAI Studio / the catalogue's actions, the unit tests and the core · linux (pull_request) Successful in 53s
wai-quantum service / service · linux (pull_request) Successful in 5m27s
WAI Studio / Studio in Chromium and Firefox · macos (pull_request) Successful in 11m5s
wai-quantum views in agent hosts / views · a scripted host (pull_request) Successful in 3m19s
wai-quantum WebGPU member / member · software Vulkan (linux) (pull_request) Successful in 2m13s
wai-quantum WebGPU member / shader checks · browser build · wasip2 inertness · MSRV (pull_request) Successful in 3m54s
wai-quantum views in agent hosts / views · the page and its engine (pull_request) Successful in 4m1s
wai-web reach builds / wai-web reach builds · the package of record, every output as recorded (pull_request) Successful in 2m22s
wai-quantum WebGPU member / member · GPU, Vulkan (jetson-hub) (pull_request) Successful in 22m0s
wai-sink-swift native sink package / libwai slices, desktop tests, simulator tests · macos (pull_request) Successful in 13m5s
wai-quantum studio and desktop / studio · browser (pull_request) Successful in 8m24s
wai-web reach builds / wai-web reach builds · this tree's wai-web, every rung on its engine line (pull_request) Successful in 5m19s
wai-quantum tensor-engine member / member · tensor engine, the kernel toolchain's simulator (linux) (pull_request) Successful in 9m19s
wai-web wasm32 / wai-web wasm32 build · corpus, menu and writers (pull_request) Successful in 6m2s
wai-quantum studio and desktop / desktop app · linux (pull_request) Successful in 12m5s
WAI Studio / Studio in WebKit · linux (pull_request) Successful in 11m43s
WAI conformance / v2 vocabulary · manifests validate as stated (pull_request) Successful in 18s
standards workspaces build + test / joule-code-rs (joule-code/joule-code-rs, joule-code-rs, linux-arm64, true) (pull_request) Successful in 6m45s
wai-quantum docs, course and locales / every command and snippet in the docs · linux (pull_request) Successful in 40m6s
WAI conformance / each feature of the independent verifiers' steps compiles alone (pull_request) Successful in 10m16s
WAI conformance / delivery telemetry · CMCD and CMSD against an independent library (pull_request) Successful in 11s
WAI conformance / cross-arch byte-equality · linux-arm64 (pull_request) Successful in 30s
WAI conformance / C2PA manifest emission · signed, read back, validated (pull_request) Successful in 2m15s
WAI conformance / cargo-class corpora · linux-arm64 (pull_request) Successful in 26m33s
wai-quantum HIP member / member · HIP absent (linux-arm64) (pull_request) Successful in 1m32s
wai-quantum npu-cores member / member · npu-cores absent (linux-arm64) (pull_request) Successful in 35s
wai-quantum pulse and dynamics / the same bits · linux-arm64 (pull_request) Successful in 2m8s
WAI energy receipts / energy receipts · linux-arm64 (pull_request) Successful in 12m15s
wai-quantum tensor-engine member / member · tensor engine absent (linux-arm64) (pull_request) Successful in 18s
WAI examples / WAI examples · android-app · linux-arm64 (pull_request) Successful in 8m8s
wai-quantum variational and algorithm library / parameters, gradients, optimisers, VQE, QAOA and builders · linux-arm64, release (pull_request) Successful in 1m44s
wai-quantum extension points / the registry and the example · linux-arm64 (pull_request) Successful in 3m58s
wai-sink-android native sink library / the JNI layer and the platform-free half on the host JVM · linux-arm64 (pull_request) Successful in 3m42s
WAI conformance / independent verifiers · claims, JWP, key discovery and integer payloads (Python) (pull_request) Successful in 59m58s
wai-quantum WebGPU member / member · DX12 and Vulkan (cbio-windows) (pull_request) Successful in 12m2s
wai-quantum studio and desktop / desktop app · windows (pull_request) Successful in 10m56s
The page's --checkpoint example was a shell block marked neither runnable nor norun, which the docs check refuses. It now runs: a whole run, the same run stopped by --slice (exit 2) and gone on with, and cmp of the two answers, so the page holds the command line to "the same bytes as a run that never stopped", receipt and all. Co-Authored-By: Claude Opus 5.5 <[email protected]>
226 lines
13 KiB
Markdown
226 lines
13 KiB
Markdown
# Variational algorithms and the algorithm library
|
||
|
||
`engine::variational` and `engine::algorithms` answer five calls, the same on
|
||
every surface: the command line (`wai-quantum gradient`, `optimize`, `vqe`,
|
||
`qaoa`, `build`), both MCP servers (`gradient_qasm`, `optimize_qasm`,
|
||
`vqe_ground_state`, `qaoa_maxcut`, `build_algorithm`), the job service
|
||
(`POST /v1/gradient`, `/v1/optimize`, `/v1/vqe`, `/v1/qaoa`, `/v1/build`) and
|
||
the browser engine (`QuantumEngine.variational(op, args)`). Each answer is
|
||
`{"request", "result"}`, the result sealed in a job's receipt and following
|
||
`wai.quantum.algorithms/1` ([the schema](../schemas/algorithms.v1.json)), so
|
||
`wai-quantum verify` checks it, and runs it again: every call is
|
||
deterministic and carries no clock, so the same request gives the same bytes.
|
||
|
||
## Parameters
|
||
|
||
A program's parameters are its real-valued inputs, `input float theta;` and
|
||
`input angle phi;`. Any job binds them with `"params"`: each value is written
|
||
into the program as a `const` of its type at exactly that double, before the
|
||
program is read, and every line keeps its number. A parameter left without a
|
||
value is refused (`Q114`, `J050`), and so is a name the program does not
|
||
declare. A sweep (`engine::sets`) may fix some parameters in `"params"` while
|
||
it sweeps the others.
|
||
|
||
```sh runnable
|
||
cat > ansatz.qasm <<'EOF'
|
||
OPENQASM 3.0;
|
||
input float t;
|
||
qubit[2] q;
|
||
h q[0];
|
||
crx(t) q[0], q[1];
|
||
EOF
|
||
wai-quantum run ansatz.qasm --param t=0.4 -o Z1 # ⟨Z1⟩ = (1 + cos 0.4)/2
|
||
wai-quantum run ansatz.qasm --sweep t=0,0.4,0.8 -o Z1 # one set, each point bound
|
||
wai-quantum run ansatz.qasm -o Z1 # exits 1
|
||
```
|
||
|
||
## Gradients
|
||
|
||
`gradient` gives `E = ⟨ψ|H|ψ⟩` for a Hamiltonian `H`, a sum of Pauli terms in
|
||
the form of a job's observables (`"Z0 Z1"`, `"0.5 X2"`, a constant `"-1.5"`, or
|
||
`{"pauli", "coeff"}`), and its derivative by each parameter, on the
|
||
double-precision state vector (at most 20 qubits, no noise, measurements only
|
||
at the end).
|
||
|
||
The reader carries every gate's derivative by every parameter
|
||
(`qasm::tangents`): through sums, products, quotients, constant powers, the
|
||
built-in functions (`sin`, `cos`, `tan`, `exp`, `ln`, `sqrt`, `arcsin`,
|
||
`arccos`, `arctan`), loops, broadcast and gate definitions, into each gate's
|
||
arguments. What it cannot follow is refused on its line with `Q129`: a
|
||
parameter under a modifier (write `crx(θ)` or `rx(-θ)` instead of
|
||
`ctrl @ rx(θ)` or `inv @ rx(θ)`), in a classical variable, a condition, an
|
||
index, a size, a loop's range or a subroutine, or a type that rounds it
|
||
(`angle[n]`, `float[32]`).
|
||
|
||
Two methods, both exact up to rounding:
|
||
|
||
- `adjoint` (the default): the circuit run forward once, then back once, each
|
||
gate's derivative applied once against the Hamiltonian applied to the state.
|
||
- `parameter_shift`: each gate a parameter moves run again at shifted angles.
|
||
Where its generator has two eigenvalues (`rx`, `ry`, `rz`, `p`, `cp`, `rxx`,
|
||
`ryy`, `rzz`, each angle of `u`, and `cu`'s phases) the rule has two terms,
|
||
`[E(θ + π/2) − E(θ − π/2)]/2`. Where it has three (`crx`, `cry`, `crz`, and
|
||
`cu`'s `θ`: eigenvalues `0, ±½`) it has four, with coefficients
|
||
`(√2 ± 1)/(4√2)` at `±π/2` and `±3π/2`. Every standard gate with a parameter
|
||
has one of the two; a gate with no rule would be refused.
|
||
|
||
The arithmetic is IEEE-754 double precision, so every number is approximate,
|
||
and the answer says so: `precision` gives `"arithmetic": "f64"`,
|
||
`"exact": false`, and `rounding_bound`, an a priori bound on the rounding of
|
||
the value and of each component. It counts each gate's entries (within four
|
||
units of their value) and each amplitude's sum of products, the expectation's
|
||
sums over the state in 64 chunks and its terms, the backward pass, and the
|
||
reader's own arithmetic for each gate's derivative, to first order in the unit
|
||
roundoff `2⁻⁵³`, and doubles the total. It bounds the reported number's
|
||
distance from the value the same circuit has in exact arithmetic.
|
||
|
||
```sh runnable
|
||
wai-quantum gradient ansatz.qasm --param t=0.4 --term Z1 --term "0.5 X0"
|
||
wai-quantum gradient ansatz.qasm --param t=0.4 --term Z1 --gradient parameter_shift --json > grad.json
|
||
wai-quantum verify grad.json
|
||
```
|
||
|
||
The tests hold each method to gradients worked out by hand for every gate
|
||
with a parameter within that bound, to central finite differences on a
|
||
circuit with every such gate, and to each other.
|
||
|
||
## Optimisers
|
||
|
||
`optimize` minimises `E` from the request's `params`, deterministically:
|
||
|
||
| `optimizer` | step | settings (defaults) |
|
||
|---|---|---|
|
||
| `gradient_descent` | `θ ← θ − step_size · ∇E` | `step_size` 0.1 |
|
||
| `adam` (the default) | the moment estimates with their bias corrections | `step_size` 0.05, `beta1` 0.9, `beta2` 0.999, `epsilon` 1e-8 |
|
||
| `spsa` | `ĝ = (E(θ + c_kΔ) − E(θ − c_kΔ))/(2c_k) · Δ`, `θ ← θ − a_k ĝ`, `Δ ∈ {±1}ⁿ` from a seeded stream | `step_size` (`a`) 0.2, `c` 0.1, `A` steps/10, `alpha` 0.602, `gamma` 0.101, `seed` 1 |
|
||
|
||
with `a_k = a/(k + 1 + A)^α` and `c_k = c/(k + 1)^γ`, at most 2000 `steps`.
|
||
The optimisers use only `+ − × ÷` and `√`, the crate's own `exp` and `ln` for
|
||
SPSA's gains, and the powers of `β` by repeated product: the same request
|
||
gives the same bytes on every platform (pinned in the tests, and held in
|
||
wasm32 by the browser engine's).
|
||
|
||
Every step is listed with its parameters and value (and gradient, or SPSA's
|
||
perturbation, estimate and gains). Each step is a link of a digest chain:
|
||
`start` is BLAKE3 of `wai.quantum.trace/1\0` and the request's canonical
|
||
text, each step's `digest` is BLAKE3 of the previous link and the step's
|
||
canonical text without its digest, and `chain` is the last. The receipt seals
|
||
the request (the program, the parameters it started from, the method and the
|
||
seed) and every step; `wai-quantum verify` checks the chain and runs the
|
||
optimisation again. `best` is the lowest value along the path, and `final`
|
||
the last point: a minimum along this path, not a proof of the global one.
|
||
|
||
```sh runnable
|
||
wai-quantum optimize ansatz.qasm --param t=0.4 --term Z1 --optimizer adam --steps 50
|
||
wai-quantum optimize ansatz.qasm --param t=0.4 --term Z1 --optimizer spsa --steps 50 --seed 7 --json > opt.json
|
||
wai-quantum verify opt.json
|
||
```
|
||
|
||
An optimisation can stop between any two steps and go on later, to the same
|
||
bytes. Its checkpoint (`wai.quantum.optimize-checkpoint/1`) holds:
|
||
|
||
- the request it is of, by the chain's `start` and the request's digest;
|
||
- the steps taken, each with its `digest`, and the last link;
|
||
- the optimiser's whole state: the point, Adam's moments and the powers of its
|
||
betas, SPSA's stream, the best point and the counts. Every number is the
|
||
hex of its f64's bits, so it reads back exactly.
|
||
|
||
A checkpoint goes on only from its own request, and only if each step is still
|
||
the link its digest says. Any other is refused (`J052`).
|
||
|
||
On the command line, `--checkpoint FILE` keeps the state in FILE as the run goes,
|
||
at most once a second and whenever it stops, and goes on from FILE when it is
|
||
there. A run killed and started again with the same arguments loses at most a
|
||
second of steps, and ends with the same bytes as a run that never stopped. The
|
||
file is removed when the run ends. `--slice N` takes at most N steps, then stops
|
||
with the state kept (exit 2), so a long optimisation can be run a slice at a
|
||
time.
|
||
|
||
```sh runnable
|
||
wai-quantum optimize ansatz.qasm --param t=0.4 --term Z1 --steps 200 --json > whole.json
|
||
wai-quantum optimize ansatz.qasm --param t=0.4 --term Z1 --steps 200 --json --checkpoint run.json --slice 100 # exits 2
|
||
wai-quantum optimize ansatz.qasm --param t=0.4 --term Z1 --steps 200 --json --checkpoint run.json > resumed.json
|
||
cmp whole.json resumed.json
|
||
```
|
||
|
||
## The variational eigensolver
|
||
|
||
`vqe` optimises an ansatz on a Hamiltonian: the request's program with its
|
||
`params`, or the built-in hardware-efficient ansatz (`--layers L`, or
|
||
`"ansatz": {"layers": L}`): layers of `ry` then `rz` on every qubit and a ring
|
||
of `cx`, the ansatz the variational machine-learning module trains
|
||
(`quantum_vml`), its parameters `t0`, `t1`, … starting at 0.1. Up to 8 qubits
|
||
the answer sets the best energy beside the exact ground energy by
|
||
diagonalisation (`reference.ground_energy`, by the cyclic Jacobi method on the
|
||
Hamiltonian's real symmetric form) and states the `gap`. The energy found is
|
||
never below the ground energy; an ansatz that cannot reach the ground state
|
||
stops above it.
|
||
|
||
```sh runnable
|
||
wai-quantum vqe --term "X0 X1" --term "Y0 Y1" --term "Z0 Z1" --layers 2 --steps 300
|
||
```
|
||
|
||
## QAOA for Max-Cut
|
||
|
||
`qaoa` builds the program and its cost from a graph (`{"nodes": n, "edges":
|
||
[[i, j] | [i, j, w], …]}`, at most 20 vertices): `|+⟩ⁿ`, then for each layer
|
||
`l`, `rzz(gamma_l · w)` on every edge and `rx(2 · beta_l)` on every qubit,
|
||
with the Hamiltonian `Σ (w/2) Z_i Z_j − (Σ w)/2`, whose expectation is minus
|
||
the expected cut. It optimises from the request's `params` or a linear ramp
|
||
and reads the best point's distribution against the maximum cut found by
|
||
enumerating every assignment: the expected cut and its ratio to the maximum,
|
||
the likeliest assignment and whether it is optimal, and the probability of an
|
||
optimal one. Assignments are written vertex `n − 1` first, as a job's counts
|
||
write a register's bits.
|
||
|
||
```sh runnable
|
||
printf '{"nodes": 4, "edges": [[0, 1], [1, 2], [2, 3], [3, 0]]}\n' > ring.json
|
||
wai-quantum qaoa --graph ring.json --layers 2 --steps 100
|
||
```
|
||
|
||
## The algorithm builders
|
||
|
||
`build` writes an OpenQASM 3 program for a standard algorithm, says how to
|
||
read its result and what it gives, and checks it with the equivalence ladder
|
||
against a reference built from the algorithm's definition, never from the
|
||
program's gates: every basis state at most 8 qubits (`exact`), random product
|
||
states at most 10 (`random`, evidence), the adder's truth table at most 16;
|
||
wider programs say `unchecked`. Without `--json` the program goes to standard
|
||
output and the check to standard error.
|
||
|
||
| `algorithm` | arguments | the program | read | its reference |
|
||
|---|---|---|---|---|
|
||
| `qpe` | `counting` (4), `phase` φ in turns | `p(2πφ)` on its eigenstate `\|1⟩`, controlled powers from `t` counting qubits, the inverse Fourier transform | the counting register's integer `k`: `φ ≈ k/2ᵗ` | the Fourier transform by its formula and the powers by their phases |
|
||
| `amplitude_estimation` | `counting` (4), `amplitude` a | `A = ry(2·arcsin √a)`, then phase estimation of the Grover operator `Q = A·Z·A†·Z` | `a ≈ sin²(πk/2ᵗ)` | `Q` as `A`'s matrices multiplied, its powers by repeated product |
|
||
| `adder` | `bits`, optionally `a`, `b`, `carry_in` | the ripple-carry adder in place: `b ← a + b + c_in mod 2ⁿ`, the carry into `c_out` | with `a` and `b`, the measured sum and carry | the truth table in integer arithmetic |
|
||
| `qsvt` | `phases` φ₀…φ_d, and `x` or `matrix` | signal processing `e^{iφ₀Z} Π W(x) e^{iφₖZ}`, `W(x) = e^{i arccos(x) X}`; or the singular value transformation of a real symmetric 2 × 2 `A` through `[[A, √(I−A²)], [√(I−A²), −A]]` | `⟨0\|U\|0⟩ = P(x)`, or the signal qubit's `⟨0\|·\|0⟩` block `P(A)` | the 2 × 2 products, and the block encoding with `√(I − A²)` by its closed form |
|
||
|
||
Phase estimation's outcome `k` has the Fejér distribution
|
||
`P(k) = |2⁻ᵗ Σⱼ e^{2πi j(φ − k/2ᵗ)}|²`, exactly `k = 2ᵗφ` when that is whole;
|
||
amplitude estimation's is `½F(k; θ/π) + ½F(k; −θ/π)` with `θ = arcsin √a`.
|
||
For `qsvt` the phases are in the signal's convention (`W(x)`); with a matrix
|
||
they are turned to the reflection's (`φ₀ + (2d − 1)π/4`, the inner ones
|
||
`− π/2`, `φ_d − π/4`), so the block is the same polynomial of `A`. All phases
|
||
zero give the Chebyshev polynomial `T_d`. The tests hold phase and amplitude
|
||
estimation to those distributions, the adder to a truth table written apart
|
||
from the builder's and run as a job on the bit-exact method, and `qsvt` to
|
||
`T_d` of a signal and of a matrix by its recursion.
|
||
|
||
```sh runnable
|
||
wai-quantum build qpe --counting 5 --phase 0.3 > qpe.qasm
|
||
wai-quantum run qpe.qasm --shots 1000
|
||
wai-quantum build adder --bits 4 --a 9 --b 7 > add.qasm
|
||
wai-quantum run add.qasm --shots 10
|
||
wai-quantum build qsvt --phases 0,0,0,0 --matrix 0.3,0.2,-0.5 --json > qsvt.json
|
||
wai-quantum verify qsvt.json
|
||
```
|
||
|
||
## Refusals
|
||
|
||
| Code | When |
|
||
|---|---|
|
||
| `J050` | `params` that do not read, a name the program does not declare as a parameter, or a parameter left without a value (with `Q114`) |
|
||
| `J051` | a gradient that cannot be taken: a differentiation method that does not exist, a parameter the reader cannot follow (with `Q129`), a program that measures in the middle, noise, no Hamiltonian, or more qubits or work than it takes |
|
||
| `J052` | an optimisation, a VQE or a QAOA run that does not read: an unknown optimiser, settings or steps past their limits, a Hamiltonian or a graph that does not read |
|
||
| `J053` | a builder's request that does not read: an unknown algorithm, sizes past its limits, or arguments it does not take |
|
||
| `J031` | the job service's own bounds (16 qubits, 500 steps, about 4·10⁹ gate amplitudes a call): the message names the command that runs it on your machine |
|