Skip to content

feat!: do not require an Order edge for each nonlocal Ext edge; compute on demand in scheduling_graph()#2951

Open
acl-cqc wants to merge 53 commits intomainfrom
acl/syn_edges
Open

feat!: do not require an Order edge for each nonlocal Ext edge; compute on demand in scheduling_graph()#2951
acl-cqc wants to merge 53 commits intomainfrom
acl/syn_edges

Conversation

@acl-cqc
Copy link
Copy Markdown
Contributor

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

BREAKING CHANGE: Hugrs are no longer guaranteed to have an Order edge representing the ordering constraint from each nonlocal Ext edge; require HugrView impls to provide scheduling_graph; remove deprecated region_portgraph(), as_petgraph(), into_region_portgraph(), sibling_subgraph::{TopoConvexChecker, ValidationMode, SiblingSubgraph::validate(), ConvexChecker}, ValidationError::MissingOrderEdge

@acl-cqc acl-cqc added this to the hugr-rs 0.28.0 milestone Apr 2, 2026
@acl-cqc acl-cqc changed the base branch from main to acl/syn_edge_prep April 5, 2026 11:31
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 5, 2026

Codecov Report

❌ Patch coverage is 98.03922% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.15%. Comparing base (d6e11c8) to head (09f6d3e).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
hugr-persistent/src/parents_view.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2951      +/-   ##
==========================================
+ Coverage   81.07%   81.15%   +0.07%     
==========================================
  Files         242      240       -2     
  Lines       45183    44954     -229     
  Branches    38951    38724     -227     
==========================================
- Hits        36633    36483     -150     
+ Misses       6585     6497      -88     
- Partials     1965     1974       +9     
Flag Coverage Δ
python 88.86% <ø> (-0.04%) ⬇️
rust 79.91% <98.03%> (+0.09%) ⬆️

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
Base automatically changed from acl/syn_edge_prep to main May 5, 2026 09:50
@acl-cqc acl-cqc changed the title feat!: do not require an Order edge for each nonlocal Ext edge; order_graph computes on demand feat!: do not require an Order edge for each nonlocal Ext edge; compute on demand in scheduling_graph() May 5, 2026
@hugrbot
Copy link
Copy Markdown
Collaborator

hugrbot commented May 5, 2026

This PR contains breaking changes to the public Rust API.

cargo-semver-checks summary
    Building hugr v0.27.1 (current)
     Built [  33.490s] (current)
   Parsing hugr v0.27.1 (current)
    Parsed [   0.004s] (current)
  Building hugr v0.27.1 (baseline)
     Built [  33.827s] (baseline)
   Parsing hugr v0.27.1 (baseline)
    Parsed [   0.004s] (baseline)
  Checking hugr v0.27.1 -> v0.27.1 (assume minor change)
   Checked [   0.011s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  68.785s] hugr
  Building hugr-cli v0.27.1 (current)
     Built [  27.529s] (current)
   Parsing hugr-cli v0.27.1 (current)
    Parsed [   0.006s] (current)
  Building hugr-cli v0.27.1 (baseline)
     Built [  27.558s] (baseline)
   Parsing hugr-cli v0.27.1 (baseline)
    Parsed [   0.006s] (baseline)
  Checking hugr-cli v0.27.1 -> v0.27.1 (assume minor change)
   Checked [   0.015s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  56.729s] hugr-cli
  Building hugr-core v0.27.1 (current)
     Built [  24.114s] (current)
   Parsing hugr-core v0.27.1 (current)
    Parsed [   0.085s] (current)
  Building hugr-core v0.27.1 (baseline)
     Built [  23.996s] (baseline)
   Parsing hugr-core v0.27.1 (baseline)
    Parsed [   0.081s] (baseline)
  Checking hugr-core v0.27.1 -> v0.27.1 (assume minor change)
   Checked [   0.214s] 196 checks: 189 pass, 7 fail, 0 warn, 56 skip

--- failure enum_missing: pub enum removed or renamed ---

Description:
A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/enum_missing.ron

Failed in:
enum hugr_core::hugr::views::sibling_subgraph::ValidationMode, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views/sibling_subgraph.rs:839

--- failure enum_no_repr_variant_discriminant_changed: enum variant had its discriminant change value ---

Description:
The enum's variant had its discriminant value change. This breaks downstream code that used its value via a numeric cast like `as isize`.
      ref: https://doc.rust-lang.org/reference/items/enumerations.html#assigning-discriminant-values
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/enum_no_repr_variant_discriminant_changed.ron

Failed in:
variant InterGraphEdgeError::NoRelation 3 -> 2 in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/hugr/validate.rs:800
variant InterGraphEdgeError::NonDominatedAncestor 4 -> 3 in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/hugr/validate.rs:810

--- failure enum_variant_missing: pub enum variant removed or renamed ---

Description:
A publicly-visible enum has at least one variant that is no longer available under its prior name. It may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/enum_variant_missing.ron

Failed in:
variant InterGraphEdgeError::MissingOrderEdge, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/validate.rs:813

--- failure inherent_method_missing: pub method removed or renamed ---

Description:
A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/inherent_method_missing.ron

Failed in:
SiblingSubgraph::validate, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views/sibling_subgraph.rs:527
SiblingSubgraph::validate, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views/sibling_subgraph.rs:527
Hugr::into_region_portgraph, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/internal.rs:401
Hugr::into_region_portgraph, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/internal.rs:401

--- failure module_missing: pub module removed or renamed ---

Description:
A publicly-visible module cannot be imported by its prior path. A `pub use` may have been removed, or the module may have been renamed, removed, or made non-public.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/module_missing.ron

