-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Legacy code removal in pass manager #11448
Legacy code removal in pass manager #11448
Conversation
One or more of the the following people are requested to review this:
|
This is necessary because kwargs is going to be removed from append method. Current pass list is generated based on the kwargs.
This also removes FlowController factory class
778428e
to
7cf2358
Compare
Pull Request Test Coverage Report for Build 7417016020Warning: This coverage report may be inaccurate.We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
💛 - Coveralls |
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.
For the most part this looks sensible to me, though it's rather hard to verify that the preset passmanagers have stayed logically the same; it perhaps would have been easier to do the simple one-to-one replacements in this PR, and have a follow-up that does the refactoring of the logic, so the two can be checked separately. I tried to check them, but I'm not certain I'd have spotted a potential mistake.
Other than that, mostly just the additional question about transpiler.PassManager.passes
- I'm not certain that keeping around the list format is a good idea, especially if it's in principal only for the visualisation. Exposing a tasks()
method that returns a copy of the raw underlying list seems fine, though (maybe even on BasePassManager
).
raise KeyError("Flow controller not found: %s" % name) | ||
del cls.registered_controllers[name] | ||
cls.hierarchy.remove(name) | ||
FlowController = BaseController |
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.
Do we need to keep this name around now, or can we just rely on BaseController
?
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.
Not necessary. The alias is removed in 6e6d90e. I was just worried about deprecation of import path.
qiskit/transpiler/passmanager.py
Outdated
def _write_passes_recursive(tasks: BaseController | GenericPass | Sequence): | ||
"""Write passmanager passes list for visualization. | ||
|
||
Conventionally, conditional flow controllers were initialized through .append() method | ||
with keyword arguments. | ||
|
||
pm = PassManager() | ||
pm.append([PassA, PassB]) | ||
pm.append([PassC, PassD], condition=callable) | ||
pm.append([PassE]) |
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 this function is purely for visualisation, it should be in the pass_manager_visualization
module, most likely. We should probably deprecate and remove PassManager.passes
in favour of the flat PassManager.tasks
, which I think already exists?
We shouldn't attempt to keep the recursive list structure around into the future; we already know that it's insufficient to represent even existing flow controllers, let alone future ones in the new structure.
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 reverts commit 4bcfcd6.
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 Naoki for making the modifications to this - it was 100x easier to check the changes to the preset pass managers, and it's clear that the vast majority of cases have 1:1 replacements that are strictly more powerful now.
) | ||
) | ||
|
||
Note that you can manage the pecking order of controllers when you want to nest them, |
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.
pecking order
I love this description!
|
||
|
||
class DoXTimesController(FlowController): | ||
"""A control-flow plugin for running a set of passes an X amount of times.""" | ||
|
||
def __init__(self, passes, options, do_x_times, **_): | ||
super().__init__(options) | ||
self.passes = passes | ||
self.do_x_times = do_x_times | ||
|
||
# pylint: disable=missing-function-docstring | ||
def iter_tasks(self, metadata): | ||
for _ in range(self.do_x_times(metadata.property_set)): | ||
for pass_ in self.passes: | ||
metadata = yield pass_ | ||
|
||
|
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 is removed because it's tested as part of qiskit.passmanager
elsewhere, I assume?
* Remove flow controller subclass .append * Update builtin pass managers to avoid append pattern * Remove running pass manager * Remove PropertySet and Fenced objects from transpile * Remove _pass_sets and let PassManager generate pass list on the fly This is necessary because kwargs is going to be removed from append method. Current pass list is generated based on the kwargs. * Remove kwargs from PassManager.append and .replace This also removes FlowController factory class * Remove max_iteration keyword from append and replace * Reno * minor: fix test and docs * Remove qiskit.passmanager.flow_controllers.FlowController * Remove .passes method from PassManager and StagedPassManager * Update reference image of pass manager drawer test * minor: fix drawer label generation * Revert "Update builtin pass managers to avoid append pattern" This reverts commit 4bcfcd6. * Minimum update of builtin pass managers
Summary
This PR is a followup of #10127 in which several methods and classes were deprecated. This PR removes deprecated code, and introduces new pattern to build pass pipeline.
Details and comments
The main goal of this PR is to remove following pattern to a build pass pipeline.
This pattern implicitly calls a factory function to create flow controller instances and wrap the passes
my_pass*
with them, by digesting the controller namespace defined inFlowController
class attributes. This also internally tracks the group of passes appended together along with the specified controller names, with the extra overhead of memory footprint., i.e.PassManager._pass_sets
.With this PR, this append pattern is almost eliminated. Users now need to explicitly instantiate the controller class instead of using the syntactic sugar above. This drastically simplifies the factory logic, and the user can also precisely manage the building of nested controllers.
In addition to this, following classes and methods are also removed.