wai-quantum: an optimisation stops and goes on to the same bytes #608

Merged
dcharlot merged 2 commits from wai/quantum-optimize-resume-2 into main 2026-11-04 10:26:30 -05:00
Owner

Replaces #597: the same commit (same patch id), on main at 2bef11f71. Main had moved by 15 commits, among them #603, which runs each workflow's gate on linux rather than behind the arm64 work it gates; a pull request runs its own head's workflows, so #597 would have run the old ones.

A long optimisation ran to its end in one process or not at all, and one killed partway lost every step. The optimiser now stops between any two steps and goes on later, to the same bytes.

What changes

wai-quantum (engine::variational)

  • optimize_resumable(request, from, each) runs from a checkpoint (from) or from the start. After every step but the last, each gets the run as it stands (Paused), and returns whether to go on. call_optimize is the same with call's checks and stamp. optimize is optimize_resumable with nothing stopping it, so its answers are unchanged.
  • The checkpoint (wai.quantum.optimize-checkpoint/1, from Paused::checkpoint) holds:
    • the request, by the chain's start and the request's digest;
    • the steps taken, each with its link, 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, the evaluation count and the gradient's rounding bound. Every number is the hex of its f64's bits, so a resume never depends on how a JSON reader rounds.
  • Refusals: a checkpoint goes on only from its own request, and only if each step is still the link its digest says. Another request, an edited step, a dropped step, a next step past the end, a state that does not read, and parameters out of range are each refused with J052.
  • A changed checkpoint whose steps still chain would give a different path. That path's answer cannot pass verify, because verify runs the request again.

wai-quantum-cli: optimize --checkpoint FILE keeps the state in FILE as the run goes, at most once a second and whenever it stops. Each write goes to FILE.partial and is renamed, so a kill mid-write leaves the last whole state. The command goes on from FILE when FILE is there, and removes FILE once the run ends. --slice N takes at most N steps, then stops with the state kept and exits 2 (as task status does while a task is active). The Chinese summary of optimize is translated from its new English.

The docs (docs/variational.md, the CLI README) and the CLI's agent docs are updated.

Tests

  • The engine: for gradient descent, Adam, SPSA and Adam with the parameter-shift rule:
    • stopped after each step in turn, written as text, read back and gone on with, every run is the uninterrupted run's bytes;
    • taken one step a slice, every run is too.
  • Refusals: a checkpoint of another program, or of more steps, is refused. So are eight changed copies: a step's value, a dropped step, the chain, the next step, the parameters, the stream, the format, and parameters that are not finite. The checkpoint's own run ends as one that never stopped.
  • The command line, against its binary:
    • 41 steps taken seven at a time end in six slices, with stdout byte for byte the uninterrupted run's (receipt included, signed with the demo key) and the checkpoint removed;
    • another request's checkpoint is refused and left as it was;
    • a 16-qubit, 600-step run killed partway with SIGKILL once it has kept a state, then started again, says it is going on, and prints exactly the uninterrupted run's bytes.
  • The variational workflow requires the two new engine tests by name.

Checked

On the build host: the engine's variational, algorithm, schema and refusal tests; cargo check with -D warnings for the engine's feature sets; and the command line's tests (the new ones among them) and clippy, with and without default features. The public-name check is clean.

🤖 Generated with Claude Code

