Skip to content
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

feat: Add SiblingSubgraph::from_node #1655

Merged
merged 3 commits into from
Nov 15, 2024
Merged

feat: Add SiblingSubgraph::from_node #1655

merged 3 commits into from
Nov 15, 2024

Conversation

aborgna-q
Copy link
Collaborator

Complementary improvement to #1654.
Creating a k-node subgraph in an n-node graph should ideally be O(k).
However, due to CQCL/portgraph#155 this ends up being O(n).

For k=1, this results in a linear cost overhead.
This PR adds a special case (written by @doug-q) that completely skips the unnecessary checks.

group                         before                                 from_node
-----                         ------                                 ---------
multinode_subgraph/10         1.01     17.7±0.26µs        ? ?/sec    1.00     17.5±0.23µs        ? ?/sec
multinode_subgraph/100        1.00   169.1±11.34µs        ? ?/sec    1.00    168.8±4.37µs        ? ?/sec
multinode_subgraph/1000       1.01      2.3±0.46ms        ? ?/sec    1.00      2.3±0.34ms        ? ?/sec
singleton_subgraph/10         12.26     3.0±0.06µs        ? ?/sec    1.00   245.6±21.24ns        ? ?/sec
singleton_subgraph/100        20.01     4.7±0.06µs        ? ?/sec    1.00    234.4±6.50ns        ? ?/sec
singleton_subgraph/1000       93.34    22.0±0.25µs        ? ?/sec    1.00    235.6±4.93ns        ? ?/sec

@aborgna-q aborgna-q requested a review from a team as a code owner November 13, 2024 17:33
Copy link

codecov bot commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.

Project coverage is 85.52%. Comparing base (e63878f) to head (68d2a59).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
hugr-core/src/hugr/views/sibling_subgraph.rs 96.55% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1655   +/-   ##
=======================================
  Coverage   85.51%   85.52%           
=======================================
  Files         136      136           
  Lines       25264    25293   +29     
  Branches    22176    22205   +29     
=======================================
+ Hits        21605    21632   +27     
- Misses       2455     2456    +1     
- Partials     1204     1205    +1     
Flag Coverage Δ
python 92.42% <ø> (ø)
rust 84.56% <96.55%> (+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.

Copy link
Collaborator

@doug-q doug-q left a comment

Choose a reason for hiding this comment

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

I think a better commit message here is feat: Add SiblingSubgraph::from_node.

hugr-core/src/hugr/views/sibling_subgraph.rs Outdated Show resolved Hide resolved
let checker = TopoConvexChecker::new(hugr);
Self::try_from_nodes_with_checker(nodes, hugr, &checker)
}
}
Copy link
Collaborator

@doug-q doug-q Nov 14, 2024

Choose a reason for hiding this comment

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

This change doesn't seem necessary. try_from_nodes_with_checker already does this, and TopoConvexChecker::new is cheap now.

aborgna-q and others added 2 commits November 14, 2024 17:15
Co-authored-by: Douglas Wilson <141026920+doug-q@users.noreply.github.com>
@aborgna-q aborgna-q changed the title perf: Special case SiblingSubgraph::try_from_nodes when n=1 feat: Add SiblingSubgraph::from_node Nov 15, 2024
Copy link
Collaborator

@doug-q doug-q left a comment

Choose a reason for hiding this comment

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

Nice.

@aborgna-q aborgna-q added this pull request to the merge queue Nov 15, 2024
Merged via the queue into main with commit c2c5752 Nov 15, 2024
23 checks passed
@aborgna-q aborgna-q deleted the ab/from-node branch November 15, 2024 12:08
@hugrbot hugrbot mentioned this pull request Nov 15, 2024
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.

2 participants