Skip to content

feat: Represent order edges in hugr-model as metadata. #2027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025

Conversation

zrho
Copy link
Contributor

@zrho zrho commented Mar 25, 2025

This PR introduces metadata to encode order edges in hugr-model. The children of a dataflow region can be assigned a key via order_hint.key metadata. Then order_hint.order metadata on the dataflow region encodes order edges between keys. The PR includes the necessary import and export code in hugr-core.

Copy link

codecov bot commented Mar 25, 2025

Codecov Report

Attention: Patch coverage is 61.78862% with 47 lines in your changes missing coverage. Please review.

Project coverage is 83.14%. Comparing base (a16389f) to head (b034d92).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
hugr-core/src/import.rs 51.02% 8 Missing and 16 partials ⚠️
hugr-py/src/hugr/model/export.py 8.00% 23 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2027      +/-   ##
==========================================
- Coverage   83.17%   83.14%   -0.04%     
==========================================
  Files         217      217              
  Lines       42034    42130      +96     
  Branches    38232    38308      +76     
==========================================
+ Hits        34962    35027      +65     
- Misses       5113     5135      +22     
- Partials     1959     1968       +9     
Flag Coverage Δ
python 85.40% <8.00%> (-0.40%) ⬇️
rust 82.91% <75.51%> (-0.01%) ⬇️

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.

Copy link

codspeed-hq bot commented Mar 25, 2025

CodSpeed Performance Report

Merging #2027 will not alter performance

Comparing zrho/model-order-hints (b034d92) with main (a16389f)

Summary

✅ 21 untouched benchmarks

@zrho zrho force-pushed the zrho/model-order-hints branch 2 times, most recently from bca1673 to e4363b6 Compare March 26, 2025 12:21
@hugrbot
Copy link
Collaborator

hugrbot commented Mar 26, 2025

This PR contains breaking changes to the public Rust API.
Please deprecate the old API instead (if possible), or mark the PR with a ! to indicate a breaking change.

cargo-semver-checks summary

--- failure enum_variant_added: enum variant added on exhaustive enum ---

Description:
A publicly-visible enum without #[non_exhaustive] has a new variant.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/enum_variant_added.ron

Failed in:
variant ImportError:OrderHint in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/import.rs:73

@zrho zrho force-pushed the zrho/model-order-hints branch from cd1fef9 to b20c170 Compare March 26, 2025 13:06
@zrho zrho force-pushed the zrho/model-order-hints branch 5 times, most recently from 9cc1bfe to 9ea72ac Compare March 26, 2025 17:38
@zrho zrho marked this pull request as ready for review March 27, 2025 17:16
@zrho zrho requested a review from a team as a code owner March 27, 2025 17:16
@zrho zrho requested a review from jake-arkinstall March 27, 2025 17:16
@zrho zrho force-pushed the zrho/model-order-hints branch from e13e8d5 to ff30662 Compare March 31, 2025 14:46
@zrho zrho requested a review from aborgna-q April 2, 2025 08:51
@aborgna-q aborgna-q changed the base branch from main to zrho/model-package April 2, 2025 10:26
Copy link
Collaborator

@aborgna-q aborgna-q left a comment

Choose a reason for hiding this comment

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

LGTM 👍

It may be interesting to add order edges to the capnp roundtrip benchmark.
Apparently a big chunk of the export rn is taken by string formatting in make_qualified_name 🫠

Comment on lines 612 to 613
.map(|(successor, _)| successor)
.filter(|successor| !self.hugr.get_optype(*successor).is_output());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since order edges are always local, you should be able to cache the output node and avoid fetching the successor's optype here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

