-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Make ComposablePass.__call__ return a Hugr
#2697
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?
Conversation
| passes: list[ComposablePass] | ||
|
|
||
| def __call__(self, hugr: Hugr): | ||
| def __call__(self, hugr: Hugr, inplace: bool = True) -> Hugr: |
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.
Make sure to overrite _apply and _apply_inline, in case some implementor calls them directly
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.
ComposablePass return a HugrComposablePass.__call__ return a Hugr
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2697 +/- ##
==========================================
- Coverage 83.53% 83.50% -0.04%
==========================================
Files 266 266
Lines 51718 51733 +15
Branches 47184 47176 -8
==========================================
- Hits 43204 43201 -3
- Misses 6134 6152 +18
Partials 2380 2380
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
acl-cqc
left a comment
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.
Thanks, Callum - think the interface is ok, I don't have a great solution to the override-at-least-one problem, but a couple of things....
| """Call all of the passes in sequence.""" | ||
| def _apply(self, hugr: Hugr) -> Hugr: | ||
| for comp_pass in self.passes: | ||
| res = comp_pass(hugr, inplace=False) |
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.
This returns the result of the last pass only! You should probably initialize via res = hugr outside the loop and then
| res = comp_pass(hugr, inplace=False) | |
| res = comp_pass(res, inplace=False) |
I'm surprised mypy doesn't complain about this, as if self.passes is empty then return res is returning an uninitialized variable
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.
Good catch! see bfb6f26.
| # At least one of the following _apply methods must be ovewritten | ||
| def _apply(self, hugr: Hugr) -> Hugr: | ||
| hugr = deepcopy(hugr) | ||
| self._apply_inplace(hugr) |
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.
If we were really concerned....you could have an _in_progress:bool on the instance of ComposablePass (not sure but this might mean setattr??), and then check that you didn't get back here with that set (and error if you do)....
I don't see a great solution tho, no
Implementing the revisions to
ComposablePassandComposedPassas discussed with Agustin.I still find the
_applyand_apply_inplacerather unintuitive (although now I realise that it will work). Looking at the default implementations in theComposablePassprotocol these look circular but as you're always overrididing at least one of the_applyor_apply_inplacemethods whenever you implement the protocol.Would be interested to know if there are suggestions to improve this.