-
Notifications
You must be signed in to change notification settings - Fork 13
feat(py): a ComposablePass protocol for hugr-py
#2636
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
base: main
Are you sure you want to change the base?
Changes from all commits
eeb4c50
c5cf1d7
8a3d6ba
7b58c05
33e325b
5e31a3d
c52de85
6d7afc2
89fabf0
91879cd
4878d5f
7045270
d20aaaa
954730f
448b5cf
17d1dc8
b6fa9a5
cc9c151
2d10e87
45bd86a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """A hugr-py passes module for hugr transformations.""" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| """A Protocol for a composable pass.""" | ||
|
|
||
| from typing import Protocol | ||
|
|
||
| from typing_extensions import Self | ||
|
|
||
| from hugr.hugr.base import Hugr | ||
| from hugr.hugr.node_port import Node | ||
|
|
||
|
|
||
| class ComposablePass(Protocol): | ||
| """A Protocol which represents a composable Hugr transformation.""" | ||
|
|
||
| def __call__(self, hugr: Hugr) -> None: ... | ||
|
|
||
| def then(self, other: Self) -> Self: ... | ||
|
|
||
| def with_entrypoint(self, entrypoint: Node) -> Self: ... | ||
|
|
||
| @property | ||
| def is_global(self) -> bool: ... | ||
|
|
||
| @property | ||
| def is_recursive(self) -> bool: ... | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this actually mean? In particular in conjunction with
If But I wonder whether it'd be better to combine these into an enum-like thing where we can be more specific (and extensible) about what the possible variants mean?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some transformations (this is perhaps getting a bit complex so maybe never mind) there are actually two variables re. scope:
(1.) probably needs to be a superset of (2.), but you might analyze the whole Hugr in order to change only one function, say (and this would enable more optimization in that function, than if you only analyzed that function alone, but the latter would be cheaper). |
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be
rather than
Implementing the
with_entrypointmethod could also be problematic for reasons I dicussed with Agustin earlier.As far as I know there isn't a way to get the Hugr subgraph given a entrypoint Node in Python. I think in rust there is something like
SiblingSubgraph::try_from_nodesAgustin suggested that we could modify the entrpoint before we apply the pass and then change it back?
Not immediately obvious to me how this would work as we aren't returing an object of type
Self. Maybe we could do something with a context manager here?