feat: InlineHint metadata#1532
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1532 +/- ##
==========================================
+ Coverage 84.05% 84.24% +0.19%
==========================================
Files 189 189
Lines 29358 29778 +420
Branches 28174 28581 +407
==========================================
+ Hits 24677 25087 +410
- Misses 3501 3502 +1
- Partials 1180 1189 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Ok let's combine functionality (not necessarily PRs) here with #1449.
I've updated that to use a similar metadata (there without the Never, with #[non_exhaustive], and I called it InlineAnnotation rather than hint, but at least it's in the same place ;-)).
Noting that #1524 uses inline_acyclic which will mean any function on a cycle will not be inlined at all (cycles are removed from graph rather than merely broken), I think #1449 handles the "Always" bit better, so that can be run first as a separate pass.
Thus, either (a) put this in first, but without the Always option (to be added in 1449); or (b) let's get #1449 in first and then this can add the Never option. I don't really mind which way around, and I think #1449 can be marked ready now (probably for a random reviewer? But you might want to check over the annotation).
WRT this PR:
- I am also unsure about "follow_hints=False" still respecting the "Never" hint; are we sure it shouldn't follow that too? (Otherwise, follow_hints will do nothing when Always is removed. One could say "Always is not a hint" but an annotation, iow it's correct for "follow_hints" to have no effect until we add some InlineAnnotation::XYZHint).
- Would be nice to add to the heuristic here that (non-preserved?) functions with only one call "are always small enough" ;)
- I haven't checked what you're doing here, but I note it's quite tricksy doing inlining respecting PassScope::EntrypointXXX :(
|
If we'd rather put this in with the algorithm as here, which I think is ok....
|
…llow_hint pass option
I think that should combine well with your PR now? |
|
This PR contains breaking changes to the public Rust API. cargo-semver-checks summary |
acl-cqc
left a comment
There was a problem hiding this comment.
Thanks Agustin, looks good to me
| Values: | ||
| - "never": Never inline this function. | ||
| - "best_effort": | ||
| Inline the function if we know it won't produce an invalid Hugr. |
There was a problem hiding this comment.
| Inline the function if we know it won't produce an invalid Hugr. | |
| Inline the function if possible |
or "as much as the compiler is able."
I don't know that infinitely big Hugrs are invalid. I mean, we can't validate them, but if we had infinite memory and address space, validation won't throw an error... ;)
| - "never": Never inline this function. | ||
| - "best_effort": | ||
| Inline the function if we know it won't produce an invalid Hugr. | ||
| This is a best effort option; the compiler may choose not to inline |
There was a problem hiding this comment.
| This is a best effort option; the compiler may choose not to inline | |
| Whilst this is no guarantees (the compiler may choose not to inline | |
| functions with this annotation), the compiler should aim to inline whenever possible, ignoring any restrictions due to finite quantities |
Or "ignoring quantitative restrictions" or something like that
There was a problem hiding this comment.
I'd be cautious of promising what the compiler will do here.
We don't want to be limited by the metadata restrictions when updating the compiler inlining pass.
| KEY = _metadata.MAX_QUBITS_HINT | ||
|
|
||
|
|
||
| class InlineAnnotationValue(Enum): |
There was a problem hiding this comment.
Just wondering if it's possible to use a Literal["never","best_effort"] instead of this Enum? That might be much simpler?
There was a problem hiding this comment.
Yeah, for a public API it may be simpler to do strings. Updated.
) We should also add a metadata for inline hints either here or in Quantinuum#1532, whichever gets merged second.
🤖 I have created a release *beep* *boop* --- ## [0.13.1](Quantinuum/tket2@tket-py-v0.13.0...tket-py-v0.13.1) (2026-05-19) ### Features * Add python definitions for the TKET metadata keys ([Quantinuum#1535](Quantinuum#1535)) ([1bfef9a](Quantinuum@1bfef9a)) * Clean Up by Deleting Unconnected Nodes after Modifier Solve ([Quantinuum#1557](Quantinuum#1557)) ([d706867](Quantinuum@d706867)) * expose the QSystemPass to Python ([Quantinuum#1556](Quantinuum#1556)) ([394a610](Quantinuum@394a610)) * InlineFunctionsPass ([Quantinuum#1524](Quantinuum#1524)) ([f40dcef](Quantinuum@f40dcef)) * InlineHint metadata ([Quantinuum#1532](Quantinuum#1532)) ([e7949c2](Quantinuum@e7949c2)) ### Bug Fixes * Apply modifiers through function calls ([Quantinuum#1531](Quantinuum#1531)) ([6a13f0c](Quantinuum@6a13f0c)) * Incorrect matching of pytket parameters to unsupported graph ports ([Quantinuum#1561](Quantinuum#1561)) ([4fc5a25](Quantinuum@4fc5a25)) * Passes with Nested Modifier ([Quantinuum#1546](Quantinuum#1546)) ([bf6df51](Quantinuum@bf6df51)) * Update examples link in README.md ([Quantinuum#1506](Quantinuum#1506)) ([9a25ec8](Quantinuum@9a25ec8)) ### Documentation * Simplify package description. ([Quantinuum#1547](Quantinuum#1547)) ([54e855f](Quantinuum@54e855f)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: Agustín Borgna <agustin.borgna@quantinuum.com>
## 🤖 New release * `tket`: 0.18.0 -> 0.19.0 (✓ API compatible changes) * `tket-qsystem`: 0.24.0 -> 0.25.0 (✓ API compatible changes) <details><summary><i><b>Changelog</b></i></summary><p> ## `tket` <blockquote> ## [0.19.0](Quantinuum/tket2@tket-v0.18.0...tket-v0.19.0) - 2026-05-28 ### Bug Fixes - Apply modifiers through function calls ([Quantinuum#1531](Quantinuum#1531)) - Incorrect matching of pytket parameters to unsupported graph ports ([Quantinuum#1561](Quantinuum#1561)) - [**breaking**] Passes with Nested Modifier ([Quantinuum#1546](Quantinuum#1546)) - bug in hugr building when `control` modifiers are nested ([Quantinuum#1550](Quantinuum#1550)) - Multiple fixes to the pytket encoder ([Quantinuum#1566](Quantinuum#1566)) - [**breaking**] Replace non-deterministic iterations on hash maps ([Quantinuum#1582](Quantinuum#1582)) - Set inputs of functions loaded as values to top during dataflow analysis ([Quantinuum#1595](Quantinuum#1595)) - Using indexes inside dagger modifier ([Quantinuum#1588](Quantinuum#1588)) - address Miri unsoundness by installing nextest and skipping FFI/long running tests ([Quantinuum#1565](Quantinuum#1565)) - skip test_nested_array to resolve miri unsoundness ([Quantinuum#1623](Quantinuum#1623)) ### New Features - *(const-fold)* combine Consts for each out-port; write prepopulated inputs ([Quantinuum#1489](Quantinuum#1489)) - InlineFunctionsPass ([Quantinuum#1524](Quantinuum#1524)) - upgrade to hugr v0.27.1 ([Quantinuum#1568](Quantinuum#1568)) - [**breaking**] Ignore empty circuits when encoding Hugr regions into pytket ([Quantinuum#1562](Quantinuum#1562)) - Add python definitions for the TKET metadata keys ([Quantinuum#1535](Quantinuum#1535)) - Clean Up by Deleting Unconnected Nodes after Modifier Solve ([Quantinuum#1557](Quantinuum#1557)) - InlineHint metadata ([Quantinuum#1532](Quantinuum#1532)) - Allowing control flow in `control` ([Quantinuum#1603](Quantinuum#1603)) ### Performance - Improve modifier resolver pass by visiting nodes in a set ([Quantinuum#1621](Quantinuum#1621)) - Avoid string formatting in Hugr op hashing ([Quantinuum#1624](Quantinuum#1624)) ### Refactor - Replace portgraph toposort in CommandIterator with node vector ([Quantinuum#1608](Quantinuum#1608)) - [**breaking**] Deprecate commands iterator ([Quantinuum#1611](Quantinuum#1611)) ### Testing - Pin guppy version in example files, fix test ([Quantinuum#1534](Quantinuum#1534)) - Skip slow modifier test ([Quantinuum#1587](Quantinuum#1587)) - Add modifier test for subscripted control qubits ([Quantinuum#1601](Quantinuum#1601)) </blockquote> ## `tket-qsystem` <blockquote> ## [0.25.0](Quantinuum/tket2@tket-qsystem-v0.24.0...tket-qsystem-v0.25.0) - 2026-05-28 ### Bug Fixes - Multiple fixes to the pytket encoder ([Quantinuum#1566](Quantinuum#1566)) - [**breaking**] Replace non-deterministic iterations on hash maps ([Quantinuum#1582](Quantinuum#1582)) ### New Features - expose the QSystemPass to Python ([Quantinuum#1556](Quantinuum#1556)) - upgrade to hugr v0.27.1 ([Quantinuum#1568](Quantinuum#1568)) - [**breaking**] Ignore empty circuits when encoding Hugr regions into pytket ([Quantinuum#1562](Quantinuum#1562)) - *(qsystem)* [**breaking**] multiple platform extensions ([Quantinuum#1567](Quantinuum#1567)) ### Refactor - [**breaking**] Deprecate commands iterator ([Quantinuum#1611](Quantinuum#1611)) ### Testing - Pin guppy version in example files, fix test ([Quantinuum#1534](Quantinuum#1534)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/).
Follow up to Quantinuum/hugr#1524. Defines a metadata value for hinting the compiler on which functions to inline.
Part of #1804.
Note that this definition is rust-only. We still need to add exports for all tket metadata definitions on the python bindings.
Guppy issue/PR (they'll need to be updated):