Skip to content

feat: runtime entrypoint arguments for the emulator#1890

Draft
ss2165 wants to merge 3 commits into
mainfrom
ss/entrypoint-args
Draft

feat: runtime entrypoint arguments for the emulator#1890
ss2165 wants to merge 3 commits into
mainfrom
ss/entrypoint-args

Conversation

@ss2165

@ss2165 ss2165 commented Jun 19, 2026

Copy link
Copy Markdown
Member

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.argreader work 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

inst = main.emulator(n_qubits=N).run(theta=1.5, k=3)          # constant args across shots
inst = main.emulator(n_qubits=N).run_per_shot([{...}, {...}])  # per-shot args

Supported arg types: bool, signed int, float, and 1-D arrays of those. nat and nested arrays are rejected with a clear error.

What's here

  • emulator/_args.py — arg classification, validation, and entrypoint surgery.
  • defs.pyemulator() wiring, arg-spec extraction, unsupported-arg error.
  • emulator/builder.py, emulator/instance.py — builder plumbing + run() / run_per_shot().
  • Unit + integration tests; the QAOA maxcut example rewritten to use runtime args.
  • Re-enables the QAOA notebook in CI (Closes [Docs]: Speed up variational loop in QAOA example #1546).

⚠️ Dependency blocker (do not merge yet)

This needs argreader-enabled tket_exts and selene_hugr_qis_compiler, which are not yet published:

  • The e2e arg tests self-skip when argreader is unavailable, so they're safe.
  • The re-enabled QAOA notebook test has no such guard and will fail on CI until the deps are published. This PR, the dependency bump, and the notebook re-enable should land together. Locally everything passes using private wheels built from tket2#1731.

Notes

  • Notebook regression snapshot was generated on macOS/arm; cross-platform determinism against Linux CI is unverified.

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchss/entrypoint-args
TestbedLinux
Click to view all benchmark results
Benchmarkhugr_bytesBenchmark Result
bytes x 1e3
(Result Δ%)
Upper Boundary
bytes x 1e3
(Limit %)
hugr_nodesBenchmark 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%)
🐰 View full continuous benchmarking report in Bencher

@codspeed-hq

codspeed-hq Bot commented Jun 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 11 untouched benchmarks


Comparing ss/entrypoint-args (88a20aa) with main (0ca86f7)

Open in CodSpeed

@ss2165 ss2165 force-pushed the ss/entrypoint-args branch 3 times, most recently from 6242ee4 to 2c31da7 Compare June 22, 2026 12:43
ss2165 and others added 3 commits June 22, 2026 13:45
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>
@ss2165 ss2165 force-pushed the ss/entrypoint-args branch from 2c31da7 to 88a20aa Compare June 22, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Docs]: Speed up variational loop in QAOA example

1 participant