feat: runtime entrypoint arguments for the emulator#1890
Draft
ss2165 wants to merge 3 commits into
Draft
Conversation
Contributor
|
| Branch | ss/entrypoint-args |
| Testbed | Linux |
Click to view all benchmark results
| Benchmark | hugr_bytes | Benchmark Result bytes x 1e3 (Result Δ%) | Upper Boundary bytes x 1e3 (Limit %) | hugr_nodes | Benchmark Result nodes (Result Δ%) | Upper Boundary nodes (Limit %) |
|---|---|---|---|---|---|---|
| tests/benchmarks/test_big_array.py::test_big_array_compile | 📈 view plot 🚷 view threshold | 154.02 x 1e3(0.00%)Baseline: 154.02 x 1e3 | 155.56 x 1e3 (99.01%) | 📈 view plot 🚷 view threshold | 6,630.00(0.00%)Baseline: 6,630.00 | 6,696.30 (99.01%) |
| tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile | 📈 view plot 🚷 view threshold | 27.71 x 1e3(0.00%)Baseline: 27.71 x 1e3 | 27.99 x 1e3 (99.01%) | 📈 view plot 🚷 view threshold | 1,051.00(0.00%)Baseline: 1,051.00 | 1,061.51 (99.01%) |
| tests/benchmarks/test_queue_push_pop.py::test_queue_push_benchmark_compile | 📈 view plot 🚷 view threshold | 10.09 x 1e3(0.00%)Baseline: 10.09 x 1e3 | 10.19 x 1e3 (99.01%) | 📈 view plot 🚷 view threshold | 301.00(0.00%)Baseline: 301.00 | 304.01 (99.01%) |
| tests/benchmarks/test_queue_push_pop.py::test_queue_push_pop_benchmark_compile | 📈 view plot 🚷 view threshold | 13.69 x 1e3(-0.01%)Baseline: 13.70 x 1e3 | 13.83 x 1e3 (99.00%) | 📈 view plot 🚷 view threshold | 420.00(0.00%)Baseline: 420.00 | 424.20 (99.01%) |
6242ee4 to
2c31da7
Compare
Support compiling a Guppy program once and running it many times with different runtime arguments (e.g. for variational workflows) instead of recompiling, via the selene emulator. When an entrypoint takes parameters, `.emulator()` wraps it so each argument is read at run time through the `tket.argreader` `read_arg` op (tagged with the parameter name) and injects selene's `ArgReaderPlugin`. Argument values are supplied at run time on the instance: * `run(**kwargs)` for constant args (same every shot), and * `run_per_shot([...])` for per-shot args (one dict per shot). Supported argument types are `bool`, signed `int`, `float`, and arrays of those; `nat` and other types raise a clear diagnostic. This is an emulator-only feature since `read_arg` is only lowered by the selene compiler and values flow through selene's `ArgProvider`. Update examples/qaoa_maxcut_example.ipynb to use this pattern: the QAOA cost/mixer angles become runtime `array[float, p]` arguments, so `main` is compiled once and re-run with `.run(...)` per parameter set instead of recompiling each optimizer iteration. A new benchmark cell quantifies it. Measured on the 7-node example (p=3, 200 shots, 12 evaluations): * recompile per evaluation: ~0.94 s / eval * compile once + runtime args: ~0.06 s / eval (after a ~0.55 s one-time build) * per-evaluation speedup: ~16x, with identical energies (diff 0.0000) This removes the recompile bottleneck that previously kept the QAOA notebook out of CI (#1546). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rewrite examples/qaoa_maxcut_example.ipynb so the QAOA cost/mixer angles are runtime `array[float, p]` arguments to the `main` entrypoint. The program is compiled and built once and re-run with `.run(...)` for each parameter set in the variational optimization loop, which is the idiomatic way to run variational workflows now that entrypoints can take runtime arguments. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The QAOA notebook was excluded from the example-notebook regression tests because recompiling the entrypoint for every optimizer evaluation made it too slow (#1546). It now passes the cost/mixer angles as runtime arguments and compiles once, so it runs in ~20s and can be re-enabled. Closes #1546 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2c31da7 to
88a20aa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This description was written by Copilot on Seyon's behalf and will be refined later.
Runtime entrypoint arguments for the emulator
Adds the Guppy-side support for passing runtime arguments to a program's entrypoint, so a program can be compiled once and run many times with different parameter values. This is the consumer of the tket2
tket.argreaderwork in Quantinuum/tket2#1731 (which continues @jake-arkinstall's #1682).The motivating use case is variational workloads (e.g. QAOA): today each parameter update forces a full recompile; with this, the parameters become entrypoint arguments and only execution repeats.
Scope
Emulator-only (selene).
compile()/compile_entrypoint()are unchanged and still reject entrypoint args.API
Supported arg types:
bool, signedint,float, and 1-D arrays of those.natand nested arrays are rejected with a clear error.What's here
emulator/_args.py— arg classification, validation, and entrypoint surgery.defs.py—emulator()wiring, arg-spec extraction, unsupported-arg error.emulator/builder.py,emulator/instance.py— builder plumbing +run()/run_per_shot().This needs argreader-enabled
tket_extsandselene_hugr_qis_compiler, which are not yet published:Notes