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

fix: Panic on SimpleReplace with multiports #1324

Merged
merged 5 commits into from
Jul 19, 2024
Merged

Conversation

aborgna-q
Copy link
Collaborator

Fixes #1323

This fix generalises the one from #1191.
SimpleReplace was too eager in disconnecting/connecting edges to the replacement graph, and that caused issues when querying the neighbours of multiports.

This gets resolved by delaying all new connections to the replacement until after we have computed all of them.
We don't need to do explicit disconnections to the replaced subgraph, since the nodes get removed anyway.

@aborgna-q aborgna-q requested a review from a team as a code owner July 17, 2024 13:00
@aborgna-q aborgna-q requested a review from doug-q July 17, 2024 13:00
Copy link

codecov bot commented Jul 17, 2024

Codecov Report

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

Project coverage is 87.45%. Comparing base (b832274) to head (3e296e1).
Report is 1 commits behind head on main.

Files Patch % Lines
hugr-core/src/hugr/rewrite/simple_replace.rs 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1324      +/-   ##
==========================================
+ Coverage   87.31%   87.45%   +0.13%     
==========================================
  Files         108      108              
  Lines       19784    19791       +7     
  Branches    17520    17527       +7     
==========================================
+ Hits        17275    17308      +33     
+ Misses       1724     1717       -7     
+ Partials      785      766      -19     
Flag Coverage Δ
rust 86.94% <90.00%> (+0.15%) ⬆️

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.

Copy link
Collaborator

@doug-q doug-q left a comment

Choose a reason for hiding this comment

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

Nice improvement, thank you. I couple of minor nits, but do lmk if you disagree. Happy to approve when you're ready.

hugr-core/src/hugr/rewrite/simple_replace.rs Outdated Show resolved Hide resolved
hugr-core/src/hugr/rewrite/simple_replace.rs Outdated Show resolved Hide resolved
/// Returns the hugr and the nodes of the NOT gates, in order.
#[fixture]
pub(in crate::hugr::rewrite) fn dfg_hugr_half_not_bools() -> (Hugr, Vec<Node>) {
fn build() -> Result<(Hugr, Vec<Node>), BuildError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer to not return a result, instead unwrap everywhere. This makes failures much easier to debug.

hugr-core/src/hugr/rewrite/simple_replace.rs Outdated Show resolved Hide resolved
#[rstest]
fn test_half_nots(
dfg_hugr_half_not_bools: (Hugr, Vec<Node>),
) -> Result<(), Box<dyn std::error::Error>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again I prefer no Result.


let subgraph = SiblingSubgraph::try_from_nodes(vec![input_not, output_not_0], &hugr)?;
// A map from (target ports of edges from the Input node of `replacement`) to (target ports of
// edges from nodes not in `removal` to nodes in `removal`).
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm glad I'm not the only one who finds this v confusing

hugr-core/src/hugr/rewrite/simple_replace.rs Outdated Show resolved Hide resolved
aborgna-q and others added 2 commits July 19, 2024 09:32
Co-authored-by: Douglas Wilson <141026920+doug-q@users.noreply.github.com>
@aborgna-q aborgna-q requested a review from doug-q July 19, 2024 08:40
Copy link
Collaborator

@doug-q doug-q left a comment

Choose a reason for hiding this comment

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

Thank you!

@aborgna-q aborgna-q added this pull request to the merge queue Jul 19, 2024
Merged via the queue into main with commit dae7e67 Jul 19, 2024
20 checks passed
@aborgna-q aborgna-q deleted the ab/fix-simple-replace branch July 19, 2024 08:55
@hugrbot hugrbot mentioned this pull request Jul 19, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jul 19, 2024
## 🤖 New release
* `hugr`: 0.8.0 -> 0.9.0
* `hugr-core`: 0.5.0 -> 0.6.0
* `hugr-passes`: 0.5.0 -> 0.6.0
* `hugr-cli`: 0.1.4 -> 0.2.0

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

## `hugr`
<blockquote>

## 0.9.0 (2024-07-19)

### Bug Fixes

- Add op's extension to signature check in `resolve_opaque_op`
([#1317](#1317))
- Panic on `SimpleReplace` with multiports
([#1324](#1324))

### Refactor

- [**breaking**] Separate Signature from FuncValueType by parametrizing
Type(/Row)/etc. ([#1138](#1138))

### Testing

- Verify order edges ([#1293](#1293))
- Add failing test case for
[#1315](#1315)
([#1316](#1316))
</blockquote>

## `hugr-core`
<blockquote>

## 0.6.0 (2024-07-19)

### Bug Fixes

- Add op's extension to signature check in `resolve_opaque_op`
([#1317](#1317))
- Panic on `SimpleReplace` with multiports
([#1324](#1324))

### Refactor

- [**breaking**] Separate Signature from FuncValueType by parametrizing
Type(/Row)/etc. ([#1138](#1138))

### Testing

- Verify order edges ([#1293](#1293))
- Add failing test case for
[#1315](#1315)
([#1316](#1316))
</blockquote>

## `hugr-passes`
<blockquote>

## 0.6.0 (2024-07-19)

### Refactor

- [**breaking**] Separate Signature from FuncValueType by parametrizing
Type(/Row)/etc. ([#1138](#1138))
</blockquote>

## `hugr-cli`
<blockquote>

## 0.2.0 (2024-07-19)

### Refactor

- [**breaking**] Separate Signature from FuncValueType by parametrizing
Type(/Row)/etc. ([#1138](#1138))
</blockquote>


</p></details>

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

---------

Co-authored-by: Douglas Wilson <douglas.wilson@quantinuum.com>
github-merge-queue bot pushed a commit to CQCL/tket2 that referenced this pull request Jul 19, 2024
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.

Unwrap panic on SimpleReplace
2 participants