(meta (core.order_hint.order 1 2))
(meta (core.order_hint.order 1 0))
(meta (core.order_hint.order 2 3))
(meta (core.order_hint.order 0 3))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mix in some unrelated metadata to test that everything gets preserved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It won't since hugr-core doesn't have the concept of regions, and so only metadata on nodes is preserved so far.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Base automatically changed from zrho/model-package to main April 2, 2025 12:59
@zrho zrho force-pushed the zrho/model-order-hints branch from 8d68b5d to b034d92 Compare April 2, 2025 13:11
@zrho zrho added this pull request to the merge queue Apr 2, 2025
Merged via the queue into main with commit 09de9e3 Apr 2, 2025
23 of 25 checks passed
@zrho zrho deleted the zrho/model-order-hints branch April 2, 2025 14:30
This was referenced Apr 2, 2025
github-merge-queue bot pushed a commit that referenced this pull request Apr 2, 2025
## 🤖 New release

* `hugr-model`: 0.18.1 -> 0.19.0 (⚠ API breaking changes)
* `hugr-core`: 0.15.2 -> 0.15.3 ~(⚠ API breaking changes)~
* `hugr-llvm`: 0.15.2 -> 0.15.3 (✓ API compatible changes)
* `hugr-passes`: 0.15.2 -> 0.15.3 (✓ API compatible changes)
* `hugr`: 0.15.2 -> 0.15.3 (✓ API compatible changes)
* `hugr-cli`: 0.15.2 -> 0.15.3 (✓ API compatible changes)

### ⚠ `hugr-model` breaking changes

```text
--- 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.40.0/src/lints/enum_missing.ron

Failed in:
  enum hugr_model::v0::table::ExtSetPart, previously in file /tmp/.tmpDqJ3X7/hugr-model/src/v0/table/mod.rs:352

--- failure enum_variant_added: enum variant added on exhaustive enum ---

Description:
A publicly-visible enum without #[non_exhaustive] has a new variant.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/enum_variant_added.ron

Failed in:
  variant Term:Func in /tmp/.tmpIpZPlW/hugr/hugr-model/src/v0/table/mod.rs:341

--- 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.40.0/src/lints/enum_variant_missing.ron

Failed in:
  variant Term::ExtSet, previously in file /tmp/.tmpDqJ3X7/hugr-model/src/v0/table/mod.rs:316
  variant Term::ConstFunc, previously in file /tmp/.tmpDqJ3X7/hugr-model/src/v0/table/mod.rs:321
  variant Term::ExtSet, previously in file /tmp/.tmpDqJ3X7/hugr-model/src/v0/ast/mod.rs:237

--- failure pub_module_level_const_missing: pub module-level const is missing ---

Description:
A public const is missing or renamed
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/pub_module_level_const_missing.ron

Failed in:
  CORE_EXT_SET in file /tmp/.tmpDqJ3X7/hugr-model/src/v0/mod.rs:177
```

### ⚠ `hugr-core` breaking changes (⚠️ ignored ⚠️ )

```text
--- failure enum_variant_added: enum variant added on exhaustive enum ---

Description:
A publicly-visible enum without #[non_exhaustive] has a new variant.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/enum_variant_added.ron

Failed in:
  variant ImportError:OrderHint in /tmp/.tmpIpZPlW/hugr/hugr-core/src/import.rs:73
```

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

## `hugr-model`

<blockquote>

##
[0.19.0](hugr-model-v0.18.1...hugr-model-v0.19.0)
- 2025-04-02

### New Features

