-
Notifications
You must be signed in to change notification settings - Fork 8
feat!: Reworked pytket decoder framework #1030
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
This PR contains breaking changes to the public Rust API. cargo-semver-checks summary
|
273b870
to
e5d3128
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1030 +/- ##
==========================================
+ Coverage 78.03% 78.47% +0.43%
==========================================
Files 99 98 -1
Lines 12208 12461 +253
Branches 11929 12182 +253
==========================================
+ Hits 9527 9779 +252
+ Misses 2048 2035 -13
- Partials 633 647 +14
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:
|
Marking this as ready for release.
|
fccf400
to
8fef667
Compare
ab2dffe
to
fd0e745
Compare
fd0e745
to
1f3cb42
Compare
420e3ac
to
fbb74ac
Compare
a92a1d2
to
0bb0c43
Compare
1f3cb42
to
e4e7686
Compare
d9d9e28
to
d53d071
Compare
d53d071
to
c32be5d
Compare
c32be5d
to
317d5ee
Compare
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.
Very cool! None of my comments should take long to resolve, so I think we can definitely merge this in today.
dfg.set_metadata(METADATA_Q_OUTPUT_REGISTERS, json!(output_qubits)); | ||
dfg.set_metadata(METADATA_B_OUTPUT_REGISTERS, json!(output_bits)); |
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 know this is outside this PR's diff, but hear me out:
It seems you only store the implicit_permutation
as metadata. If this code is also used to load pytket circuits into HUGR, then the user would presumably expect that the HUGR respects the permutation, i.e. that the order of the outputs are shuffled accrodingly...
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.
We take care of that in the hugr->pytket encoder logic :)
tket2/tket/src/serialize/pytket/encoder/value_tracker.rs
Lines 480 to 482 in 99f568b
// Compute the final register permutations. | |
let (qubit_outputs, qubit_permutation) = | |
compute_final_permutation(qubit_outputs, &self.qubits, &self.output_qubits); |
We compute the permutation from the registers we see at the output, and compose it with any METADATA_{B,Q}_OUTPUT_REGISTERS
metadata originating from pytket.
That lets us do hugr rewrites that swap qubits around without caring about the pytket repr.
(We are surely missing tests for that though...)
/// | ||
/// A [decoder configuration](crate::serialize::pytket::PytketDecoderConfig) | ||
/// contains a list of such decoders. | ||
pub trait PytketDecoder { |
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.
Can you add a mention of PytketDecoder
to the module docs?
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.
Added a paragraph. We'll expand the module docs in a followup PR
use hugr::extension::simple_op::MakeExtensionOp; | ||
use hugr::extension::ExtensionId; | ||
use hugr::ops::ExtensionOp; | ||
use hugr::ops::{ExtensionOp, OpType}; | ||
use hugr::types::TypeArg; | ||
use hugr::HugrView; | ||
use tket_json_rs::optype::OpType as Tk1OpType; |
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.
Rename to PytketOpType
?
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 tried, but we decided not to.
#1037
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.
ok got it, but this would just be a file-local rename... You can probably do it 🙃
Urgh, I used github's PR VSCode extension, and it's very buggy. It lost some of the comments I had made. I've added them back myself, as far as I could remember, hopefully I didn't miss anything important :( |
Coverage seems to say that |
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.
Awesome, thanks a lot!
Just one more suggestion: consider using "Resource" instead of "Wire", when referring to pytket wires. E.g. ResourceTracker
instead of WireTracker
.
Would be good if "wire" only referred to HUGR wires :)
EDIT: Reposting my earlier message that might have been lost:
Coverage seems to say that impl PytketDecoder for BoolEmitter is not tested? Might be worth adding a test for that...
use hugr::extension::simple_op::MakeExtensionOp; | ||
use hugr::extension::ExtensionId; | ||
use hugr::ops::ExtensionOp; | ||
use hugr::ops::{ExtensionOp, OpType}; | ||
use hugr::types::TypeArg; | ||
use hugr::HugrView; | ||
use tket_json_rs::optype::OpType as Tk1OpType; |
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.
ok got it, but this would just be a file-local rename... You can probably do it 🙃
let wire_tracker = Self::init_wire_tracker( | ||
serialcirc, | ||
&mut dfg, | ||
&signature.input, |
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.
nit: you can probably recover the input types from the dfg, and avoid a signature.clone()
above?
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.
We're passing &mut dfg
around, so we can't have a reference to the signature -.-
@@ -110,7 +114,7 @@ pub trait PytketDecoder { | |||
|
|||
/// Given a pytket [`tket_json_rs::circuit_json::Operation`] node in the | |||
/// HUGR circuit and its operation type, try to convert it to a pytket | |||
/// operation and add it to the pytket encoder. | |||
/// operation and add it to the pytket decoder. | |||
/// | |||
/// Returns an [`DecodeStatus`] indicating if the operation was successfully | |||
/// converted. If the operation is not supported by the encoder, it's |
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.
/// converted. If the operation is not supported by the encoder, it's | |
/// converted. If the operation is not supported by the decoder, it's |
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.
also on the two lines below.
We could use some documentation standarisation about those terms, but thankfully they are all private types so we can rename them later 🤷 |
## 🤖 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/).
PytketDecoder
trait that let us extend the decoding framework to external extensions.TODO:
BREAKING CHANGE: Split pytket encoder/decoder errors into separate structs.