Skip to content
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

feat(hugr-passes): Add nonlocal_edges and ensure_no_nonlocal_edges #1345

Merged
merged 7 commits into from
Jul 25, 2024

Conversation

doug-q
Copy link
Collaborator

@doug-q doug-q commented Jul 25, 2024

Closes #1346

@doug-q doug-q requested a review from a team as a code owner July 25, 2024 07:28
@doug-q doug-q requested a review from ss2165 July 25, 2024 07:28
Copy link

codecov bot commented Jul 25, 2024

Codecov Report

Attention: Patch coverage is 98.41270% with 1 line in your changes missing coverage. Please review.

Project coverage is 87.65%. Comparing base (88af215) to head (cf5ec14).
Report is 3 commits behind head on main.

Files Patch % Lines
hugr-passes/src/non_local.rs 98.41% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1345      +/-   ##
==========================================
+ Coverage   87.59%   87.65%   +0.06%     
==========================================
  Files         112      113       +1     
  Lines       19964    20051      +87     
  Branches    17697    17784      +87     
==========================================
+ Hits        17487    17576      +89     
- Misses       1694     1695       +1     
+ Partials      783      780       -3     
Flag Coverage Δ
python 91.53% <ø> (ø)
rust 87.16% <98.41%> (+0.07%) ⬆️

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.

@doug-q doug-q linked an issue Jul 25, 2024 that may be closed by this pull request
Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

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

Everything except docstring comments are minor

//! This module provides functions for inspecting and modifying the nature of
//! non local edges in a Hugr.
//!
//! TODO Add `remove_nonlocal_edges` and `add_nonlocal_edges` functions
Copy link
Member

Choose a reason for hiding this comment

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

should this go in the module docstring or be left as a comment?


/// Returns an iterator over all non local edges in a Hugr.
///
/// All `(node, in_port)` pairs are returned where `in_port` is connected to a
Copy link
Member

Choose a reason for hiding this comment

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

maybe make clear only checks value ports

hugr.nodes().flat_map(move |node| {
hugr.in_value_types(node).filter_map(move |(in_p, _)| {
hugr.linked_outputs(node, in_p)
.any(|(neighbour_node, _)| hugr.get_parent(node) != hugr.get_parent(neighbour_node))
Copy link
Member

Choose a reason for hiding this comment

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

nit: hugr.get_parent(node) can be computed once outside this closure

hugr-passes/src/non_local.rs Outdated Show resolved Hide resolved
let mut builder = DFGBuilder::new(Signature::new_endo(BOOL_T)).unwrap();
let [in_w] = builder.input_wires_arr();
let ([out_w], edge) = {
let mut builder = builder
Copy link
Member

Choose a reason for hiding this comment

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

nit: give this builder a different name to the outer one to make it easier to parse

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I prefer the same name. It is invalid to refer to the shadowed variable since the new one holds a mutable reference to it. But I do not feel strongly, have renamed.

@doug-q doug-q requested a review from ss2165 July 25, 2024 13:38
Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

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

thanks!

@doug-q doug-q enabled auto-merge July 25, 2024 13:53
@doug-q doug-q added this pull request to the merge queue Jul 25, 2024
Merged via the queue into main with commit ef101a6 Jul 25, 2024
24 checks passed
@doug-q doug-q deleted the doug/nonlocal branch July 25, 2024 14:00
@hugrbot hugrbot mentioned this pull request Jul 25, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jul 29, 2024
## 🤖 New release
* `hugr`: 0.9.1 -> 0.10.0
* `hugr-core`: 0.6.1 -> 0.7.0
* `hugr-passes`: 0.6.1 -> 0.6.2
* `hugr-cli`: 0.2.1 -> 0.3.0

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

## `hugr`
<blockquote>

## 0.10.0 (2024-07-26)

### Bug Fixes

(#1350))
- [**breaking**] Bump serialisation version with no upgrade path
([#1352](#1352))

### Features

- Add `nonlocal_edges` and `ensure_no_nonlocal_edges`
([#1345](#1345))
- Serialization upgrade path
([#1327](#1327))
- [**breaking**] Replace opaque type arguments with String
([#1328](#1328))
- Add `impl Hash for Type`
([#1347](#1347))
- `HasDef` and `HasConcrete` traits for def/concrete op design pattern
([#1336](#1336))
- Add pointer standard extension
([#1337](#1337))
- [**breaking**] Remove the `Eq` type bound.
([#1364](#1364))

### Refactor

- [**breaking**] Use JSON rather than YAML in opaque fields.
([#1338](#1338))
- [**breaking**] Declarative module behind optional feature flag
([#1341](#1341))

### Testing

- Miri gate serialization upgrades
([#1349](#1349))
</blockquote>

## `hugr-core`
<blockquote>

## 0.7.0 (2024-07-26)

### Bug Fixes

(#1350))
- [**breaking**] Bump serialisation version with no upgrade path
([#1352](#1352))

### Features

- Serialization upgrade path
([#1327](#1327))
- [**breaking**] Replace opaque type arguments with String
([#1328](#1328))
- Add `impl Hash for Type`
([#1347](#1347))
- `HasDef` and `HasConcrete` traits for def/concrete op design pattern
([#1336](#1336))
- Add pointer standard extension
([#1337](#1337))
- [**breaking**] Remove the `Eq` type bound.
([#1364](#1364))

### Refactor

- [**breaking**] Use JSON rather than YAML in opaque fields.
([#1338](#1338))
- [**breaking**] Declarative module behind optional feature flag
([#1341](#1341))

### Testing

- Miri gate serialization upgrades
([#1349](#1349))
</blockquote>

## `hugr-passes`
<blockquote>

## 0.6.2 (2024-07-26)

### Features

- Add `nonlocal_edges` and `ensure_no_nonlocal_edges`
([#1345](#1345))
</blockquote>

## `hugr-cli`
<blockquote>

## 0.3.0 (2024-07-26)

### Features

- [**breaking**] Created `validate` CLI subcommand.
([#1312](#1312))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).

---------

Co-authored-by: Douglas Wilson <[email protected]>
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.

Add a pass to check whether there are any non local edges
2 participants