refactor: add HugrView::scheduling_graph, deprecate region_portgraph#3015
refactor: add HugrView::scheduling_graph, deprecate region_portgraph#3015
Conversation
1356b19 to
6db3845
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3015 +/- ##
==========================================
- Coverage 81.30% 81.06% -0.25%
==========================================
Files 240 242 +2
Lines 45356 45181 -175
Branches 39160 38949 -211
==========================================
- Hits 36876 36624 -252
- Misses 6490 6591 +101
+ Partials 1990 1966 -24
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:
|
This reverts commit 04178e4.
6db3845 to
521319f
Compare
Merging this PR will degrade performance by 23.65%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | multinode_subgraph[100] |
1.1 ms | 1.2 ms | -14.35% |
| ❌ | multinode_subgraph[10] |
135 µs | 154.3 µs | -12.51% |
| ❌ | fewnode_subgraph[10] |
137.1 µs | 155.7 µs | -11.93% |
| ❌ | fewnode_subgraph[100] |
610.2 µs | 787.3 µs | -22.49% |
| ❌ | fewnode_subgraph[1000] |
5.3 ms | 7 ms | -23.65% |
| ❌ | multinode_subgraph[1000] |
14.2 ms | 16 ms | -10.78% |
Comparing acl/syn_edge_prep (956f087) with main (7881c99)
Footnotes
-
6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
| }; | ||
| use std::collections::BTreeSet; | ||
|
|
||
| use portgraph::{SecondaryMap, UnmanagedDenseMap}; |
There was a problem hiding this comment.
This file is basically a straight copy of TopoConvexChecker from portgraph then slightly reparametrized
| @@ -0,0 +1,778 @@ | |||
| use std::collections::BTreeSet; | |||
There was a problem hiding this comment.
Tests moved out of sibling_subgraph.rs
|
|
||
| impl<T: LinkView> pv::GraphBase for SynEdgeWrapper<T> { | ||
| type NodeId = NIdx<T::NodeIndexBase>; | ||
| type EdgeId = ( |
There was a problem hiding this comment.
Note this is significantly more informative than portgraph's petgraph-traits, but perhaps it shouldn't be
|
|
||
| impl<T: LinkView> pv::NodeIndexable for SynEdgeWrapper<T> { | ||
| fn node_bound(&self) -> usize { | ||
| // ALAN copied from petgraph; but are `NodeIndex`es always dense? |
There was a problem hiding this comment.
I was a bit worried here??
| /// but at least this distinguishes synthetic edges from original edges. | ||
| /// | ||
| /// [FlatRegion]: portgraph::view::FlatRegion | ||
| type EdgeWeight = MaybeSynEdge<(PortOffset<T::PortOffsetBase>, PortOffset<T::PortOffsetBase>)>; |
There was a problem hiding this comment.
Again, portgraph's petgraph-traits does not provide any edge info, not even just the port offsets
| /// Access to the graph, sufficient to allow [pv::Topo] | ||
| pub fn petgraph( | ||
| &self, | ||
| ) -> impl pv::NodeCount |
There was a problem hiding this comment.
this type is part of the hiding, and quite deliberate. It could be much more detailed (NodeId/EdgeId types etc.)
| /// Skip convexity check. | ||
| SkipConvexity, | ||
| mod hidden { | ||
| #![expect(deprecated)] // Remove enum along with TopoConvexChecker |
There was a problem hiding this comment.
This mod hidden is so we can do this to capture the deprecation warning from #[derive(Default)]
| /// particularly when many checks must be performed. | ||
| pub type LineConvexChecker<'g, Base> = | ||
| ConvexChecker<'g, Base, portgraph::algorithms::LineConvexChecker<CheckerRegion<'g, Base>>>; | ||
| pub type LineConvexChecker<'g, Base> = PortgraphCheckerWithNodes< |
There was a problem hiding this comment.
So I've put some effort into trying to keep this alive, on the grounds that it's potentially much more efficient than TopoConvexChecker. I think it works only for graphs with no container nodes, in which case there will be no syn edges, so it'll still be as ok as it ever was.
But, we could also drop it and plan to reimplement line checking somewhere else if we want it, possibly based off Quantinuum/tket2#1289 somehow
| outputs: &OutgoingPorts<H::Node>, | ||
| function_calls: &IncomingPorts<H::Node>, | ||
| ) -> Result<Vec<H::Node>, InvalidSubgraph<H::Node>> { | ||
| // Compute the nodes inside the boundary ignoring synthetic edges - |
There was a problem hiding this comment.
This is key, can you check that you agree?
| // that would lead to needing those synthetic edges) then the subgraph is invalid | ||
| // (nodes would not share the same parent)! | ||
| let node_indices = make_pg_subgraph::<H>( | ||
| self.checker.graph().region_view.clone(), |
There was a problem hiding this comment.
So I guess this is the same backdoor as portgraph_no_syn_edges, and a slight shame I can't use the same method, but here I think it is the right thing to do
This preps the way for #2951 without actually breaking anything: the new
scheduling_graphjust contains the same edges as the Hugr, which still include the nonlocal edges currently required in the spec. (#2951 will then be able to add "fake" edges to thescheduling_graph, but there is no way to add them to theregion_portgraph- such "fake" edges do not go between portgraph ports!)A lot of this can only really be tested when we actually add the synthetic edges in #2951 though, and I haven't written those tests yet...