Skip to content

Conversation

aborgna-q
Copy link
Collaborator

@aborgna-q aborgna-q commented Aug 15, 2025

Depends on #1039

  • Adds an optional config parameter to all the load_tk1 / save_tk1 utilities, so we don't use the default by mistake.
  • Uses the new qsystem encoder/decoders in tket-py, so now we can load ZZMax/ZZPhase/PhasedX

BREAKING CHANGE: Added encode/decode config arguments to pytket load/store utilities

This is not a breaking change for the python lib, so I'll override the flag for release-please:

BEGIN_COMMIT_OVERRIDE

feat: Support qsystem native operations when loading pytket circuits (#1041)

END_COMMIT_OVERRIDE

@aborgna-q aborgna-q requested a review from ss2165 August 15, 2025 15:19
@aborgna-q aborgna-q requested a review from a team as a code owner August 15, 2025 15:19
Copy link

codecov bot commented Aug 15, 2025

Codecov Report

❌ Patch coverage is 32.69231% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.28%. Comparing base (5514164) to head (6ee9aa6).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
tket/src/serialize/pytket.rs 38.46% 23 Missing and 1 partial ⚠️
badger-optimiser/src/main.rs 0.00% 9 Missing ⚠️
tket/src/serialize/pytket/encoder.rs 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1041      +/-   ##
==========================================
- Coverage   78.41%   78.28%   -0.13%     
==========================================
  Files         102      102              
  Lines       12641    12667      +26     
  Branches    12362    12388      +26     
==========================================
+ Hits         9912     9916       +4     
- Misses       2077     2099      +22     
  Partials      652      652              
Flag Coverage Δ
python 81.00% <ø> (ø)
rust 78.22% <32.69%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aborgna-q
Copy link
Collaborator Author

Testing anything with the Tk2Circuit interface is terrible, but I added a simple check to ensure it works.
We'll have to do something more comprehensive later.

Comment on lines +69 to +71
# Check that we didn't use the opaque tk1 op fallback.
# TODO: There's no way to traverse the circuit nodes??
assert "TKET1.tk1op" not in tk1_dot
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x.x

At least we can check that we're doing the right thing in the render

graph 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"]
            4["(4) const:custom:f64(0.75)"]
            5["(5) LoadConstant"]
            6["(6) tket.qsystem.ZZPhase"]
            7["(7) const:custom:f64(0.25)"]
            8["(8) LoadConstant"]
            9["(9) const:custom:f64(0.33)"]
            10["(10) LoadConstant"]
            11["(11) tket.qsystem.PhasedX"]
            2--"0:0<br>qubit"-->6
            2--"1:1<br>qubit"-->6
            4--"0:0<br>float64"-->5
            5--"0:2<br>float64"-->6
            6--"0:0<br>qubit"-->3
            6--"1:0<br>qubit"-->11
            7--"0:0<br>float64"-->8
            8--"0:1<br>float64"-->11
            9--"0:0<br>float64"-->10
            10--"0:2<br>float64"-->11
            11--"0:1<br>qubit"-->3
        end
    end
Loading

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes

@aborgna-q aborgna-q force-pushed the ab/custom-config-loading branch from 5f16398 to 40e1fb9 Compare August 15, 2025 15:42
Base automatically changed from ab/decoder-qsystem to main August 15, 2025 16:16
@aborgna-q aborgna-q force-pushed the ab/custom-config-loading branch from 40e1fb9 to 6ee9aa6 Compare August 15, 2025 16:19
@hugrbot
Copy link
Collaborator

hugrbot commented Aug 15, 2025

This PR contains breaking changes to the public Rust API.

cargo-semver-checks summary

--- failure function_parameter_count_changed: pub fn parameter count changed ---

Description:
A publicly-visible function now takes a different number of parameters.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#fn-change-arity
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.43.0/src/lints/function_parameter_count_changed.ron

Failed in:
tket::serialize::pytket::load_tk1_json_str now takes 2 parameters instead of 1, in /home/runner/work/tket2/tket2/PR_BRANCH/tket/src/serialize/pytket.rs:164
tket::serialize::load_tk1_json_str now takes 2 parameters instead of 1, in /home/runner/work/tket2/tket2/PR_BRANCH/tket/src/serialize/pytket.rs:164
tket::serialize::pytket::save_tk1_json_str now takes 2 parameters instead of 1, in /home/runner/work/tket2/tket2/PR_BRANCH/tket/src/serialize/pytket.rs:226
tket::serialize::save_tk1_json_str now takes 2 parameters instead of 1, in /home/runner/work/tket2/tket2/PR_BRANCH/tket/src/serialize/pytket.rs:226
tket::serialize::pytket::load_tk1_json_file now takes 2 parameters instead of 1, in /home/runner/work/tket2/tket2/PR_BRANCH/tket/src/serialize/pytket.rs:137
tket::serialize::load_tk1_json_file now takes 2 parameters instead of 1, in /home/runner/work/tket2/tket2/PR_BRANCH/tket/src/serialize/pytket.rs:137
tket::serialize::pytket::save_tk1_json_file now takes 3 parameters instead of 2, in /home/runner/work/tket2/tket2/PR_BRANCH/tket/src/serialize/pytket.rs:183
tket::serialize::save_tk1_json_file now takes 3 parameters instead of 2, in /home/runner/work/tket2/tket2/PR_BRANCH/tket/src/serialize/pytket.rs:183
tket::serialize::pytket::load_tk1_json_reader now takes 2 parameters instead of 1, in /home/runner/work/tket2/tket2/PR_BRANCH/tket/src/serialize/pytket.rs:150
tket::serialize::load_tk1_json_reader now takes 2 parameters instead of 1, in /home/runner/work/tket2/tket2/PR_BRANCH/tket/src/serialize/pytket.rs:150
tket::serialize::pytket::save_tk1_json_writer now takes 3 parameters instead of 2, in /home/runner/work/tket2/tket2/PR_BRANCH/tket/src/serialize/pytket.rs:204
tket::serialize::save_tk1_json_writer now takes 3 parameters instead of 2, in /home/runner/work/tket2/tket2/PR_BRANCH/tket/src/serialize/pytket.rs:204

Comment on lines +69 to +71
# Check that we didn't use the opaque tk1 op fallback.
# TODO: There's no way to traverse the circuit nodes??
assert "TKET1.tk1op" not in tk1_dot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes



def test_conversion_qsystem():
tk1 = Circuit(2).ZZPhase(0.75, 0, 1).PhasedX(0.25, 0.33, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add zzmax as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZZMax is a bit annoying, because the roundtrip is not the identity.

We convert ZZMax to the equivalent ZZPhase(1/2) during decoding, and we extract it as is.

@@ -636,7 +626,7 @@ impl<H: HugrView> PytketEncoderContext<H> {
let config = Arc::clone(&self.config);

// Recursively encode the sub-graph.
let mut subencoder = PytketEncoderContext::new_arc(circ, node, config)?;
let mut subencoder = PytketEncoderContext::new(circ, node, config)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to have coverage of this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a simple change—adding a decoder for CircBoxes—but not part of this PR. See #44

@aborgna-q aborgna-q added this pull request to the merge queue Aug 18, 2025
Merged via the queue into main with commit 88c5c79 Aug 18, 2025
20 of 22 checks passed
@aborgna-q aborgna-q deleted the ab/custom-config-loading branch August 18, 2025 15:19
@hugrbot hugrbot mentioned this pull request Aug 18, 2025
github-merge-queue bot pushed a commit that referenced this pull request Aug 18, 2025
## 🤖 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/).
github-merge-queue bot pushed a commit that referenced this pull request Aug 19, 2025
🤖 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>
croyzor pushed a commit that referenced this pull request Aug 20, 2025
🤖 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants