Skip to content

Conversation

@CalMacCQ
Copy link
Contributor

@CalMacCQ CalMacCQ commented Nov 18, 2025

Implementing the revisions to ComposablePass and ComposedPass as discussed with Agustin.

I still find the _apply and _apply_inplace rather unintuitive (although now I realise that it will work). Looking at the default implementations in the ComposablePass protocol these look circular but as you're always overrididing at least one of the _apply or _apply_inplace methods whenever you implement the protocol.

Would be interested to know if there are suggestions to improve this.

@CalMacCQ CalMacCQ requested a review from a team as a code owner November 18, 2025 11:49
@CalMacCQ CalMacCQ requested a review from acl-cqc November 18, 2025 11:49
@CalMacCQ CalMacCQ marked this pull request as draft November 18, 2025 11:50
passes: list[ComposablePass]

def __call__(self, hugr: Hugr):
def __call__(self, hugr: Hugr, inplace: bool = True) -> Hugr:
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CalMacCQ CalMacCQ changed the title feat: Make ComposablePass return a Hugr feat: Make ComposablePass.__call__ return a Hugr Nov 18, 2025
@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

❌ Patch coverage is 26.92308% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.50%. Comparing base (1edeb25) to head (8037052).

Files with missing lines Patch % Lines
hugr-py/src/hugr/passes/_composable_pass.py 30.00% 14 Missing ⚠️
hugr-py/src/hugr/hugr/base.py 16.66% 5 Missing ⚠️
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              
Flag Coverage Δ
python 91.17% <26.92%> (-0.36%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@CalMacCQ CalMacCQ marked this pull request as ready for review November 19, 2025 13:57
@CalMacCQ CalMacCQ requested review from ss2165 and removed request for acl-cqc November 19, 2025 14:01
Copy link
Contributor

@acl-cqc acl-cqc left a 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)
Copy link
Contributor

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

Suggested change
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

Copy link
Contributor Author

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)
Copy link
Contributor

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

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.

4 participants