Skip to content

Conversation

@acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Jul 23, 2025

Add LowerDropsPass, use in QSystemPass.

hugr 0.22.0 -> 0.22.1 gets the "copy_discard_array" being in the default ReplaceTypes

@codecov
Copy link

codecov bot commented Jul 23, 2025

Codecov Report

❌ Patch coverage is 95.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.40%. Comparing base (85ee480) to head (b227152).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
tket-qsystem/src/lib.rs 75.00% 0 Missing and 1 partial ⚠️
tket-qsystem/src/lower_drops.rs 97.22% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #979      +/-   ##
==========================================
- Coverage   79.65%   79.40%   -0.25%     
==========================================
  Files          94       95       +1     
  Lines       11552    11592      +40     
  Branches    11282    11322      +40     
==========================================
+ Hits         9202     9205       +3     
- Misses       1720     1754      +34     
- Partials      630      633       +3     
Flag Coverage Δ
python 78.14% <ø> (ø)
rust 79.43% <95.00%> (-0.26%) ⬇️

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.

fn run(&self, hugr: &mut H) -> Result<Self::Result, Self::Error> {
let mut rt = ReplaceTypes::default();
rt.linearizer()
.register_callback(array_type_def(), copy_discard_array);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should possibly be done in DelegatingLinearizer::default(), which currently adds only linearize_array (for ValueArray). Or, perhaps that change happens when we remove ValueArray?

I also worry that there are other types we need to add (i.e. anything guppy-affine but hugr-linear)....however I think if there were any, we would need them in the linearize_arrays pass, and the only linearizer callback I see there is...this one!

Copy link
Contributor

Choose a reason for hiding this comment

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

I am also adding the same callback in the replace borrow arrays pass - does it cause issues with multiple passes adding this?

It does seem a bit confusing to have some logic for this in the DelegatingLinearizer default and some in the passes given not all the passes may be run but if at least on pass with ReplaceTypes with linearisation is run it will use all the defaults?

Copy link
Contributor Author

@acl-cqc acl-cqc Jul 25, 2025

Choose a reason for hiding this comment

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

Each ReplaceTypes has its own (independent) list of callbacks, and the linearize_array callback is stateless, so it should work. But it is more of a maintenance issue - i.e. we are now getting up to 3 passes.

If multiple ReplaceTypes passes actually get run, we'll probably need to make sure linearize_array is added to all of them (not just one) - each pass only runs linearization on the parts of the Hugr that it changes.

So, might be better to add this to ReplaceTypes::default() now (as a Hugr PR, for the hugr-v0.22 release), and then one of us can remove the existing tket register_callback rather than add another....it's now a very simple Hugr PR!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This done in hugr-0.22.1, to which I'm updating here, so you should no longer need it in the pass for borrow-arrays @tatiana-s

@acl-cqc acl-cqc requested a review from tatiana-s July 23, 2025 12:39
@acl-cqc acl-cqc marked this pull request as ready for review July 23, 2025 12:39
@acl-cqc acl-cqc requested a review from a team as a code owner July 23, 2025 12:39
@acl-cqc acl-cqc requested review from doug-q and removed request for a team July 23, 2025 12:39
fn run(&self, hugr: &mut H) -> Result<Self::Result, Self::Error> {
let mut rt = ReplaceTypes::default();
rt.linearizer()
.register_callback(array_type_def(), copy_discard_array);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am also adding the same callback in the replace borrow arrays pass - does it cause issues with multiple passes adding this?

It does seem a bit confusing to have some logic for this in the DelegatingLinearizer default and some in the passes given not all the passes may be run but if at least on pass with ReplaceTypes with linearisation is run it will use all the defaults?

let h = std::mem::take(dfb.hugr_mut());
Some(NodeTemplate::CompoundOp(Box::new(h)))
},
ReplacementOptions::default().with_linearization(true),
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 handle adding a relevant discard op to the type - if so how does it know which one is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the replacement for Drop is an empty DFG with the same signature as the Drop. So inside that DFG there will be an Input node, with a single outport of the relevant type, and the linearizer will figure out how to implement a discard (0-ary copy) op from that. (See CQCL/hugr#2435)

@acl-cqc acl-cqc removed the request for review from doug-q July 25, 2025 10:04
Base automatically changed from lm/hugr-v22 to main July 25, 2025 11:25
@acl-cqc acl-cqc changed the title Lower "Drop" op in guppy extension Lower "Drop" op in guppy extension, update hugr to 0.22.1 Jul 28, 2025
@acl-cqc acl-cqc changed the title Lower "Drop" op in guppy extension, update hugr to 0.22.1 Lower "Drop" op in guppy extension, update hugr minor version Jul 28, 2025
@acl-cqc acl-cqc changed the title Lower "Drop" op in guppy extension, update hugr minor version feat: Lower "Drop" op in guppy extension, update hugr minor version Jul 28, 2025
@acl-cqc acl-cqc requested a review from ss2165 July 28, 2025 11:24
@acl-cqc acl-cqc added this pull request to the merge queue Jul 28, 2025
Merged via the queue into main with commit c157a36 Jul 28, 2025
21 checks passed
@acl-cqc acl-cqc deleted the acl/lower-drop branch July 28, 2025 11:29
croyzor pushed a commit that referenced this pull request Aug 11, 2025
…979)

Add LowerDropsPass, use in QSystemPass.

hugr 0.22.0 -> 0.22.1 gets the "copy_discard_array" being in the default
ReplaceTypes
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