refactor(metadata)!: Migrate all metadata keys onto the new metadata traits#1328
refactor(metadata)!: Migrate all metadata keys onto the new metadata traits#1328maximilianruesch merged 31 commits intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1328 +/- ##
==========================================
- Coverage 79.77% 79.59% -0.19%
==========================================
Files 158 158
Lines 20509 20505 -4
Branches 19542 19538 -4
==========================================
- Hits 16362 16321 -41
- Misses 3168 3203 +35
- Partials 979 981 +2
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:
|
3b4efbe to
c7a2221
Compare
|
Ensure the "BREAKING CHANGE: " notice is always at the bottom of the description |
tket/src/serialize/pytket/decoder.rs
Outdated
| .set_metadata::<metadata::Phase>(node, &serialcirc.phase); | ||
| dfg.hugr_mut() | ||
| .set_metadata_any(node, METADATA_Q_REGISTERS, json!(serialcirc.qubits)); | ||
| .set_metadata::<metadata::QubitRegisters>(node, serialcirc.qubits.clone()); // TODO Do we find something better than clone? |
There was a problem hiding this comment.
The question is whether we find something that avoids the clone, whether it is inevitable, or whether it should be cheap enough to remain. Might be the last case if it is a small vec of ints.
There was a problem hiding this comment.
Outcome: The clone here is not avoidable without major changes to the function interface, and it seems to be cheap. It shall be fine.
tket/src/serialize/pytket/tests.rs
Outdated
| hugr.entrypoint(), | ||
| METADATA_INPUT_PARAMETERS, | ||
| serde_json::json!(["alpha", "beta"]), | ||
| vec![String::from("alpha"), String::from("beta")], |
There was a problem hiding this comment.
nit: "".to_string() is standard and a bit more concise
tket/src/metadata.rs
Outdated
| @@ -0,0 +1,75 @@ | |||
| //! (Incomplete) Collection of metadata keys used throughout tket. | |||
There was a problem hiding this comment.
Seems to be an oversight, the collection was previously incomplete, but now every key should be in here.
tket/src/metadata.rs
Outdated
|
|
||
| /// Metadata key for the number of qubits that a HUGR node expects to be required for execution. | ||
| /// | ||
| /// This value is only valid when set at the entrypoint function node. TODO discuss this |
There was a problem hiding this comment.
Outcome: The comment will be removed. We will not enforce any constraints.
tket/src/metadata.rs
Outdated
| #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| pub struct MaxQubits; | ||
| impl Metadata for MaxQubits { | ||
| const KEY: &'static str = "TKET.expected_qubits"; // TODO think about this name really hard |
There was a problem hiding this comment.
this doesn't line up with the name of the struct or what is used in released guppy
There was a problem hiding this comment.
Also a source of discussion, since we want to rename the key. We now have yet another opportunity to rename it, before we use it in tket somewhere.
Alternatively, we could decide that we only want to introduce the key when we actually use it in tket, but we should decide on a name pretty soon imo.
There was a problem hiding this comment.
Outcome: Guppy uses tket.hint.max_qubits, so we will use that.
| pub struct MaxQubits; | ||
| impl Metadata for MaxQubits { | ||
| const KEY: &'static str = "TKET.expected_qubits"; // TODO think about this name really hard | ||
| type Type<'hugr> = u32; |
There was a problem hiding this comment.
is the 'hugr lifetime annotation required if it is not used?
There was a problem hiding this comment.
Yes, since the trait specifies Type to have a generic lifetime parameter and that must be specified as far as I know, even if unused. It can have any name, but for consistency I chose 'hugr
tket/src/metadata.rs
Outdated
|
|
||
| /// Metadata key for flagging unitarity constraints on a HUGR node | ||
| /// | ||
| /// See crate::modifier::ModifierFlags TODO discuss this |
There was a problem hiding this comment.
Leftover, will be removed.
tket/src/metadata.rs
Outdated
| type Type<'hugr> = u8; | ||
| } | ||
|
|
||
| // Metadata keys migrated from TKET1 |
There was a problem hiding this comment.
| // Metadata keys migrated from TKET1 | |
| // Metadata keys used for TKET1 compatibility |
|
This PR contains breaking changes to the public Rust API. cargo-semver-checks summary |
## 🤖 New release * `tket`: 0.16.0 -> 0.17.0 (✓ API compatible changes) * `tket-qsystem`: 0.22.0 -> 0.23.0 (✓ API compatible changes) <details><summary><i><b>Changelog</b></i></summary><p> ## `tket` <blockquote> ## [0.17.0](tket-v0.16.0...tket-v0.17.0) - 2026-02-02 ### Bug Fixes - *(encoded-circ)* Track unsupported wires between input and output ([#1224](#1224)) - Multiple fixes to the pytket encoder ([#1226](#1226)) - Don't use opgroup in pytket barrier encoding ([#1251](#1251)) - guppy_to_circuit always returns num_operations = 0 ([#1200](#1200)) - *(pytket-decoder)* Avoid QAllocating and immediately freeing qubits ([#1256](#1256)) - Encoding of opaque subgraphs with no associated qubit/bit ([#1295](#1295)) - [**breaking**] Don't rely on command params for pytket barriers ([#1298](#1298)) - Track output qubits in CircuitInfo ([#1304](#1304)) - Wrongly reused qubit IDs in pytket encoding ([#1358](#1358)) ### New Features - Deprecate local find_tuple_unpack rewrite ([#1188](#1188)) - Add CopyableExpressionAST ([#1209](#1209)) - `NormalizeGuppy` pass to simplify generated structure ([#1220](#1220)) - [**breaking**] pytket EncodedCircuit struct for in-place pytket optimisation ([#1211](#1211)) - [**breaking**] Interval is independent of resource IDs and scope position ([#1205](#1205)) - Don't translate usizes to pytket ([#1241](#1241)) - BorrowSquashPass to elide redundant borrow/return ops ([#1159](#1159)) - [**breaking**] Bump hugr to 0.25.0 ([#1325](#1325)) - Remove order edges in NormalizeGuppy pass ([#1326](#1326)) - [**breaking**] Remove deprecated unpack tuple pass ([#1387](#1387)) ### Refactor - Remove contain_qubits, use TypeUnpacker ([#1283](#1283)) - [**breaking**] Replace Subcircuit with SiblingSubgraph ([#1288](#1288)) - *(metadata)* [**breaking**] Migrate all metadata keys onto the new metadata traits ([#1328](#1328)) </blockquote> ## `tket-qsystem` <blockquote> ## [0.23.0](tket-qsystem-v0.22.0...tket-qsystem-v0.23.0) - 2026-02-02 ### Bug Fixes - [**breaking**] Don't rely on command params for pytket barriers ([#1298](#1298)) - Wrongly reused qubit IDs in pytket encoding ([#1358](#1358)) ### New Features - `NormalizeGuppy` pass to simplify generated structure ([#1220](#1220)) - Allow running arbitrary serializable pytket passes on hugrs ([#1266](#1266)) - BorrowSquashPass to elide redundant borrow/return ops ([#1159](#1159)) - [**breaking**] Bump hugr to 0.25.0 ([#1325](#1325)) - Remove order edges in NormalizeGuppy pass ([#1326](#1326)) - hide new public funcs introduced by linearization ([#1333](#1333)) ### Testing - regenerate guppy_opt examples, and count gates ([#1249](#1249)) - run pytket on guppy_opt tests, measure (very limited) success ([#1250](#1250)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/).
Migrates all metadata keys (that I know of) in
tketto use the new metadata traits introduced in HUGR, and unifies them to be in one file. This includes some debugging metadata, unitary flags, etc. Finally, some trivial fixes / simplifications are added that come as a convenience of the new metadata system.I would still argue that this is a refactor, even though a breaking refactor seems contradictional.
Related to Quantinuum/guppylang#1378
BREAKING CHANGE: Renamed the
"unitary"key to contain theTKETprefix as is standard with all other metadata keys.