Skip to content

refactor: further cleanups to SiblingSubgraph + generalize over trait HugrConvexChecker#2957

Merged
acl-cqc merged 17 commits intomainfrom
acl/sib_sub2
Mar 25, 2026
Merged

refactor: further cleanups to SiblingSubgraph + generalize over trait HugrConvexChecker#2957
acl-cqc merged 17 commits intomainfrom
acl/sib_sub2

Conversation

@acl-cqc
Copy link
Copy Markdown
Contributor

@acl-cqc acl-cqc commented Mar 17, 2026

  • Add a trait capturing the validation + convexity checking operation at the Hugr (not portgraph) level.
  • Implement this for any struct ConvexChecker wrapping a CreateConvexChecker<CheckerRegion> - this includes the TopoConvexChecker used previously.
  • Generalize try_new_with_checker and try_from_nodes_with_checker to take an arbitrary impl HugrConvexChecker. (The old TopoCC implements, so this is non-breaking 😄 😁)
  • make_pg_subgraph takes region and node_map, rather than recomputing them; avoid calling region_portgraph in (the majority of cases where) we already have them in a struct ConvexChecker
  • Inline pick_parent into try_new (just to create a checker)
  • Add check_parent i.e. that parents are all the same. (Thus fulfilling try_new_with_checker's doc comment that it checks this.)
  • Also check the ConvexChecker's region_parent is the same as the subgraph, seems this was missing before
  • Remove the (internal) check in helper validate_subgraph that all nodes have the same parent; this is never called on the actual nodes of the subgraph, only nodes returned by make_pg_subgraph or children of a hugr dataflow region, where this is guaranteed. Then, rename to validate_boundary.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 89.28571% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.13%. Comparing base (39d047f) to head (c9944c1).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
hugr-core/src/hugr/views/sibling_subgraph.rs 89.28% 7 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2957      +/-   ##
==========================================
- Coverage   83.87%   81.13%   -2.74%     
==========================================
  Files         267      239      -28     
  Lines       52941    45307    -7634     
  Branches    46857    39123    -7734     
==========================================
- Hits        44404    36761    -7643     
- Misses       6268     6563     +295     
+ Partials     2269     1983     -286     
Flag Coverage Δ
python 88.87% <ø> (+0.06%) ⬆️
rust 79.91% <89.28%> (-3.32%) ⬇️

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.

@acl-cqc acl-cqc changed the title refactor: more SSG cleanup refactor: more SiblingSubgraph cleanup Mar 19, 2026
@acl-cqc acl-cqc requested a review from aborgna-q March 19, 2026 00:34
@acl-cqc acl-cqc marked this pull request as ready for review March 19, 2026 00:34
@acl-cqc acl-cqc requested a review from a team as a code owner March 19, 2026 00:34
@acl-cqc acl-cqc changed the title refactor: more SiblingSubgraph cleanup refactor: more SiblingSubgraph cleanup, add trait HugrConvexChecker Mar 19, 2026
@acl-cqc acl-cqc changed the title refactor: more SiblingSubgraph cleanup, add trait HugrConvexChecker refactor: further cleanups to SiblingSubgraph + generalize over trait HugrConvexChecker Mar 19, 2026
Copy link
Copy Markdown
Contributor Author

@acl-cqc acl-cqc Mar 20, 2026

Choose a reason for hiding this comment

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

Note this repeats the pick_parent in try_new_with_checker (inside nodes_if_valid_and_convex), which is a little inefficient. We could just pick an arbitrary parent (and then either that would be ok, or we'd reject the boundary as invalid later anyway). I did this in b24107e but it seemed more complicated not less so I reverted...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Couldn't we split pick_parent into a picker and a checker?

Keep the old pick_parent, and rename your new version to check_parents (passing the parent as parameter instead), and only call it from nodes_if_valid_and_convex.

Copy link
Copy Markdown
Contributor Author

@acl-cqc acl-cqc Mar 24, 2026

Choose a reason for hiding this comment

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

Ok, well, sort of, and sort of gone further.
Old pick_parent code reinstated, but inlined into its only use (in try_new, to create the checker).
pick_parent renamed to check_parent does all the checking...could rename, I mean it's private.

Moreover, moved responsibility for check_parent and checking against the checker's region_parent into try_new_with_checker, as otherwise every impl of nodes_if_valid_and_convex would have to do that. Hence, renamed to just nodes_if_convex (there is some validity checking still though....so could keep the longer name if you prefer). EDIT: I'm not so convinced about this anymore; we therefore also need to check the checker is appropriate in fn validate (when a checker is passed in), so two places. But, I dunno, it does feel like the better trait interface; thoughts?

Copy link
Copy Markdown
Contributor Author

@acl-cqc acl-cqc Mar 24, 2026

Choose a reason for hiding this comment

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

Finally, I've dropped the check in validate_subgraph (now validate_subgraph_boundary) that all the nodes have the same parent. Whilst that sounds like a good thing, on closer inspection

  1. It's not used in fn validate - at least not directly, not on the nodes in the SiblingSubgraph: they are checked only for equality against (recomputing what the nodes should be by the ConvexChecker or using make_pg_subgraph i.e. a portgraph flat region (subgraph))
  2. It's used in try_new_dataflow_subgraph but here it's pretty trivial (all the nodes were taken from the same hugr region)
  3. It's used in nodes_if_convex i.e. checking that the nodes just calculated by the ConvexityChecker (again using make_pg_subgraph) have the same parent. Which again seems a bit pointless.

So could revert that one (02ee279) if you feel strongly, but if you are on the fence - we are doing a stronger check, see point 1.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hehe, fair enough.

I think the change is fine.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Couldn't we split pick_parent into a picker and a checker?

Keep the old pick_parent, and rename your new version to check_parents (passing the parent as parameter instead), and only call it from nodes_if_valid_and_convex.

@acl-cqc acl-cqc requested a review from aborgna-q March 24, 2026 20:34
@acl-cqc acl-cqc enabled auto-merge March 25, 2026 13:37
@acl-cqc acl-cqc added this pull request to the merge queue Mar 25, 2026
Merged via the queue into main with commit 7341dae Mar 25, 2026
30 checks passed
@acl-cqc acl-cqc deleted the acl/sib_sub2 branch March 25, 2026 13:45
This was referenced Mar 25, 2026
github-merge-queue bot pushed a commit that referenced this pull request Mar 31, 2026
## 🤖 New release

* `hugr-model`: 0.26.1 -> 0.27.0 (✓ API compatible changes)
* `hugr-core`: 0.26.1 -> 0.27.0 (✓ API compatible changes)
* `hugr-llvm`: 0.26.1 -> 0.27.0 (✓ API compatible changes)
* `hugr-persistent`: 0.5.1 -> 0.6.0 (✓ API compatible changes)
* `hugr`: 0.26.1 -> 0.27.0 (✓ API compatible changes)
* `hugr-cli`: 0.26.1 -> 0.27.0 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

## `hugr-model`

<blockquote>

##
[0.26.0](hugr-model-v0.25.7...hugr-model-v0.26.0)
- 2026-03-16

### Testing

- Replace model text snapshots with roundtrip tests
([#2933](#2933))
- Add missing width arg in model-call example
([#2945](#2945))
</blockquote>

## `hugr-core`

<blockquote>

##
[0.27.0](hugr-core-v0.26.1...hugr-core-v0.27.0)
- 2026-03-31

### Bug Fixes

- Use valid identifiers when constructing AST model
([#2973](#2973))
- Panic on constant folding with opaque consts
([#2986](#2986))

### New Features

- *(py)* Allow missing ext versions ExtensionDesc metadata
([#2979](#2979))
- [**breaking**] Deprecate JSON serialization format
([#2991](#2991))
- [**breaking**] Bump public `portgraph` dependency to `0.16.0`
([#2998](#2998))

### Refactor

- Simplify validate_subtree
([#2969](#2969))
- further cleanups to SiblingSubgraph + generalize over trait
HugrConvexChecker
([#2957](#2957))
</blockquote>

## `hugr-llvm`

<blockquote>

##
[0.27.0](hugr-llvm-v0.26.1...hugr-llvm-v0.27.0)
- 2026-03-31

### New Features

- *(hugr-llvm)* Emit rounding operation for `FloatOps::fround` extension
ops ([#2949](#2949))
</blockquote>

## `hugr-persistent`

<blockquote>

##
[0.6.0](hugr-persistent-v0.5.1...hugr-persistent-v0.6.0)
- 2026-03-31

### New Features

- [**breaking**] Deprecate JSON serialization format
([#2991](#2991))
</blockquote>

## `hugr`

<blockquote>

##
[0.27.0](hugr-v0.26.1...hugr-v0.27.0)
- 2026-03-31

### Bug Fixes

- Use valid identifiers when constructing AST model
([#2973](#2973))
- Panic on constant folding with opaque consts
([#2986](#2986))

### New Features

- *(py)* Allow missing ext versions ExtensionDesc metadata
([#2979](#2979))
- [**breaking**] Bump public `portgraph` dependency to `0.16.0`
([#2998](#2998))
- [**breaking**] Deprecate JSON serialization format
([#2991](#2991))

### Refactor

- Simplify validate_subtree
([#2969](#2969))
- further cleanups to SiblingSubgraph + generalize over trait
HugrConvexChecker
([#2957](#2957))
</blockquote>

## `hugr-cli`

<blockquote>

##
[0.27.0](hugr-cli-v0.26.1...hugr-cli-v0.27.0)
- 2026-03-31

### Bug Fixes

- Do extension resolution on exts loaded by hugr-cli
([#2987](#2987))

### New Features

- *(py)* Allow missing ext versions ExtensionDesc metadata
([#2979](#2979))
- [**breaking**] Deprecate JSON serialization format
([#2991](#2991))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

---------

Co-authored-by: Agustín Borgna <[email protected]>
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