feat: Capture pytket's output permutation explicitly in the hugr connectivity#1075
feat: Capture pytket's output permutation explicitly in the hugr connectivity#1075
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1075 +/- ##
==========================================
+ Coverage 79.01% 79.09% +0.07%
==========================================
Files 115 115
Lines 13416 13390 -26
Branches 12634 12608 -26
==========================================
- Hits 10601 10591 -10
+ Misses 2158 2144 -14
+ Partials 657 655 -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:
|
e9fc8b9 to
b1891f4
Compare
lmondada
left a comment
There was a problem hiding this comment.
I think there is an error in your docs, but otherwise I like it. This makes more sense to me than the metadata trick you had before.
One question: does this represent a breaking change in serialisation? I.e. are there circuits that users may have stored for which the ordering of the outputs will not be parsed properly?
| /// This originates from pytket's `implicit_permutation` field. | ||
| /// | ||
| /// For a circuit with three qubit registers [q0, q1, q2] and an implicit | ||
| /// permutation {q0 -> q1, q1 -> q2, q2 -> q0}, `output_to_input` will be {1 |
There was a problem hiding this comment.
I don't think output_to_input refers to anything anymore. Update?
| /// A map from pytket register hashes to the latest up-to-date [`TrackedQubit`] referencing it. | ||
| /// | ||
| /// The map keys are kept in the order they were defined in the circuit. | ||
| /// The map keys are kept in the order we expect to see them at the circuits output. |
There was a problem hiding this comment.
I'm confused. In fn known_pytket_qubits you reorder your outputs using output_qubit_permutation, so that would indicate that they are not ordered by output order?
Furthermore, this is an IndexMap, so I'm not even sure what the order would be.
There was a problem hiding this comment.
same comment 4 lines below.
There was a problem hiding this comment.
Ah, I forgot to rollback this comment after trying a change here.
IndexMap is a HashMap that keeps the insertion order of its keys, so we can traverse it / find elements by index, etc.
tket/src/serialize/pytket.rs
Outdated
| pub const METADATA_Q_REGISTERS: &str = "TKET1.qubit_registers"; | ||
| /// The reordered qubit registers in the output, if an implicit permutation was applied. | ||
| #[deprecated( | ||
| note = "Output registers now always match the input register order.", |
There was a problem hiding this comment.
I don't find this message very clear. Do you mean something like
| note = "Output registers now always match the input register order.", | |
| note = "Qubit permutations are now represented explicitly in DFG output ordering .", |
| #[deprecated( | ||
| note = "TKET.tk1op payload is stored as a op parameter, not a metadata field.", | ||
| since = "0.14.1" | ||
| )] |
There was a problem hiding this comment.
I don't understand how this deprecation relates to the rest of the PR, but that might not be important.
There was a problem hiding this comment.
Sorry, it's a drive-by added while deprecating the other constants.
Technically yes. Stored hugrs extracted from pytket circuits with The |
🤖 I have created a release *beep* *boop* --- ## [0.12.5](tket-py-v0.12.4...tket-py-v0.12.5) (2025-08-26) ### Features * Capture pytket's output permutation explicitly in the hugr connectivity ([#1075](#1075)) ([5fc9614](5fc9614)) --- 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.14.0 -> 0.15.0 (✓ API compatible changes) * `tket-qsystem`: 0.20.1 -> 0.21.0 (✓ API compatible changes) <details><summary><i><b>Changelog</b></i></summary><p> ## `tket` <blockquote> ## [0.15.0](tket-v0.14.0...tket-v0.15.0) - 2025-09-15 ### Bug Fixes - [**breaking**] Fix rotation -> float param type conversion ([#1061](#1061)) - Pytket barrier operations not being decoded ([#1069](#1069)) - Always load parameter expressions as half turns in the decoder ([#1083](#1083)) - Move attribute to come after all the cases. ([#1112](#1112)) ### New Features - Capture pytket's output permutation explicitly in the hugr connectivity ([#1075](#1075)) - Add ResourceScope ([#1052](#1052)) - [**breaking**] Remove unnecessary Arc from PytketDecoder method ([#1114](#1114)) - [**breaking**] Remove deprecated definitions ([#1113](#1113)) </blockquote> ## `tket-qsystem` <blockquote> ## [0.21.0](tket-qsystem-v0.20.1...tket-qsystem-v0.21.0) - 2025-09-15 ### Bug Fixes - [**breaking**] Fix rotation -> float param type conversion ([#1061](#1061)) - Pytket barrier operations not being decoded ([#1069](#1069)) - *(qystem)* fix angle bug in CZ decomposition ([#1080](#1080)) - Always load parameter expressions as half turns in the decoder ([#1083](#1083)) ### New Features - Add a `borrow_array` type replacement pass ([#975](#975)) - Add gpu module ([#1090](#1090)) - [**breaking**] Remove unnecessary Arc from PytketDecoder method ([#1114](#1114)) - [**breaking**] Remove deprecated definitions ([#1113](#1113)) ### Refactor - [**breaking**] Factor out wasm extension code into compute module ([#1089](#1089)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/). --------- Co-authored-by: Agustín Borgna <121866228+aborgna-q@users.noreply.github.com> Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com>
Now the permutation gets reflected in the wire structure.
A
(circ := Circuit(2).SWAP(0,1)).replace_SWAPs()now gets encoded directly asgraph LR subgraph 0 ["(0) Module"] direction LR subgraph 1 ["(1) [**FuncDefn: #quot;#quot;**]"] direction LR style 1 stroke:#832561,stroke-width:3px 2["(2) Input"] 3["(3) Output"] 2--"0:1<br>qubit"-->3 2--"1:0<br>qubit"-->3 end endBefore we only stored the permutation in the circuit's metadata