Skip to content

Conversation

lmondada
Copy link
Contributor

@lmondada lmondada commented May 6, 2025

Currently, SimpleReplacement stores its output boundary map nu_out by referring to nodes outside the deleted subgraph in the host graph. This forces the invalidation set of the replacements to include nodes past the output, forbidding simultaneous adjacent replacements.

This PR fixes this by allowing the keys of nu_out (i.e. the ports on the output boundary of the subgraph) to be either incoming ports (as before), or outgoing ports (in which case this is equivalent to specifying the map on all incoming ports linked to the given outgoing ports). The latter is less general but covers most use cases and reduces the size of the invalidation set.

Closes #2098

BREAKING CHANGE: Generalised arguments to [SimpleReplacement::new] and [SimpleReplacement::map_host_output] to allow for outgoing ports. Previous type signatures remain valid, however, type inference may fail.

@lmondada lmondada requested a review from a team as a code owner May 6, 2025 07:21
@lmondada lmondada requested a review from mark-koch May 6, 2025 07:21
@lmondada lmondada changed the base branch from main to release-rs-v0.16.0 May 6, 2025 07:21
Copy link

codecov bot commented May 6, 2025

Codecov Report

Attention: Patch coverage is 97.59036% with 2 lines in your changes missing coverage. Please review.

Project coverage is 83.05%. Comparing base (a918853) to head (bbfa488).
Report is 1 commits behind head on release-rs-v0.16.0.

Files with missing lines Patch % Lines
hugr-core/src/hugr/patch/simple_replace.rs 97.53% 2 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                   @@
##           release-rs-v0.16.0    #2151      +/-   ##
======================================================
+ Coverage               83.01%   83.05%   +0.04%     
======================================================
  Files                     219      219              
  Lines                   41331    41385      +54     
  Branches                37479    37533      +54     
======================================================
+ Hits                    34310    34372      +62     
+ Misses                   5194     5186       -8     
  Partials                 1827     1827              
Flag Coverage Δ
python 85.69% <ø> (ø)
rust 82.78% <97.59%> (+0.04%) ⬆️

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 May 6, 2025

This PR contains breaking changes to the public Rust API.

cargo-semver-checks summary

--- failure method_requires_different_generic_type_params: method now requires a different number of generic type parameters ---

Description:
A method now requires a different number of generic type parameters than it used to. Uses of this method that supplied the previous number of generic types will be broken.
      ref: https://doc.rust-lang.org/reference/items/generics.html
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/method_requires_different_generic_type_params.ron

Failed in:
hugr_core::hugr::patch::simple_replace::SimpleReplacement::map_host_output takes 1 generic types instead of 0, in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:341
hugr_core::hugr::patch::SimpleReplacement::map_host_output takes 1 generic types instead of 0, in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:341
hugr_core::hugr::SimpleReplacement::map_host_output takes 1 generic types instead of 0, in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:341
hugr_core::SimpleReplacement::map_host_output takes 1 generic types instead of 0, in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:341

@lmondada lmondada force-pushed the luca/out-boundary-map branch from 947e74d to 19098e5 Compare May 6, 2025 07:26
@lmondada lmondada changed the title feat: Accept outgoing ports in SimpleReplacement nu_out feat!: Accept outgoing ports in SimpleReplacement nu_out May 6, 2025
Copy link
Contributor

@mark-koch mark-koch left a comment

Choose a reason for hiding this comment

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

The implementation looks good to me, but I'm missing the broader context to tell if the thing itself is a good idea 😅 A second opinion on this might be useful

Co-authored-by: Mark Koch <48097969+mark-koch@users.noreply.github.com>
@lmondada
Copy link
Contributor Author

lmondada commented May 6, 2025

A second opinion on this might be useful

@aborgna-q, ok? 🙃

@aborgna-q
Copy link
Collaborator

Looks great to me!

@lmondada lmondada added this pull request to the merge queue May 6, 2025
Merged via the queue into release-rs-v0.16.0 with commit 20081dd May 6, 2025
25 checks passed
@lmondada lmondada deleted the luca/out-boundary-map branch May 6, 2025 11:00
aborgna-q pushed a commit that referenced this pull request May 7, 2025
Currently, SimpleReplacement stores its output boundary map nu_out by
referring to nodes outside the deleted subgraph in the host graph. This
forces the invalidation set of the replacements to include nodes past
the output, forbidding simultaneous adjacent replacements.

This PR fixes this by allowing the keys of `nu_out` (i.e. the ports on
the output boundary of the subgraph) to be either incoming ports (as
before), or outgoing ports (in which case this is equivalent to
specifying the map on all incoming ports linked to the given outgoing
ports). The latter is less general but covers most use cases and reduces
the size of the invalidation set.

Closes #2098

BREAKING CHANGE: Generalised arguments to [`SimpleReplacement::new`] and
[`SimpleReplacement::map_host_output`] to allow for outgoing ports.
Previous type signatures remain valid, however, type inference may fail.

---------

Co-authored-by: Mark Koch <48097969+mark-koch@users.noreply.github.com>
This was referenced May 7, 2025
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.

SimpleReplacement invalidates output nodes

4 participants