- Python bindings for `hugr-model`.
([#1959](#1959))
- Remove extension sets from `hugr-model`.
([#2031](#2031))
- Packages in `hugr-model` and envelope support.
([#2026](#2026))
- Represent order edges in `hugr-model` as metadata.
([#2027](#2027))
</blockquote>

## `hugr-core`

<blockquote>

##
[0.16.0](hugr-core-v0.15.2...hugr-core-v0.16.0)
- 2025-04-02

### Documentation

- Provide docs for array ops, fix bad doc for HugrView::poly_func_type
([#2021](#2021))

### New Features

- Expand SimpleReplacement API
([#1920](#1920))
- Python bindings for `hugr-model`.
([#1959](#1959))
- ReplaceTypes pass allows replacing extension types and ops
([#1989](#1989))
- Remove extension sets from `hugr-model`.
([#2031](#2031))
- Packages in `hugr-model` and envelope support.
([#2026](#2026))
- Represent order edges in `hugr-model` as metadata.
([#2027](#2027))
- add `build_expect_sum` to allow specific error messages
([#2032](#2032))
</blockquote>

## `hugr-llvm`

<blockquote>

##
[0.16.0](hugr-llvm-v0.15.2...hugr-llvm-v0.16.0)
- 2025-04-02

### New Features

- *(hugr-llvm)* Add llvm codegen for `arithmetic.float.fpow`
([#2042](#2042))
- *(hugr-llvm)* Emit divmod and mod operations
([#2025](#2025))
</blockquote>

## `hugr-passes`

<blockquote>

##
[0.16.0](hugr-passes-v0.15.2...hugr-passes-v0.16.0)
- 2025-04-02

### New Features

- ReplaceTypes pass allows replacing extension types and ops
([#1989](#1989))
- MakeTuple->UnpackTuple elision pass
([#2012](#2012))
- [**breaking**] Extend LowerTypes pass to linearize by inserting
copy/discard ([#2018](#2018))
</blockquote>

## `hugr`

<blockquote>

##
[0.16.0](hugr-v0.15.2...hugr-v0.16.0)
- 2025-04-02

### Documentation

- Provide docs for array ops, fix bad doc for HugrView::poly_func_type
([#2021](#2021))

### New Features

- MakeTuple->UnpackTuple elision pass
([#2012](#2012))
- [**breaking**] Extend LowerTypes pass to linearize by inserting
copy/discard ([#2018](#2018))
- Expand SimpleReplacement API
([#1920](#1920))
- Python bindings for `hugr-model`.
([#1959](#1959))
- ReplaceTypes pass allows replacing extension types and ops
([#1989](#1989))
- Remove extension sets from `hugr-model`.
([#2031](#2031))
- Represent order edges in `hugr-model` as metadata.
([#2027](#2027))
- add `build_expect_sum` to allow specific error messages
([#2032](#2032))
- Packages in `hugr-model` and envelope support.
([#2026](#2026))
</blockquote>

## `hugr-cli`

<blockquote>

##
[0.16.0](hugr-cli-v0.15.2...hugr-cli-v0.16.0)
- 2025-04-02

### Documentation

- Add usage info to hugr-cli's rustdocs
([#2044](#2044))
</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]>
This was referenced Apr 8, 2025
@hugrbot hugrbot mentioned this pull request Apr 15, 2025
aborgna-q added a commit that referenced this pull request Apr 15, 2025
#2027 ended up being breaking due to adding a new variant to an error
enum missing the `non_exhaustive` marker.

This (breaking) PR makes sure all error enums have the flag.

BREAKING CHANGE: Marked all Error enums as `non_exhaustive`
github-merge-queue bot pushed a commit that referenced this pull request Apr 16, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.11.5](hugr-py-v0.11.4...hugr-py-v0.11.5)
(2025-04-16)


### Features

* **hugr-py:** move in result classes from guppylang
([#2084](#2084))
([b6efb03](b6efb03))
* Packages in `hugr-model` and envelope support.
([#2026](#2026))
([a16389f](a16389f))
* Represent order edges in `hugr-model` as metadata.
([#2027](#2027))
([09de9e3](09de9e3))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
@hugrbot hugrbot mentioned this pull request Apr 28, 2025
github-merge-queue bot pushed a commit that referenced this pull request May 7, 2025
## 🤖 New release

* `hugr-model`: 0.19.0 -> 0.19.1 (✓ API compatible changes)
* `hugr-core`: 0.15.3 -> 0.15.4 (✓ API compatible changes)
* `hugr-llvm`: 0.15.3 -> 0.15.4 (~⚠ API breaking changes~ overwriten)
* `hugr-passes`: 0.15.3 -> 0.15.4 (✓ API compatible changes)
* `hugr`: 0.15.3 -> 0.15.4 (✓ API compatible changes)
* `hugr-cli`: 0.15.3 -> 0.15.4 (✓ API compatible changes)

### ⚠ `hugr-llvm` breaking changes

```text
--- failure trait_missing: pub trait removed or renamed ---

Description:
A publicly-visible trait cannot be imported by its prior path. A `pub use` may have been removed, or the trait 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.40.0/src/lints/trait_missing.ron

Failed in:
  trait hugr_llvm::utils::array_op_builder::ArrayOpBuilder, previously in file /tmp/.tmpyTFqSG/hugr-llvm/src/utils/array_op_builder.rs:10
  trait hugr_llvm::utils::ArrayOpBuilder, previously in file /tmp/.tmpyTFqSG/hugr-llvm/src/utils/array_op_builder.rs:10
```

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

## `hugr-model`

<blockquote>

##
[0.19.0](hugr-model-v0.18.1...hugr-model-v0.19.0)
- 2025-04-02

### New Features

- Python bindings for `hugr-model`.
([#1959](#1959))
- Remove extension sets from `hugr-model`.
([#2031](#2031))
- Packages in `hugr-model` and envelope support.
([#2026](#2026))
- Represent order edges in `hugr-model` as metadata.
([#2027](#2027))
</blockquote>

## `hugr-core`

<blockquote>

##
[0.16.0](hugr-core-v0.15.3...hugr-core-v0.16.0)
- 2025-04-30

### New Features

- Export the portgraph hierarchy in HugrInternals
([#2057](#2057))
- Implement Debug for generic Wire<N>s
([#2068](#2068))
- Add ExtensionOp helpers
([#2072](#2072))
- ReplaceTypes: handlers for array constants + linearization
([#2023](#2023))
- move `ArrayOpBuilder` to hugr-core
([#2115](#2115))

### Testing

- Disable IO-dependent tests when running miri
([#2123](#2123))
</blockquote>

## `hugr-llvm`

<blockquote>

##
[0.16.0](hugr-llvm-v0.15.3...hugr-llvm-v0.16.0)
- 2025-04-30

### New Features

- move `ArrayOpBuilder` to hugr-core
([#2115](#2115))
</blockquote>

## `hugr-passes`

<blockquote>

##
[0.16.0](hugr-passes-v0.15.3...hugr-passes-v0.16.0)
- 2025-04-30

### New Features

- ReplaceTypes: handlers for array constants + linearization
([#2023](#2023))
</blockquote>

## `hugr`

<blockquote>

##
[0.16.0](hugr-v0.15.3...hugr-v0.16.0)
- 2025-04-30

### New Features

- Export the portgraph hierarchy in HugrInternals
([#2057](#2057))
- Implement Debug for generic Wire<N>s
([#2068](#2068))
- Add ExtensionOp helpers
([#2072](#2072))
- ReplaceTypes: handlers for array constants + linearization
([#2023](#2023))
- move `ArrayOpBuilder` to hugr-core
([#2115](#2115))

### Testing

- Disable IO-dependent tests when running miri
([#2123](#2123))
</blockquote>

## `hugr-cli`

<blockquote>

##
[0.15.3](hugr-cli-v0.15.2...hugr-cli-v0.15.3)
- 2025-04-02

### Documentation

- Add usage info to hugr-cli's rustdocs
([#2044](#2044))
</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]>
aborgna-q added a commit that referenced this pull request May 7, 2025
#2027 ended up being breaking due to adding a new variant to an error
enum missing the `non_exhaustive` marker.

This (breaking) PR makes sure all error enums have the flag.

BREAKING CHANGE: Marked all Error enums as `non_exhaustive`
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