Skip to content

feat: PersistentHugr implements HugrView #2202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 22, 2025
Merged

Conversation

lmondada
Copy link
Contributor

Closes #2095

@lmondada lmondada requested a review from a team as a code owner May 12, 2025 14:42
@lmondada lmondada requested review from zrho and aborgna-q and removed request for a team and zrho May 12, 2025 14:42
Copy link

codecov bot commented May 12, 2025

Codecov Report

Attention: Patch coverage is 71.75573% with 222 lines in your changes missing coverage. Please review.

Project coverage is 81.99%. Comparing base (acf201f) to head (70088a7).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
hugr-core/src/hugr/persistent/parents_view.rs 16.43% 122 Missing ⚠️
hugr-core/src/hugr/persistent/trait_impls.rs 77.15% 48 Missing and 5 partials ⚠️
hugr-core/src/hugr/persistent/state_space.rs 79.85% 27 Missing and 1 partial ⚠️
hugr-core/src/hugr/persistent.rs 96.00% 4 Missing and 6 partials ⚠️
hugr-core/src/hugr/internal.rs 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2202      +/-   ##
==========================================
- Coverage   82.03%   81.99%   -0.04%     
==========================================
  Files         234      237       +3     
  Lines       41702    42767    +1065     
  Branches    37616    38679    +1063     
==========================================
+ Hits        34209    35068     +859     
- Misses       5518     5706     +188     
- Partials     1975     1993      +18     
Flag Coverage Δ
python 85.34% <ø> (+0.12%) ⬆️
rust 81.64% <71.75%> (-0.05%) ⬇️

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.

Base automatically changed from feat/persistenthugr to main May 14, 2025 19:04
@lmondada lmondada force-pushed the luca/persistent-impl-hugrview branch from 08e3eb0 to 7cd85d7 Compare May 19, 2025 11:14
@lmondada lmondada changed the base branch from main to luca/add-bd-traversal-simple-repl May 19, 2025 11:15
@lmondada
Copy link
Contributor Author

I've rebased on top of main and have simplified/improved the logic to find linked incoming/outgoing ports. In doing so, I've also established a more stable API for querying the boundary edges of SimpleReplacements, see #2231

Apologies I think this will require a complete re-review. The combination of the changes + rebase makes diff-ing changes between before and now difficult. The main changes are the methods

  • PersistentHugr::get_single_outgoing_port
  • PersistentHugr::get_all_incoming_ports

@lmondada lmondada requested a review from aborgna-q May 19, 2025 11:19
@lmondada
Copy link
Contributor Author

Question: I've implemented a partial subset of HugrView in parents_view.rs. I think this is fine because the type is private.

The alternative would be to introduce a new trait that captures the parts of HugrView that I need, but this new trait would have to be public as it would be exposed through the SimpleReplacement API. I worry that this makes the API less readable (as the user will need to be aware of one more trait), even if we provide blanket implementations.

Let me know which approach you prefer

Base automatically changed from luca/add-bd-traversal-simple-repl to main May 20, 2025 15:26
@lmondada
Copy link
Contributor Author

Question: I've implemented a partial subset of HugrView in parents_view.rs. I think this is fine because the type is private.

btw this is also the reason why coverage is low. Everything else is well-covered. I could add dummy for the missing implementations to increase coverage artificially, but I don't think that's a useful thing to do...

Copy link
Collaborator

@aborgna-q aborgna-q left a comment

Choose a reason for hiding this comment

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

Awesome!
I only have some nitpicks

portgraph::view::FlatRegion<'_, Self::RegionPortgraph<'_>>,
Self::RegionPortgraphNodes,
) {
// TODO: this is currently not very efficient
Copy link
Collaborator

Choose a reason for hiding this comment

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

I imagine this would require a custom portgraph implementation.
Open an issue and link it from here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

-> #2248 (same below)

Comment on lines 74 to 78
// TODO: A lot of these implementations (especially the ones relating to node
// hierarchies) are very inefficient as they (often unnecessarily) construct
// the whole extracted HUGR in memory. We are currently prioritizing correctness
// and clarity over performance and will optimise some of these operations in
// the future as bottlenecks are encountered.
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Open an issue!

@lmondada lmondada enabled auto-merge May 22, 2025 14:28
@lmondada lmondada added this pull request to the merge queue May 22, 2025
Merged via the queue into main with commit 70bec95 May 22, 2025
26 of 27 checks passed
@lmondada lmondada deleted the luca/persistent-impl-hugrview branch May 22, 2025 14:34
@hugrbot hugrbot mentioned this pull request May 22, 2025
github-merge-queue bot pushed a commit that referenced this pull request May 26, 2025
I mistakenly made these as comments on #2168 because GitHub's "show
changes from last review" includes changes merged in from main - the
code I was commenting on actually went into main as part of #2202 . So,
nothing major, but separating out.
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.

Implement HugrView & Rewrite traits on PersistentHugr
3 participants