feat!: runtime entrypoint arguments via generic tket.argreader op#1731
feat!: runtime entrypoint arguments via generic tket.argreader op#1731ss2165 wants to merge 6 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1731 +/- ##
==========================================
+ Coverage 85.29% 85.35% +0.06%
==========================================
Files 191 194 +3
Lines 30355 30692 +337
Branches 28986 29299 +313
==========================================
+ Hits 25890 26196 +306
- Misses 3240 3262 +22
- Partials 1225 1234 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
8781aed to
46fdd23
Compare
from PR #1682 Initial concept of entrypoint arg lowering using selene's argreader utility Restore debug path stripping, but just strip the paths to keep the IR valid cargo fmt Anyhow is now not behind a feature flag Add simple documentation to satisfy clippy (will likely need elaboration)
- Remove ArgumentReadOpDef (8 variants) and replace with ReadArgOpDef { ReadArg }
- Replace ArgumentReadOp/SimpleArgs/ReadArgs with ReadArgOp { tag, output_type }
- Delete map_type and wrap_entrypoint_with_arguments (surgery will live in guppy)
- Add ArgKind enum + classify_arg_type() for type-driven LLVM dispatch
- Add ReadArgBuilder trait for ergonomic graph construction
- Rewrite LLVM lowering with type-driven dispatch and emit_array_read helper
- Add 13 extension unit tests and 7 LLVM lowering snapshot tests
- Add Default derive to QISPreludeCodegen for test setup
- Remove 'entry_args' from Python test parametrize (no guppy changes yet)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add argreader::EXTENSION to qsystem_extensions() so it is serialized - Regenerate tket-exts/src/tket_exts/data/tket/argreader.json - Add ArgReaderExtension Python wrapper with read_arg() helper - Register argreader in tket_exts __init__ and tket_registry() - Add validation test fixture for the argreader extension Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…sting Move ArgKind, classify_arg_type and the scalar/array classification helpers out of the HUGR extension definition and into the LLVM lowering module, since classification is purely a codegen concern. - Identify types via full Type comparison against the canonical tables (INT_TYPES, bool_t, float64_type) and the borrow_array TypeDef, instead of flakily matching on bare extension ids. - Reject integer widths other than i64 (log-width 6) at codegen time, where the get_i64 selene extern is the only integer reader; the extension layer stays permissive about width. - Revert anyhow back to an optional dependency in tket-qsystem, gated by the cli + llvm features, now that the only non-llvm anyhow user has moved. - qis-compiler: enable module.verify() after codegen and validate that the entrypoint has no leftover input parameters (all args must flow through read_arg ops). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mirror the result/debug codegen by making argreader operate on the standard `array` type through the existing `ArrayLowering` abstraction, instead of being hard-wired to `borrow_array`. - Add `alloc_array` to the `ArrayLowering` trait (argreader produces arrays, whereas result only consumes them) and implement it for `HeapArrayLowering` via `array::build_array_alloc`. - Make `ArgReaderCodegenExtension` generic over `AL: ArrayLowering`; allocate + wrap the extern-filled buffer with `alloc_array` + `array_from_ptr`. - Classify the standard `array` typedef (`as_borrow_array` -> `as_std_array`). - Wire argreader with `SeleneHeapArrayCodegen::LOWERING` in qis-compiler, the same lowering result/debug use; the bespoke borrow-array path is gone. - Tests + snapshots updated to standard arrays; classification and narrow-int rejection unchanged. The asymmetry that motivated this is a guppy compilation choice: guppy bridges borrow_array -> standard array before `result`, so the matching bridge will be added before `read_arg` in the guppy entrypoint wrapper. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
This PR contains breaking changes to the public Rust API. cargo-semver-checks summary |
There was a problem hiding this comment.
Pull request overview
Adds a new tket.argreader HUGR extension and LLVM lowering to enable reading runtime-provided entrypoint arguments (scalars and fixed-size arrays), wiring it through tket-qsystem, tket-exts, and qis-compiler, with updated snapshot fixtures.
Changes:
- Introduces
tket.argreaderextension (Rust + JSON + Python bindings) with a genericread_arg<tag, T>() -> Top. - Implements LLVM codegen for
read_arg, including array allocation support via a newArrayLowering::alloc_arraymethod. - Integrates the argreader codegen into
qis-compilerand updates LLVM snapshot fixtures accordingly.
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tket-qsystem/src/llvm/argreader.rs | New LLVM lowering for tket.argreader ops, including scalar/array variants and tests. |
| tket-qsystem/src/llvm/array_utils.rs | Extends ArrayLowering with alloc_array and implements it for heap lowering. |
| tket-qsystem/src/llvm/prelude.rs | Makes QISPreludeCodegen Default (and still Clone). |
| tket-qsystem/src/llvm.rs | Exposes the new llvm::argreader module. |
| tket-qsystem/src/extension/argreader.rs | Defines the tket.argreader extension and ReadArgOp plumbing + tests. |
| tket-qsystem/src/extension.rs | Registers the new extension in the qsystem extension list/registry. |
| tket-qsystem/src/llvm/snapshots/tket_qsystem__llvm__argreader__test__emit_argreader_codegen@pre-mem2reg@llvm21_1.snap | New snapshot fixture for argreader scalar bool (pre-mem2reg). |
| tket-qsystem/src/llvm/snapshots/tket_qsystem__llvm__argreader__test__emit_argreader_codegen@pre-mem2reg@llvm21_2.snap | New snapshot fixture for argreader scalar int (pre-mem2reg). |
| tket-qsystem/src/llvm/snapshots/tket_qsystem__llvm__argreader__test__emit_argreader_codegen@pre-mem2reg@llvm21_3.snap | New snapshot fixture for argreader scalar f64 (pre-mem2reg). |
| tket-qsystem/src/llvm/snapshots/tket_qsystem__llvm__argreader__test__emit_argreader_codegen@pre-mem2reg@llvm21_4.snap | New snapshot fixture for argreader bool array (pre-mem2reg). |
| tket-qsystem/src/llvm/snapshots/tket_qsystem__llvm__argreader__test__emit_argreader_codegen@pre-mem2reg@llvm21_5.snap | New snapshot fixture for argreader i64 array (pre-mem2reg). |
| tket-qsystem/src/llvm/snapshots/tket_qsystem__llvm__argreader__test__emit_argreader_codegen@pre-mem2reg@llvm21_6.snap | New snapshot fixture for argreader f64 array (pre-mem2reg). |
| tket-qsystem/src/llvm/snapshots/tket_qsystem__llvm__argreader__test__emit_argreader_codegen@llvm21_1.snap | New snapshot fixture for argreader scalar bool (post-opt). |
| tket-qsystem/src/llvm/snapshots/tket_qsystem__llvm__argreader__test__emit_argreader_codegen@llvm21_2.snap | New snapshot fixture for argreader scalar int (post-opt). |
| tket-qsystem/src/llvm/snapshots/tket_qsystem__llvm__argreader__test__emit_argreader_codegen@llvm21_3.snap | New snapshot fixture for argreader scalar f64 (post-opt). |
| tket-qsystem/src/llvm/snapshots/tket_qsystem__llvm__argreader__test__emit_argreader_codegen@llvm21_4.snap | New snapshot fixture for argreader bool array (post-opt). |
| tket-qsystem/src/llvm/snapshots/tket_qsystem__llvm__argreader__test__emit_argreader_codegen@llvm21_5.snap | New snapshot fixture for argreader i64 array (post-opt). |
| tket-qsystem/src/llvm/snapshots/tket_qsystem__llvm__argreader__test__emit_argreader_codegen@llvm21_6.snap | New snapshot fixture for argreader f64 array (post-opt). |
| tket-exts/src/tket_exts/data/tket/argreader.json | Ships the extension definition JSON for tket.argreader. |
| tket-exts/src/tket_exts/tket/argreader.py | Adds Python API surface for read_arg. |
| tket-exts/src/tket_exts/tket/init.py | Exports argreader submodule. |
| tket-exts/src/tket_exts/init.py | Registers/exports ArgReaderExtension in the public extension registry. |
| tket-exts/tests/test_validate_exts.py | Adds validation coverage for the new extension export + op instantiation. |
| qis-compiler/rust/lib.rs | Wires ArgReaderCodegenExtension into codegen extension set. |
| qis-compiler/python/tests/snapshots/test_basic_generation/test_llvm/sol-x86_64-windows-msvc-entry_args/entry_args_x86_64-windows-msvc_sol | Updated LLVM snapshot for entry-args on sol (windows x86_64). |
| qis-compiler/python/tests/snapshots/test_basic_generation/test_llvm/sol-x86_64-unknown-linux-gnu-entry_args/entry_args_x86_64-unknown-linux-gnu_sol | Updated LLVM snapshot for entry-args on sol (linux x86_64). |
| qis-compiler/python/tests/snapshots/test_basic_generation/test_llvm/sol-x86_64-apple-darwin-entry_args/entry_args_x86_64-apple-darwin_sol | Updated LLVM snapshot for entry-args on sol (macOS x86_64). |
| qis-compiler/python/tests/snapshots/test_basic_generation/test_llvm/sol-aarch64-apple-darwin-entry_args/entry_args_aarch64-apple-darwin_sol | Updated LLVM snapshot for entry-args on sol (macOS aarch64). |
| qis-compiler/python/tests/snapshots/test_basic_generation/test_llvm/helios-x86_64-windows-msvc-entry_args/entry_args_x86_64-windows-msvc_helios | Updated LLVM snapshot for entry-args on helios (windows x86_64). |
| qis-compiler/python/tests/snapshots/test_basic_generation/test_llvm/helios-aarch64-apple-darwin-entry_args/entry_args_aarch64-apple-darwin_helios | Updated LLVM snapshot for entry-args on helios (macOS aarch64). |
| qis-compiler/pyproject.toml | Expands uv cache keys to include upstream Rust sources so rebuilds invalidate correctly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Runtime entrypoint arguments (
tket.argreader)Based on #1682 (originally by @jake-arkinstall).
What this does
Lets a compiled user program read runtime arguments at the entrypoint, so a program can be compiled once and run many times with different parameters (the motivating use case is variational workloads like QAOA, where today every parameter update forces a recompile).
Dependant guppy PR: Quantinuum/guppylang#1890
read_arg<Tag, T>op that is parametrised by string tag (likeresult) and the type it outputs.tket-qsystem: argreader extension definition (extension/argreader.rs) and LLVM lowering (llvm/argreader.rs,llvm/prelude.rs). Roughly mirrorsresultcodegen. However, this new op can create new arrays so needs allocation in ArrayLowering.tket-exts: ships thetket.argreaderextension JSON + Python bindings.qis-compiler: wires the argreader plugin into codegen; regenerated test HUGRs and LLVM/selene snapshots (the large diff is almost entirely regenerated snapshot fixtures).BREAKING CHANGE: ArrayLowering trait has new required method alloc_array for allocating a fresh array.