Replaces #597: the same commit (same patch id), on main at 2bef11f71. Main had moved by 15 commits, among them #603, which runs each workflow's gate on `linux` rather than behind the arm64 work it gates; a pull request runs its own head's workflows, so #597 would have run the old ones. A long optimisation ran to its end in one process or not at all, and one killed partway lost every step. The optimiser now stops between any two steps and goes on later, to the same bytes. ## What changes **wai-quantum** (`engine::variational`) - `optimize_resumable(request, from, each)` runs from a checkpoint (`from`) or from the start. After every step but the last, `each` gets the run as it stands (`Paused`), and returns whether to go on. `call_optimize` is the same with `call`'s checks and stamp. `optimize` is `optimize_resumable` with nothing stopping it, so its answers are unchanged. - **The checkpoint** (`wai.quantum.optimize-checkpoint/1`, from `Paused::checkpoint`) holds: - the request, by the chain's `start` and the request's digest; - the steps taken, each with its link, 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, the evaluation count and the gradient's rounding bound. Every number is the hex of its f64's bits, so a resume never depends on how a JSON reader rounds. - **Refusals:** a checkpoint goes on only from its own request, and only if each step is still the link its digest says. Another request, an edited step, a dropped step, a next step past the end, a state that does not read, and parameters out of range are each refused with `J052`. - A changed checkpoint whose steps still chain would give a different path. That path's answer cannot pass `verify`, because `verify` runs the request again. **wai-quantum-cli:** `optimize --checkpoint FILE` keeps the state in FILE as the run goes, at most once a second and whenever it stops. Each write goes to `FILE.partial` and is renamed, so a kill mid-write leaves the last whole state. The command goes on from FILE when FILE is there, and removes FILE once the run ends. `--slice N` takes at most N steps, then stops with the state kept and exits 2 (as `task status` does while a task is active). The Chinese summary of `optimize` is translated from its new English. The docs (`docs/variational.md`, the CLI README) and the CLI's agent docs are updated. ## Tests - **The engine:** for gradient descent, Adam, SPSA and Adam with the parameter-shift rule: - stopped after each step in turn, written as text, read back and gone on with, every run is the uninterrupted run's bytes; - taken one step a slice, every run is too. - **Refusals:** a checkpoint of another program, or of more steps, is refused. So are eight changed copies: a step's value, a dropped step, the chain, the next step, the parameters, the stream, the format, and parameters that are not finite. The checkpoint's own run ends as one that never stopped. - **The command line, against its binary:** - 41 steps taken seven at a time end in six slices, with stdout byte for byte the uninterrupted run's (receipt included, signed with the demo key) and the checkpoint removed; - another request's checkpoint is refused and left as it was; - a 16-qubit, 600-step run killed partway with `SIGKILL` once it has kept a state, then started again, says it is going on, and prints exactly the uninterrupted run's bytes. - The variational workflow requires the two new engine tests by name. ## Checked On the build host: the engine's variational, algorithm, schema and refusal tests; `cargo check` with `-D warnings` for the engine's feature sets; and the command line's tests (the new ones among them) and clippy, with and without default features. The public-name check is clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
wai-quantum: an optimisation stops and goes on to the same bytes
Some checks failed
wai-quantum WebGPU member / shader checks · browser build · wasip2 inertness · MSRV (pull_request) Successful in 3m25s
wai-web reach builds / wai-web reach builds · the package of record, every output as recorded (pull_request) Successful in 3m0s
wai-quantum docs, course and locales / every command and snippet in the docs · linux (pull_request) Failing after 21m6s
wai-sink-android native sink library / every ABI, the AAR, and the instrumented tests in a headless emulator · macos (pull_request) Successful in 5m37s
wai-quantum views in agent hosts / views · a scripted host (pull_request) Successful in 7m7s
wai-quantum WebGPU member / member · Metal (macos) (pull_request) Successful in 8m38s
wai-web wasm32 / wai-web wasm32 build · corpus, menu and writers (pull_request) Successful in 7m25s
WAI Studio / Studio in WebKit · linux (pull_request) Successful in 10m49s
wai-sink-swift native sink package / libwai slices, desktop tests, simulator tests · macos (pull_request) Successful in 12m16s
standards workspaces build + test / macOS energy backends (pull_request) Successful in 38m37s
wai-quantum tensor-engine member / member · tensor engine, the kernel toolchain's simulator (linux) (pull_request) Successful in 16m37s
wai-web reach builds / wai-web reach builds · this tree's wai-web, every rung on its engine line (pull_request) Successful in 12m6s
WAI Studio / Studio in Chromium and Firefox · macos (pull_request) Successful in 24m35s
standards workspaces build + test / joule-code-rs (joule-code/joule-code-rs, joule-code-rs, linux-arm64, true) (pull_request) Has been cancelled
WAI conformance / cargo-class corpora · linux-arm64 (pull_request) Has been cancelled
WAI conformance / v2 vocabulary · manifests validate as stated (pull_request) Has been cancelled
WAI conformance / independent verifiers · claims, JWP, key discovery and integer payloads (Python) (pull_request) Has been cancelled
WAI conformance / each feature of the independent verifiers' steps compiles alone (pull_request) Has been cancelled
WAI conformance / delivery telemetry · CMCD and CMSD against an independent library (pull_request) Has been cancelled
WAI conformance / cross-arch byte-equality · linux-arm64 (pull_request) Has been cancelled
WAI conformance / C2PA manifest emission · signed, read back, validated (pull_request) Has been cancelled
WAI energy receipts / energy receipts · linux-arm64 (pull_request) Has been cancelled
WAI examples / WAI examples · android-app · linux-arm64 (pull_request) Has been cancelled
wai-quantum HIP member / member · HIP absent (linux-arm64) (pull_request) Has been cancelled
wai-quantum npu-cores member / member · npu-cores absent (linux-arm64) (pull_request) Has been cancelled
wai-quantum pulse and dynamics / the same bits · linux-arm64 (pull_request) Has been cancelled
wai-quantum extension points / the registry and the example · linux-arm64 (pull_request) Has been cancelled
wai-quantum tensor-engine member / member · tensor engine absent (linux-arm64) (pull_request) Has been cancelled
wai-quantum variational and algorithm library / parameters, gradients, optimisers, VQE, QAOA and builders · linux-arm64, release (pull_request) Has been cancelled
wai-sink-android native sink library / the JNI layer and the platform-free half on the host JVM · linux-arm64 (pull_request) Has been cancelled
980fffc34d
A long optimisation ran to its end in one process or not at all; one
killed partway lost every step. The engine's optimiser now runs from a
checkpoint (engine::variational::optimize_resumable, call_optimize): after
every step its caller has the run as it stands and may stop it there, and
the checkpoint, wai.quantum.optimize-checkpoint/1, holds the steps taken
with their links and 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 as the bits of its f64. Gone on with from any step,
a run ends with the same bytes as one that never stopped, for each
optimiser; a checkpoint of another request, or one whose steps were
changed, is refused (J052).

wai-quantum optimize --checkpoint FILE keeps the state in FILE as it goes
(at most once a second, and when it stops; written whole or not at all),
goes on from FILE when it is there, and removes it when the run ends; a
run killed and started again with the same arguments ends with the same
bytes, receipt and all. --slice N takes at most N steps, then stops with
the state kept (exit 2).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
wai-quantum docs: the checkpoint example runs, and shows its claim
All checks were successful
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
0636f34e20
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]>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Transaction-Science/open-standards!608
No description provided.