Skip to content

refactor: add HugrView::scheduling_graph, deprecate region_portgraph#3015

Open
acl-cqc wants to merge 25 commits intomainfrom
acl/syn_edge_prep
Open

refactor: add HugrView::scheduling_graph, deprecate region_portgraph#3015
acl-cqc wants to merge 25 commits intomainfrom
acl/syn_edge_prep

Conversation

@acl-cqc
Copy link
Copy Markdown
Contributor

@acl-cqc acl-cqc commented Apr 2, 2026

This preps the way for #2951 without actually breaking anything: the new scheduling_graph just 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 the scheduling_graph, but there is no way to add them to the region_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...

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 5, 2026

Codecov Report

❌ Patch coverage is 73.13433% with 72 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.06%. Comparing base (6b9aba6) to head (956f087).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
hugr-core/src/hugr/views/syn_edge.rs 31.76% 56 Missing and 2 partials ⚠️
hugr-core/src/hugr/views/sibling_subgraph.rs 90.00% 7 Missing and 1 partial ⚠️
hugr-core/src/hugr/views.rs 92.30% 3 Missing ⚠️
...ugr-core/src/hugr/views/sibling_subgraph/convex.rs 94.33% 3 Missing ⚠️
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     
Flag Coverage Δ
python 88.89% <ø> (-0.05%) ⬇️
rust 79.80% <73.13%> (-0.29%) ⬇️

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 force-pushed the acl/syn_edge_prep branch from 6db3845 to 521319f Compare April 9, 2026 08:49
@acl-cqc acl-cqc requested a review from aborgna-q April 9, 2026 08:49
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 9, 2026

Merging this PR will degrade performance by 23.65%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 6 regressed benchmarks
✅ 23 untouched benchmarks
⏩ 6 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

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)

Open in CodSpeed

Footnotes

  1. 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};
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This file is basically a straight copy of TopoConvexChecker from portgraph then slightly reparametrized

@@ -0,0 +1,778 @@
use std::collections::BTreeSet;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tests moved out of sibling_subgraph.rs


impl<T: LinkView> pv::GraphBase for SynEdgeWrapper<T> {
type NodeId = NIdx<T::NodeIndexBase>;
type EdgeId = (
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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>)>;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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<
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 -
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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(),
Copy link
Copy Markdown
Contributor Author

@acl-cqc acl-cqc Apr 9, 2026

Choose a reason for hiding this comment

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

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

@acl-cqc acl-cqc marked this pull request as ready for review April 9, 2026 09:26
@acl-cqc acl-cqc requested a review from a team as a code owner April 9, 2026 09:26
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.

1 participant