refactor: further cleanups to SiblingSubgraph + generalize over trait HugrConvexChecker#2957
refactor: further cleanups to SiblingSubgraph + generalize over trait HugrConvexChecker#2957
Conversation
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
- 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 usingmake_pg_subgraphi.e. a portgraph flat region (subgraph)) - It's used in
try_new_dataflow_subgraphbut here it's pretty trivial (all the nodes were taken from the same hugr region) - It's used in
nodes_if_convexi.e. checking that the nodes just calculated by the ConvexityChecker (again usingmake_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.
There was a problem hiding this comment.
Hehe, fair enough.
I think the change is fine.
There was a problem hiding this comment.
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.
## 🤖 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]>
struct ConvexCheckerwrapping aCreateConvexChecker<CheckerRegion>- this includes theTopoConvexCheckerused previously.try_new_with_checkerandtry_from_nodes_with_checkerto take an arbitraryimpl HugrConvexChecker. (The old TopoCC implements, so this is non-breaking 😄 😁)make_pg_subgraphtakes region and node_map, rather than recomputing them; avoid callingregion_portgraphin (the majority of cases where) we already have them in astruct ConvexCheckerpick_parentintotry_new(just to create a checker)check_parenti.e. that parents are all the same. (Thus fulfillingtry_new_with_checker's doc comment that it checks this.)validate_subgraphthat all nodes have the same parent; this is never called on the actual nodes of the subgraph, only nodes returned bymake_pg_subgraphor children of a hugr dataflow region, where this is guaranteed. Then, rename tovalidate_boundary.