-
Notifications
You must be signed in to change notification settings - Fork 9
feat: Define a wire tracker for the new pytket decoder #1036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1036 +/- ##
==========================================
- Coverage 79.74% 78.03% -1.72%
==========================================
Files 97 99 +2
Lines 11674 12208 +534
Branches 11395 11929 +534
==========================================
+ Hits 9309 9526 +217
- Misses 1734 2049 +315
- Partials 631 633 +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:
|
420e3ac
to
fbb74ac
Compare
a92a1d2
to
0bb0c43
Compare
} | ||
} | ||
|
||
/// Tracked wires to a pytket operation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what this docstring means
/// Return an iterator over the wires and their types. | ||
/// | ||
/// This returns the wires as-is, without any additional conversions. | ||
/// If you need to retrieve a specific wire type, use TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover comment from the automated type translation work. Removed.
|
||
/// Returns the tracked qubit elements in the set of wires as an array. | ||
#[inline] | ||
pub fn qubits_arr<const N: usize>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no array equivalent for bits?
do all of these need to be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main object that implementors of decoders interact with when doing operation translations, so I tried to add some useful helpers.
This one (in contrast to wires_arr
) is just a collect_arr
wrapper, so I removed it.
/// operation, all previous references to it become "outdated". | ||
#[derive(Debug, Clone, Default)] | ||
pub struct WireTracker { | ||
/// A list of tracked wires, with their type and list of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list or map? outdated docstring?
/// | ||
/// * `hugr` - The hugr to add the wires to. | ||
/// * `args` - The list of pytket element ids to map to wires. | ||
/// * `operation` - The name of the operation being decoded, used for error reporting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it is only used for error reporting shouldn't it be added as context by the calling function instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a change copying the model ImportError
/ ImportErrorInner
structure,
so we can add the context later and remove these parameters.
@ss2165 I ended up going and adding a last commit simplifying the tracker logic after the review. Sorry 😬 |
reg: Arc<PytketRegister>, | ||
/// The hash of the pytket register for this tracked element, used to | ||
/// speed up hashing and equality checks. | ||
reg_hash: RegisterHash, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally these two should be in a struct by themselves - they're not independent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally intended to put this inside the Arc, but RegisterHash
is a single byte so it's cheaper to just have it here.
I guess we could add an intermediary
pub struct PytketResource {
element: Arc<tket_json_rs::register::ElementId>,
hash: RegisterHash,
}
I'll add a TODO
- Adds a `PytketDecoder` trait that let us extend the decoding framework to external extensions. - Translations are no longer 1-to-1 between pytket commands and hugr ops, the decoding call has access to a hugr builder and its context. - Allows tracking wires with complex/composite types. We don't provide helpers to convert types yet, it's up to the extension emitter to look at the incoming wire types. (Note: I splitted this change to a previous PR, #1036) TODO: - [x] Implement the decoder trait for all standard extensions. - [x] Fix remaining test errors. - [ ] Add a nicer guide for writing extension traits in the module docs. BREAKING CHANGE: Split pytket encoder/decoder errors into separate structs.
## 🤖 New release * `tket`: 0.13.2 -> 0.14.0 (✓ API compatible changes) * `tket-qsystem`: 0.18.1 -> 0.19.0 (✓ API compatible changes) <details><summary><i><b>Changelog</b></i></summary><p> ## `tket` <blockquote> ## [0.14.0](tket-v0.13.2...tket-v0.14.0) - 2025-08-18 ### New Features - [**breaking**] Allow PytketTypeTranslators to translate nested types ([#1038](#1038)) - Define a wire tracker for the new pytket decoder ([#1036](#1036)) - [**breaking**] Reworked pytket decoder framework ([#1030](#1030)) - [**breaking**] Use qsystem encoder/decoders in tket-py ([#1041](#1041)) - [**breaking**] Avoid eagerly cloning SerialCircuits when decoding from pytket ([#1048](#1048)) ### Refactor - [**breaking**] Rename tk2 encoder names to tket ([#1037](#1037)) </blockquote> ## `tket-qsystem` <blockquote> ## [0.19.0](tket-qsystem-v0.18.1...tket-qsystem-v0.19.0) - 2025-08-18 ### New Features - Add emitters for tket-qsystem ([#1039](#1039)) - [**breaking**] Avoid eagerly cloning SerialCircuits when decoding from pytket ([#1048](#1048)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/).
🤖 I have created a release *beep* *boop* --- ## [0.12.2](tket-py-v0.12.1...tket-py-v0.12.2) (2025-08-19) ### Features * Define a wire tracker for the new pytket decoder ([#1036](#1036)) ([2466ee2](2466ee2)) * Support qsystem native operations when loading pytket circuits ([#1041](#1041)) ([88c5c79](88c5c79)) * **tket-py:** Create BadgerOptimiser from arbitrary Rewriters ([#1022](#1022)) ([a975c1d](a975c1d)), closes [#1021](#1021) ### Documentation * Update README badges ([#1004](#1004)) ([d609bf5](d609bf5)) --- 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>
🤖 I have created a release *beep* *boop* --- ## [0.12.2](tket-py-v0.12.1...tket-py-v0.12.2) (2025-08-19) ### Features * Define a wire tracker for the new pytket decoder ([#1036](#1036)) ([2466ee2](2466ee2)) * Support qsystem native operations when loading pytket circuits ([#1041](#1041)) ([88c5c79](88c5c79)) * **tket-py:** Create BadgerOptimiser from arbitrary Rewriters ([#1022](#1022)) ([a975c1d](a975c1d)), closes [#1021](#1021) ### Documentation * Update README badges ([#1004](#1004)) ([d609bf5](d609bf5)) --- 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>
Defines a
WireTracker
struct for the pytket decoder framework.It keeps track of wires that have been added to the HUGR being created along with which qubit/bit/parameter elements each of them carries (wires may carry multiple, see
PytketTypeTranslator
in::serialize::pytket::extensions
.The tracker lets us associate new wires with registers/parameters, and updates previous references so they know they don't have the latest pytket register value.
In the future we'll expand this tracker to let us do automatic type translations (e.g. unpacking a tuple), as defined by the extension decoders.
Also adds a new
Tk1DecodeError
that will be used by the decoder framework.Depends on #1035