Skip to content

feat!: Split the pytket extension encoder trait#970

Merged
aborgna-q merged 5 commits intomainfrom
ab/encoder-trait-split
Jul 16, 2025
Merged

feat!: Split the pytket extension encoder trait#970
aborgna-q merged 5 commits intomainfrom
ab/encoder-trait-split

Conversation

@aborgna-q
Copy link
Collaborator

@aborgna-q aborgna-q commented Jul 14, 2025

Splits the type_to_pytket method out of the PytketEmitter trait implemented by extensions, and into a new TypeTranslator trait as we'll use them in the decoder trait too.

Adds a TypeTranslatorSet used by the encoder/decoder config that caches the translation, since it gets called multiple times with the same types.

BREAKING CHANGE: Moved PytketEmitter::type_to_pytket to new TypeTranslator trait.

@aborgna-q aborgna-q requested a review from a team as a code owner July 14, 2025 12:49
@aborgna-q aborgna-q requested a review from doug-q July 14, 2025 12:49
@codecov
Copy link

codecov bot commented Jul 14, 2025

Codecov Report

Attention: Patch coverage is 83.14607% with 30 lines in your changes missing coverage. Please review.

Project coverage is 79.68%. Comparing base (6017450) to head (d062945).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...t2/src/serialize/pytket/config/type_translators.rs 83.78% 9 Missing and 3 partials ⚠️
tket2/src/serialize/pytket/extension/bool.rs 37.50% 5 Missing ⚠️
tket2/src/serialize/pytket.rs 0.00% 4 Missing ⚠️
tket2/src/serialize/pytket/extension.rs 88.57% 4 Missing ⚠️
tket2/src/serialize/pytket/extension/prelude.rs 62.50% 2 Missing and 1 partial ⚠️
tket2/src/serialize/pytket/extension/float.rs 87.50% 1 Missing ⚠️
tket2/src/serialize/pytket/extension/rotation.rs 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #970      +/-   ##
==========================================
+ Coverage   79.24%   79.68%   +0.43%     
==========================================
  Files          92       95       +3     
  Lines       11206    11556     +350     
  Branches    10932    11279     +347     
==========================================
+ Hits         8880     9208     +328     
- Misses       1707     1717      +10     
- Partials      619      631      +12     
Flag Coverage Δ
python 81.58% <ø> (-0.17%) ⬇️
rust 79.63% <83.14%> (+0.45%) ⬆️

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.

@hugrbot
Copy link
Collaborator

hugrbot commented Jul 14, 2025

This PR contains breaking changes to the public Rust API.

cargo-semver-checks summary

--- failure enum_no_repr_variant_discriminant_changed: enum variant had its discriminant change value ---

Description:
The enum's variant had its discriminant value change. This breaks downstream code that used its value via a numeric cast like `as isize`.
      ref: https://doc.rust-lang.org/reference/items/enumerations.html#assigning-discriminant-values
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.42.0/src/lints/enum_no_repr_variant_discriminant_changed.ron

Failed in:
variant OpConvertError::MissingSerialisedParams 1 -> 0 in /home/runner/work/tket2/tket2/PR_BRANCH/tket2/src/serialize/pytket.rs:188
variant OpConvertError::MissingSerialisedArguments 2 -> 1 in /home/runner/work/tket2/tket2/PR_BRANCH/tket2/src/serialize/pytket.rs:201
variant OpConvertError::WireHasNoValues 3 -> 2 in /home/runner/work/tket2/tket2/PR_BRANCH/tket2/src/serialize/pytket.rs:215
variant OpConvertError::WireAlreadyHasValues 4 -> 3 in /home/runner/work/tket2/tket2/PR_BRANCH/tket2/src/serialize/pytket.rs:223

--- failure enum_variant_missing: pub enum variant removed or renamed ---

Description:
A publicly-visible enum has at least one variant that is no longer available under its prior name. It may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.42.0/src/lints/enum_variant_missing.ron

Failed in:
variant OpConvertError::UnsupportedOpSerialization, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket2/src/serialize/pytket.rs:183

--- failure function_missing: pub fn removed or renamed ---

Description:
A publicly-visible function cannot be imported by its prior path. A `pub use` may have been removed, or the function itself may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.42.0/src/lints/function_missing.ron

Failed in:
function tket2::serialize::pytket::encoder::default_encoder_config, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket2/src/serialize/pytket/encoder/config.rs:29

--- failure module_missing: pub module removed or renamed ---

Description:
A publicly-visible module cannot be imported by its prior path. A `pub use` may have been removed, or the module may have been renamed, removed, or made non-public.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.42.0/src/lints/module_missing.ron

Failed in:
mod tket2::extension::guppy, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket2/src/extension/guppy.rs:1

--- failure pub_module_level_const_missing: pub module-level const is missing ---

Description:
A public const is missing or renamed
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.42.0/src/lints/pub_module_level_const_missing.ron

Failed in:
GUPPY_EXTENSION_VERSION in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket2/src/extension/guppy.rs:17
DROP_OP_NAME in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket2/src/extension/guppy.rs:20
GUPPY_EXTENSION_ID in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket2/src/extension/guppy.rs:15

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.42.0/src/lints/struct_missing.ron

Failed in:
struct tket2::serialize::pytket::encoder::RegisterCount, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket2/src/serialize/pytket/encoder/value_tracker.rs:192
struct tket2::serialize::pytket::encoder::Tk1EncoderConfig, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket2/src/serialize/pytket/encoder/config.rs:47
struct tket2::extension::guppy::GUPPY_EXTENSION, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket2/src/extension/guppy.rs:22

