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: MakeTuple->UnpackTuple elision pass #2012

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

feat: MakeTuple->UnpackTuple elision pass #2012

wants to merge 2 commits into from

Conversation

aborgna-q
Copy link
Collaborator

@aborgna-q aborgna-q commented Mar 20, 2025

Imports the MakeTuple -> UnpackTuple elimination pass from tket2.
This removes tuple unpacks consuming the output of a MakeTuple, and deletes the packing operation when possible.

This pass does not remove the reverse case, Unpack->MakeTuple. Should it be added here? We should avoid producing overlapping rewrites if doing that (the simple Pack->Unpack->Pack case is easy, but multiports can make things interesting).

Requires #2011
Closes #1810

@aborgna-q aborgna-q requested a review from a team as a code owner March 20, 2025 17:13
@aborgna-q aborgna-q requested review from mark-koch and removed request for a team March 20, 2025 17:13
@aborgna-q aborgna-q force-pushed the ab/sibling-subgraph-from-node branch from b3dc6a5 to bad40dc Compare March 20, 2025 17:26
Copy link
Contributor

@mark-koch mark-koch left a comment

Choose a reason for hiding this comment

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

Thanks! Mostly wondering about edge cases with order and inter-graph edges?

Btw, it would be nice to have the opposite UnpackTuple -> MakeTuple elison as well since Guppy sometimes emits those when dealing with structs. Happy for this to be a follow-up though

let mut nodes = unpack_nodes;
nodes.push(pack_node);
let subcirc = SiblingSubgraph::try_from_nodes_with_checker(nodes, hugr, checker).unwrap();
let subcirc_signature = subcirc.signature(hugr);
Copy link
Contributor

Choose a reason for hiding this comment

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

afaik this will panic if there are order edges?


let mut nodes = unpack_nodes;
nodes.push(pack_node);
let subcirc = SiblingSubgraph::try_from_nodes_with_checker(nodes, hugr, checker).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this unwrap safe?

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the make-unpack is an inter-graph edge?

Base automatically changed from ab/sibling-subgraph-from-node to main March 21, 2025 15:17
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.

2 participants