Skip to content

Conversation

@aborgna-q
Copy link
Collaborator

We were writing OPAQUE_HUGR to the pytket barrier operation's opgroup when encoding opaque subgraphs, to be able to quickly check if an incoming barrier should be decoded and return errors on invalid payloads.

However, this was an invalid use of the opgroup field which caused pytket to panic when multiple operations with the same opgroup had different signatures.

This PR removes the use of that field, and adds some helpers to check the contents of a barrier payload instead.

@aborgna-q aborgna-q requested a review from a team as a code owner November 12, 2025 14:32
@aborgna-q aborgna-q requested a review from ss2165 November 12, 2025 14:32
@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.12%. Comparing base (6bc3c4e) to head (45c7f9b).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
tket/src/serialize/pytket/opaque.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1251      +/-   ##
==========================================
+ Coverage   79.06%   79.12%   +0.05%     
==========================================
  Files         160      160              
  Lines       20421    20412       -9     
  Branches    19489    19480       -9     
==========================================
+ Hits        16145    16150       +5     
+ Misses       3289     3279      -10     
+ Partials      987      983       -4     
Flag Coverage Δ
python 92.65% <ø> (ø)
qis-compiler 100.00% <ø> (ø)
rust 78.45% <95.45%> (+0.06%) ⬆️

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.

Copy link
Contributor

@acl-cqc acl-cqc left a comment

Choose a reason for hiding this comment

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

Yup, thanks @aborgna-q . Looks about as nice as I think it's possible to be given the tket1 serialization format...so pretty grotty 😆 but LGTM!

/// - `opgroup`: A tket1 operation group identifier, if any.
/// - `opgroup`: A tket1 [operation group
/// identifier](https://docs.quantinuum.com/tket/user-guide/manual/manual_circuit.html#modifying-operations-within-circuits),
/// if any.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pub wrt the whole crate so you can't just drop the param?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • It's part of the public API (custom encoders may call this function)
  • It's a generic call to emit arbitrary pytket commands, no reason not to allow custom optypes if someone wants to use them.

bits: &[TrackedBit],
params: &[LoadedParameter],
opgroup: Option<&str>,
_opgroup: Option<&str>,
Copy link
Contributor

Choose a reason for hiding this comment

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

:-( I guess there is no plan to deprecate this? (Some third-party encoder/decoder might still use it?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same here, it's part of the PytketDecoder trait. We don't lose much by giving the info to the user (pytket commands are normally an Operation + arguments + opgroup)

pub use payload::{EncodedEdgeID, OpaqueSubgraphPayload};

#[expect(deprecated)]
pub use payload::OPGROUP_OPAQUE_HUGR;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to #[deprecate] this too, or does it inherit that from the original definition?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No deprecation on re-exports, the warning is emitted if the main definition is deprecated.

/// A reference to a subgraph tracked by an `OpaqueSubgraphs` registry
/// in an [`EncodedCircuit`][super::super::circuit::EncodedCircuit]
/// structure.
#[serde(rename = "HugrExternal")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean we should declare this as a breaking PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These external payloads are meant to be short-lived, and are only valid when decoded by the same runtime that generated them.

You could make the case that we are breaking Inline payloads but I don't expect anyone to be storing pytket circuits with embedded Hugrs, with the aim to recover them atm

bits: &[TrackedBit],
params: &[LoadedParameter],
opgroup: Option<&str>,
_opgroup: Option<&str>,
Copy link
Member

Choose a reason for hiding this comment

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

deprecate parameter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

#1251 (comment)

It's part of the PytketDecoder trait. We don't lose much by giving the info to the user (pytket commands are normally an Operation + arguments + opgroup)

@aborgna-q aborgna-q added this pull request to the merge queue Nov 12, 2025
Merged via the queue into main with commit 5aa4800 Nov 12, 2025
24 checks passed
@aborgna-q aborgna-q deleted the ab/dont-set-opgroup branch November 12, 2025 16:48
@hugrbot hugrbot mentioned this pull request Nov 12, 2025
github-merge-queue bot pushed a commit that referenced this pull request Nov 13, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.12.11](tket-py-v0.12.10...tket-py-v0.12.11)
(2025-11-13)


### Bug Fixes

* **ci:** Make wheels compatible with MacOS 15.0
(#1248)
([49c5996](49c5996))
* Don't use opgroup in pytket barrier encoding
(#1251)
([49c5996](49c5996))
* guppy_to_circuit always returns num_operations = 0
(#1200)
([49c5996](49c5996))
* **pytket-decoder:** Avoid QAllocating and immediately freeing qubits
([#1256](#1256))
([228ff52](228ff52))

---
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 <[email protected]>
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.

4 participants