--- failure trait_method_missing: pub trait method removed or renamed ---

Description:
A trait method is no longer callable, and may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#major-any-change-to-trait-item-signatures
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.42.0/src/lints/trait_method_missing.ron

Failed in:
method type_to_pytket of trait PytketEmitter, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket2/src/serialize/pytket/extension.rs:82
method type_to_pytket of trait PytketEmitter, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket2/src/serialize/pytket/extension.rs:82

Copy link
Contributor

@doug-q doug-q left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, I never submitted the review.

I think it would be could to fix the missing coverage in TypeTranslatorSet

///
/// This is used both during encoding and decoding of pytket operations and
/// types.
pub trait TypeTranslator {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed to PytketTypeTransformer

params: 0,
});
}
if let Some(tuple) = sum.as_tuple() {
Copy link
Contributor

Choose a reason for hiding this comment

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

no coverage here

vec![BOOL_EXTENSION_ID]
}

fn type_to_pytket(&self, typ: &hugr::types::CustomType) -> Option<RegisterCount> {
Copy link
Contributor

Choose a reason for hiding this comment

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

No coverage.

You don't check the extension. I suppose this is Ok, but I recommend you at least document in the trait that typ is guaranteed to have an extension matching the result of extensions.

@aborgna-q aborgna-q force-pushed the ab/encoder-trait-split branch from 1f63401 to d062945 Compare July 16, 2025 12:27
@aborgna-q aborgna-q added this pull request to the merge queue Jul 16, 2025
Merged via the queue into main with commit 8c9b810 Jul 16, 2025
21 checks passed
@aborgna-q aborgna-q deleted the ab/encoder-trait-split branch July 16, 2025 12:51
@hugrbot hugrbot mentioned this pull request Jul 16, 2025
This was referenced Jul 25, 2025
jennyQuantinuum pushed a commit that referenced this pull request Jul 27, 2025
Splits the `type_to_pytket` method out of the `PytketEmitter` trait
implemented by extensions, and into a new `TypeTranslator` trait as
we'll use them in the decoder trait too.

Adds a `TypeTranslatorSet` used by the encoder/decoder config that
caches the translation, since it gets called multiple times with the
same types.

BREAKING CHANGE: Moved `PytketEmitter::type_to_pytket` to new
`TypeTranslator` trait.

---------

Co-authored-by: Douglas Wilson <141026920+doug-q@users.noreply.github.com>
github-merge-queue bot pushed a commit that referenced this pull request Jul 28, 2025
## 🙂  New release

* `tket2`: 0.12.3 -> `tket` 0.13.0 (New crate name!)
* `tket2-hseries`: 0.16.1 -> `tket-qsystem` 0.17.0 (New crate name!)

<details><summary><i><b>Changelog</b></i></summary><p>

## `tket`

<blockquote>

##
[0.13.0](tket2-v0.12.3...tket-v0.13.0)
- 2025-07-25

### New Features

- [**breaking] Rename tket2.* HUGR extensions to tket.*
([#988](#988))
- [**breaking] Rename tket2* libs to tket*
([#987](#987))
- [**breaking**] Update to `hugr 0.21`
([#965](#965))
- Add guppy extension with drop operation
([#962](#962))
- [**breaking**] Split the pytket extension encoder trait
([#970](#970))
</blockquote>

## `tket-qsystem`

<blockquote>

##
[0.17.0](tket2-hseries-v0.16.1...tket-qsystem-v0.17.0)
- 2025-07-25

### New Features

- [**breaking] Rename tket2.* HUGR extensions to tket.*
([#988](#988))
- [**breaking] Rename tket2* libs to tket*
([#987](#987))
- [**breaking**] Update to `hugr 0.21`
([#965](#965))
- Add guppy extension with drop operation
([#962](#962))
</blockquote>


</p></details>

---
This PR was generated by a human.
croyzor pushed a commit that referenced this pull request Aug 11, 2025
## 🙂  New release

* `tket2`: 0.12.3 -> `tket` 0.13.0 (New crate name!)
* `tket2-hseries`: 0.16.1 -> `tket-qsystem` 0.17.0 (New crate name!)

<details><summary><i><b>Changelog</b></i></summary><p>

## `tket`

<blockquote>

##
[0.13.0](tket2-v0.12.3...tket-v0.13.0)
- 2025-07-25

### New Features

- [**breaking] Rename tket2.* HUGR extensions to tket.*
([#988](#988))
- [**breaking] Rename tket2* libs to tket*
([#987](#987))
- [**breaking**] Update to `hugr 0.21`
([#965](#965))
- Add guppy extension with drop operation
([#962](#962))
- [**breaking**] Split the pytket extension encoder trait
([#970](#970))
</blockquote>

## `tket-qsystem`

<blockquote>

##
[0.17.0](tket2-hseries-v0.16.1...tket-qsystem-v0.17.0)
- 2025-07-25

### New Features

- [**breaking] Rename tket2.* HUGR extensions to tket.*
([#988](#988))
- [**breaking] Rename tket2* libs to tket*
([#987](#987))
- [**breaking**] Update to `hugr 0.21`
([#965](#965))
- Add guppy extension with drop operation
([#962](#962))
</blockquote>


</p></details>

---
This PR was generated by a human.
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