Skip to content

fix!: Passes with Nested Modifier#1546

Open
nicolaassolini-qntm wants to merge 45 commits intomainfrom
na/fix-nested-modifier
Open

fix!: Passes with Nested Modifier#1546
nicolaassolini-qntm wants to merge 45 commits intomainfrom
na/fix-nested-modifier

Conversation

@nicolaassolini-qntm
Copy link
Copy Markdown
Contributor

@nicolaassolini-qntm nicolaassolini-qntm commented Apr 27, 2026

closes #1518 closes #1520

Bug 1
The condition in modify_fn_if_needed was incorrect. As a result, the pass solver attempted to process classical functions, leading to an invalid inversion of non-quantum input ordering.

Bug 2
There was a misalignment between metadata-derived values (from_metadata) and the corresponding function representation. This inconsistency became visible with nested modifiers, where metadata mismatches caused the modifier builder to skip the modified block, ultimately triggering errors.

Bug 3
In modify_cfg, wire_node_inout was called with the modified signature types. The modified signature has extra control qubits prepended. Since wire_node_inout iterates the type list while incrementing old port indices starting from 0, it was misaligned producing two Out ports that can't be connected.

Fix:

  • The check in modify_fn_if_needed has been corrected to properly exclude classical functions.
  • Metadata handling has been aligned with function values (via updates introduced in this guppy PR), ensuring consistency between node values and their expected representation at the tket level.
  • At modifier_resolver.rs#L1069 we use the original signature instead of the modified one since the offset already contains the information about the added qubits.

Additional tests have been introduced to improve coverage of modifier handling and HUGR construction.

BREAKING CHANGE: In ModifierResolver::modify_fn_if_needed the parameter signature has been removed
BREAKING CHANGE: In control.rs, dagger.rs, and power.rs, the modifier constructors new() became private, and signature() was reduced from pub to pub(crate).
BREAKING CHANGE: In modifier_resolver.rs, several internal helpers were hidden or narrowed:
BREAKING CHANGE: DirWire::new, ModifierResolver::new, ModifierResolverErrors::{unreachable, unresolvable}, connect_all, and modify_signature are now private.
BREAKING CHANGE: DirWire::reverse is now pub(crate)
BREAKING CHANGE: In resolver submodules: modify_fn_if_needed, modify_fn, modify_global_phase, delete_phase, and modify_tket_op were changed from pub to pub(crate).

nicolaassolini-qntm and others added 30 commits April 10, 2026 12:32
… double_modifier.py, update rendering, and improve apply_passes.py logic
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

❌ Patch coverage is 78.50467% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.03%. Comparing base (6d87034) to head (7df220a).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
tket/src/modifier/modifier_resolver/call_modify.rs 72.50% 9 Missing and 2 partials ⚠️
tket/src/modifier/modifier_resolver.rs 83.01% 2 Missing and 7 partials ⚠️
tket/src/modifier/control.rs 50.00% 1 Missing ⚠️
tket/src/modifier/dagger.rs 50.00% 1 Missing ⚠️
tket/src/modifier/power.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1546      +/-   ##
==========================================
+ Coverage   83.80%   84.03%   +0.22%     
==========================================
  Files         188      188              
  Lines       29035    29097      +62     
  Branches    27931    27993      +62     
==========================================
+ Hits        24333    24451     +118     
+ Misses       3540     3473      -67     
- Partials     1162     1173      +11     
Flag Coverage Δ
python 92.32% <ø> (ø)
qis-compiler 91.66% <ø> (ø)
rust 83.70% <78.50%> (+0.23%) ⬆️

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
Copy Markdown
Collaborator

hugrbot commented Apr 27, 2026

This PR contains breaking changes to the public Rust API.

cargo-semver-checks summary
    Building tket v0.18.0 (current)
     Built [  42.384s] (current)
   Parsing tket v0.18.0 (current)
    Parsed [   0.110s] (current)
  Building tket v0.18.0 (baseline)
     Built [  42.793s] (baseline)
   Parsing tket v0.18.0 (baseline)
    Parsed [   0.105s] (baseline)
  Checking tket v0.18.0 -> v0.18.0 (assume minor change)
   Checked [   0.153s] 196 checks: 194 pass, 2 fail, 0 warn, 56 skip

--- 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.47.0/src/lints/function_missing.ron

Failed in:
function tket::modifier::modifier_resolver::global_phase_modify::delete_phase, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/modifier_resolver/global_phase_modify.rs:106

--- failure inherent_method_missing: pub method removed or renamed ---

Description:
A publicly-visible method or associated fn 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.47.0/src/lints/inherent_method_missing.ron

Failed in:
ModifierDagger::new, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/dagger.rs:15
ModifierDagger::signature, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/dagger.rs:37
ModifierControl::new, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/control.rs:16
ModifierControl::signature, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/control.rs:27
ModifierResolver::modify_fn_if_needed, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/modifier_resolver/dfg_modify.rs:298
ModifierResolver::modify_fn, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/modifier_resolver/dfg_modify.rs:317
ModifierResolver::modify_global_phase, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/modifier_resolver/global_phase_modify.rs:22
ModifierResolver::modify_tket_op, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/modifier_resolver/tket_op_modify.rs:17
ModifierResolver::new, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/modifier_resolver.rs:331
ModifierResolver::connect_all, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/modifier_resolver.rs:605
ModifierResolver::modify_signature, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/modifier_resolver.rs:699
ModifierPower::new, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/power.rs:16
ModifierPower::signature, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/power.rs:39
ModifierResolverErrors::unreachable, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/modifier_resolver.rs:417
ModifierResolverErrors::unresolvable, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/modifier_resolver.rs:422
ModifierResolverErrors::unreachable, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/modifier_resolver.rs:417
ModifierResolverErrors::unresolvable, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket/src/modifier/modifier_resolver.rs:422

   Summary semver requires new major version: 2 major and 0 minor checks failed
  Finished [  87.795s] tket
  Building tket-qec v0.1.0 (current)
     Built [  37.236s] (current)
   Parsing tket-qec v0.1.0 (current)
    Parsed [   0.007s] (current)
  Building tket-qec v0.1.0 (baseline)
     Built [  37.392s] (baseline)
   Parsing tket-qec v0.1.0 (baseline)
    Parsed [   0.007s] (baseline)
  Checking tket-qec v0.1.0 -> v0.1.0 (assume minor change)
   Checked [   0.016s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  76.520s] tket-qec
  Building tket-qsystem v0.24.0 (current)
     Built [  43.985s] (current)
   Parsing tket-qsystem v0.24.0 (current)
    Parsed [   0.028s] (current)
  Building tket-qsystem v0.24.0 (baseline)
     Built [  43.171s] (baseline)
   Parsing tket-qsystem v0.24.0 (baseline)
    Parsed [   0.027s] (baseline)
  Checking tket-qsystem v0.24.0 -> v0.24.0 (assume minor change)
   Checked [   0.062s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  89.369s] tket-qsystem

@nicolaassolini-qntm nicolaassolini-qntm changed the title fix: Passes with Nested Modifier fix!: Passes with Nested Modifier Apr 28, 2026
@nicolaassolini-qntm nicolaassolini-qntm changed the title fix!: Passes with Nested Modifier fix!: Passes with Nested Modifier Apr 28, 2026
@nicolaassolini-qntm nicolaassolini-qntm marked this pull request as ready for review May 1, 2026 16:07
@nicolaassolini-qntm nicolaassolini-qntm requested a review from a team as a code owner May 1, 2026 16:07
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.

[Bug]: Error with function taking classical arguments under nested modifier [Bug]: Classical Function Inside Modifier

3 participants