Skip to content

feat!: Replace CircuitHash with hugr's implementation#1420

Merged
aborgna-q merged 3 commits intomainfrom
ab/bye-hash
Mar 3, 2026
Merged

feat!: Replace CircuitHash with hugr's implementation#1420
aborgna-q merged 3 commits intomainfrom
ab/bye-hash

Conversation

@aborgna-q
Copy link
Copy Markdown
Collaborator

@aborgna-q aborgna-q commented Feb 25, 2026

The hashing code was copied and improved in hugr-passes (Quantinuum/hugr#2840).

This breaking PR removes the old code from here. I added a new circuit_hash method to Circuit that should cover previous usages.

BREAKING CHANGE: Removed CircuitHash trait, use Circuit::circuit_hash or hugr::algorithms::hash::HugrHash instead.

Performance is the same between both implementations: bench

@hugrbot
Copy link
Copy Markdown
Collaborator

hugrbot commented Feb 25, 2026

This PR contains breaking changes to the public Rust API.

cargo-semver-checks summary
    Building tket v0.17.0 (current)
     Built [  50.143s] (current)
   Parsing tket v0.17.0 (current)
    Parsed [   0.095s] (current)
  Building tket v0.17.0 (baseline)
     Built [  44.538s] (baseline)
   Parsing tket v0.17.0 (baseline)
    Parsed [   0.087s] (baseline)
  Checking tket v0.17.0 -> v0.17.0 (assume minor change)
   Checked [   0.108s] 196 checks: 195 pass, 1 fail, 0 warn, 49 skip

--- failure trait_missing: pub trait removed or renamed ---

Description:
A publicly-visible trait cannot be imported by its prior path. A `pub use` may have been removed, or the trait 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.46.0/src/lints/trait_missing.ron

Failed in:
trait tket::circuit::CircuitHash, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/circuit/hash.rs:15

   Summary semver requires new major version: 1 major and 0 minor checks failed
  Finished [  98.121s] tket
  Building tket-qsystem v0.23.0 (current)
     Built [  45.530s] (current)
   Parsing tket-qsystem v0.23.0 (current)
    Parsed [   0.026s] (current)
  Building tket-qsystem v0.23.0 (baseline)
     Built [  45.557s] (baseline)
   Parsing tket-qsystem v0.23.0 (baseline)
    Parsed [   0.025s] (baseline)
  Checking tket-qsystem v0.23.0 -> v0.23.0 (assume minor change)
   Checked [   0.056s] 196 checks: 196 pass, 49 skip
   Summary no semver update required
  Finished [  92.663s] tket-qsystem

@aborgna-q aborgna-q marked this pull request as ready for review February 25, 2026 11:17
@aborgna-q aborgna-q requested a review from a team as a code owner February 25, 2026 11:17
@aborgna-q aborgna-q requested a review from acl-cqc February 25, 2026 11:17
Copy link
Copy Markdown
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.

Looks good, thanks @aborgna-q

g.bench_with_input(BenchmarkId::new("hash_simple", size), &size, |b, size| {
let circ = make_cnot_layers(8, *size);
b.iter(|| black_box(circ.circuit_hash(circ.entrypoint())))
let hugr = make_cnot_layers(8, *size);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this benchmark still belong here? Quantinuum/hugr#2840 has its own benchmarks

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I had added a comment, but forgot to push it.

//! TODO: This is already being done in the Hugr repository, so we could remove it from here.
//! We don't delete it yet to keep an example for writing benchmarks. Remove it once other benchmarks are written.


use std::thread::{self, JoinHandle};

use crate::circuit::CircuitHash;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Presumably you don't need to import anything else instead because of the new Circuit::circuit_hash(&self, T::Node) ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yep, it's a struct method rather than a trait now.

@aborgna-q aborgna-q enabled auto-merge March 3, 2026 15:49
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.60%. Comparing base (9c03ee0) to head (498a00e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #1420    +/-   ##
========================================
  Coverage   79.60%   79.60%            
========================================
  Files         156      155     -1     
  Lines       20432    20332   -100     
  Branches    19443    19343   -100     
========================================
- Hits        16264    16185    -79     
+ Misses       3197     3187    -10     
+ Partials      971      960    -11     
Flag Coverage Δ
python 92.99% <ø> (ø)
qis-compiler 100.00% <ø> (ø)
rust 78.90% <100.00%> (-0.01%) ⬇️

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 aborgna-q added this pull request to the merge queue Mar 3, 2026
Merged via the queue into main with commit e2b4991 Mar 3, 2026
24 checks passed
@aborgna-q aborgna-q deleted the ab/bye-hash branch March 3, 2026 16:00
This was referenced Mar 3, 2026
github-merge-queue bot pushed a commit that referenced this pull request Apr 2, 2026
## 🤖 New release

* `tket`: 0.17.0 -> 0.18.0 (✓ API compatible changes)
* `tket-qsystem`: 0.23.0 -> 0.24.0 (✓ API compatible changes)

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

## `tket`

<blockquote>

##
[0.18.0](tket-v0.17.0...tket-v0.18.0)
- 2026-04-02

### Bug Fixes

- *(pytket decoder)* Panic on repeated bit registers in pytket decoded
output ([#1445](#1445))
- pytket encoder drops order edges to the output node
([#1466](#1466))

### Documentation

- Fix tket README introductory example
([#1463](#1463))

### New Features

- [**breaking**] Use raw Hugrs in pytket encoding/decoding API
([#1418](#1418))
- [**breaking**] Remove unused `lower_to_pytket` pass
([#1431](#1431))
- [**breaking**] Replace CircuitHash with hugr's implementation
([#1420](#1420))
- [**breaking**] Update MSRV to rust 1.91
([#1446](#1446))
- [**breaking**] Update to hugr 0.26.0
([#1448](#1448))
- [**breaking**] Follow pass scopes in composable passes
([#1429](#1429))
- Implemented `post_opdef` for `RotationOp` for constant folding
([#1468](#1468))
- [**breaking**] Reorganize `tket::passes` and add `hugr_passes`
re-exports ([#1472](#1472))
- [**breaking**] Bump `hugr` dependency to 0.27.0
([#1488](#1488))
- Move hugr-passes implementations to tket::passes
([#1487](#1487))
- Pass scopes in python API, update to hugr-py 0.16
([#1464](#1464))

### Refactor

- *(llvm)* use llvm.is.fpclass for from_halfturns
([#1457](#1457))

### Testing

- Fixed signatures when decoding pytket circuits
([#1405](#1405))
</blockquote>

## `tket-qsystem`

<blockquote>

##
[0.24.0](tket-qsystem-v0.23.0...tket-qsystem-v0.24.0)
- 2026-04-02

### Bug Fixes

- pytket encoder drops order edges to the output node
([#1466](#1466))
- Constant Folding with PassScope::Global should act globally, not just
beneath the entrypoint
([#1470](#1470))

### New Features

- [**breaking**] Use raw Hugrs in pytket encoding/decoding API
([#1418](#1418))
- Add qsystem.rz pytket decoder
([#1432](#1432))
- [**breaking**] Update MSRV to rust 1.91
([#1446](#1446))
- [**breaking**] Update to hugr 0.26.0
([#1448](#1448))
- [**breaking**] Follow pass scopes in composable passes
([#1429](#1429))
- [**breaking**] Reorganize `tket::passes` and add `hugr_passes`
re-exports ([#1472](#1472))
- Move hugr-passes implementations to tket::passes
([#1487](#1487))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

---------

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.

3 participants