Add memoization to StagedPassmanager#8277
Conversation
|
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
84fc1a7 to
b70f30c
Compare
Pull Request Test Coverage Report for Build 2590459825
💛 - Coveralls |
jakelishman
left a comment
There was a problem hiding this comment.
This feels like a lot of complexity - _validate_init_kwargs is always called during __init__, so the expanded_stages object is always created anyway. If the issue is purely about __setattr__, then it would be better to just handle that in __setattr__: something like having both self.expanded_stages accesses be getattr(self, "_expanded_stages", ()) would sidestep the issue - if _expanded_stages hasn't yet been set, then it'll just default to an empty set, and __setattr__ will always do the right thing.
cached_property is effectively just a different way of sidestepping the underlying __setattr__ issue - it directly gets the __dict__ from the object it's attached to, and then does its gets and sets into that rather than using the regular structures.
|
This has merge conflicts due to the rewriting of the pass-manager structures in #10124 and #10127. Given my above comment, I'm not super clear that the additional complexity added by this PR is worthwhile, but if this is something you feel strongly should be included in the |
Summary
Simplifies code and improves readability by introducing memoization for
expanded_stagesinStagedPassmanagerthrough thecached_propertydecorator in functools. @mtreinish @jakelishmanDetails and comments
__setattr__.self._expanded_stagesattribute.self.expanded_stagesimmutability.