Failed in:
mod hugr_core::hugr::views::petgraph, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views/petgraph.rs:1

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/struct_missing.ron

Failed in:
struct hugr_core::hugr::views::petgraph::HugrNodeRef, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views/petgraph.rs:190
struct hugr_core::hugr::views::sibling_subgraph::ConvexChecker, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views/sibling_subgraph.rs:1090
struct hugr_core::hugr::views::petgraph::PetgraphWrapper, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views/petgraph.rs:16
struct hugr_core::hugr::views::PetgraphWrapper, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views/petgraph.rs:16

--- failure trait_method_missing: pub trait method removed or renamed ---

Description:
A trait method is no longer callable, and may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-item-signature
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/trait_method_missing.ron

Failed in:
method as_petgraph of trait HugrView, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:397
method as_petgraph of trait HugrView, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:397
method as_petgraph of trait HugrView, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:397
method region_portgraph of trait HugrInternals, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/internal.rs:47

   Summary semver requires new major version: 7 major and 0 minor checks failed
  Finished [  49.279s] hugr-core
  Building hugr-llvm v0.27.1 (current)
     Built [  28.157s] (current)
   Parsing hugr-llvm v0.27.1 (current)
    Parsed [   0.012s] (current)
  Building hugr-llvm v0.27.1 (baseline)
     Built [  28.345s] (baseline)
   Parsing hugr-llvm v0.27.1 (baseline)
    Parsed [   0.012s] (baseline)
  Checking hugr-llvm v0.27.1 -> v0.27.1 (assume minor change)
   Checked [   0.044s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  57.774s] hugr-llvm
  Building hugr-model v0.27.1 (current)
     Built [  10.221s] (current)
   Parsing hugr-model v0.27.1 (current)
    Parsed [   0.016s] (current)
  Building hugr-model v0.27.1 (baseline)
     Built [  10.222s] (baseline)
   Parsing hugr-model v0.27.1 (baseline)
    Parsed [   0.016s] (baseline)
  Checking hugr-model v0.27.1 -> v0.27.1 (assume minor change)
   Checked [   0.029s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  21.282s] hugr-model
  Building hugr-persistent v0.6.1 (current)
     Built [  20.992s] (current)
   Parsing hugr-persistent v0.6.1 (current)
    Parsed [   0.008s] (current)
  Building hugr-persistent v0.6.1 (baseline)
     Built [  21.276s] (baseline)
   Parsing hugr-persistent v0.6.1 (baseline)
    Parsed [   0.007s] (baseline)
  Checking hugr-persistent v0.6.1 -> v0.6.1 (assume minor change)
   Checked [   0.012s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  43.025s] hugr-persistent

@acl-cqc acl-cqc marked this pull request as ready for review May 5, 2026 13:09
@acl-cqc acl-cqc requested a review from a team as a code owner May 5, 2026 13:09
@acl-cqc acl-cqc requested review from cqc-alec and mark-koch and removed request for mark-koch May 5, 2026 13:09
/// The API is designed for `hugr-persistent` and allows to implement [HugrView] such that
/// [HugrInternals::RegionPortgraph] is not tied to the original view but rather an owned
/// temporary [Hugr].
pub fn owned_scheduling_graph<'a, N: HugrNode, V>(
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 broadly equivalent to the removed Hugr::into_region_portgraph from internals.rs; it could be an instance method again (into_scheduling_graph) but seems more consistent in this file.

It is definitely the part of the PR that I'm least keen on!! But either we expose more internal details of SchedulingGraph (which I've been trying to avoid in the design, to keep some flexibility to change in the future), and use those details in hugr-persistent; or, we put some hugr-persistent-specific functionality here. This PR chooses the latter route...
(but it doesn't seem that weird a functionality, even if hugr-persistent is the only place we're using it ATM.)

Thoughts welcome!

Comment thread specification/hugr.md Outdated
respecting the Dataflow edges.** The following operations are used to
express control flow, i.e. conditional or repeated evaluation.

**ALAN this might be a place to either say, and respecting the ordering
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.

Thoughts here?

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.

Yes, could be worth saying that descendent nodes may be interleaved with siblings, subject to the ordering constraints imposed by Dataflow 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.

I have done - I realize that I was actually planning for that to come later along with tweaks to some Hugr code to enact it, but it's not a correction to the spec (it doesn't change anything that was there before AFAICS), merely a clarification; and whilst there is some Hugr code that sort-of-assumes otherwise, I think updating that can be classed as an improvement or optimization (or just possibly bugfix) i.e. in another PR.

So, would you mind having another quick look over the spec 🙏 ? I also explicitly mentioned respecting Order edges too (but not synthetic/nonlocal edges since there is no need to).

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.

(@cqc-alec, sorry!)

Comment thread hugr-py/tests/test_hugr_build.py Outdated

def test_build_inter_graph(snapshot):
# Possibly a bit redundant now, really we're just testing that we *don't* do
# anything special anymore, following https://github.com/Quantinuum/hugr/pulls/2951.
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.

Suggested change
# anything special anymore, following https://github.com/Quantinuum/hugr/pulls/2951.
# anything special anymore, following https://github.com/Quantinuum/hugr/pull/2951.

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 am humbled. I would never have spotted that myself :-)

Comment thread specification/hugr.md Outdated
respecting the Dataflow edges.** The following operations are used to
express control flow, i.e. conditional or repeated evaluation.

**ALAN this might be a place to either say, and respecting the ordering
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.

Yes, could be worth saying that descendent nodes may be interleaved with siblings, subject to the ordering constraints imposed by Dataflow edges.

Copy link
Copy Markdown
Collaborator

@cqc-alec cqc-alec left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants