Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass manager refactoring: cleanup internals (#10127)
* Refactor internals of pass manager and flow controllers. This PR introduces two changes for * remove tight coupling of flow controller to pass runner instance, * remove pass normalization. PropertySet becomes context var so that flow controllers can be instantiated without coupling to a pass runner instance. BasePass becomes an iterable of length 1 to skip normalization. The decoupling of property set from pass runner allows pass manager to directly broadcast pass runner in the multithread, rather than distributing self and craete multiple pass runner in each thread. * Replace class attribute PASS_RUNNER with property method. This allows subclass to dispatch different pass runner type depending on the target code. * Refactor passmanager module - Add OptimizerTask as a protocol for the pass and flow controller. These are in principle the same object that inputs and outputs IR with optimization. - A task gains execute method that takes IR and property set. This makes property set local to iteration of the passes. - Drop dependency on pass runner. Now pass manager has a single linear flow controller. - Pass manager gain responsibility of compiler frontend and backend as pass runner dependency is removed. This allows flow controllers to be still type agnostic. - Drop future property set, as this is no longer necessary because optimization task has the execute method explicitly taking the property set. * Refactor transpiler passmanager - Remove pass runner baseclass and replace RunningPassmanager baseclass with FlowControllerLiner - Implemented frontoend and backend functionality in transpiler Pass manager * Rename module: base_pass -> base_optimization_tasks * Backward compatibility fix - Move handling of required passes to generic pass itself. This makes optimizer tasks the composite pattern-like for more readability. - Readd MetaPass to transpiler BasePass as a metaclass which implements predefined equivalence check for all passes. This is necessary to take care of duplicated pass run, which is prohibited in circuit pass manager. - Add FlowControllerMeta that allows users to subclass FlowController, while delegating the pass control to BaseFlowController. - Readd count to pass manager callback - Add PassState that manages the state of execution including PropertySet. This is a portable namespace that can be shared across passes. * Update module documentation * Update release note * lint fix * OptimizationTask -> Task In multi-IR realm task can be something other than optimization. For example IR conversion. Name should not limit operation on subclass. * Typo fix FlowControllerLiner -> FlowControllerLinear * Use RunState value. Set 0 to success case. * Separate property set from pass state. Now Task.execute method has two arguments for property set and pass state. Lifetime of property set data is entire execution of the pass manager, while that of pass state is execution of a single pass. * Pending deprecate fenced_property_set and remove usage. * Pending deprecate FencedObject baseclass and remove usage. * Add some inline comments. * Convert RunState to raw Enum * Change the policy for the use of multiple IRs. Just updated module documentation, no actual code change. Future developer must not introduce strict type check on IR (at least in base classes in the module). * Updated interface of base controller. Namely .append() and .passes are moved to particular subclass and the baseclass is now agnostic to construction of task pipeline. This adds more flexibility to design of conditioned pipelines. Note that PassState is also renamed to WorkflowStatus because this is sort of global mutable variable, rather than local status information of a particular pass. * Remove FlowControllerMeta and turn FlowController into a subclass of BaseController. * Remove dependency on controller_factory method and deprecate. * Update release note * Readd code change in #10835 Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * typehint fix * doc fix * move FencedPropertySet class back to transpiler.fencedobjs * Temporary: add lint ignore * Fix example code in class doc * Tweaks to documentation * Change baseclass of the MetaPass and revert f28cad9 * Update interface of execute and use generator feature. - Add new container class PassmanagerMetadata - Rename propertyset with compilation_status - Provide metadata with the iter_tasks instead of property_set - Send metadata through generator - Turn metadata required, and let pass manager create metadata - Return metadata from execute along with the IR * Update deprecations * Delay instantiation of FlowControllerLinear until execution of pass manager * Stop wrapping a list of tasks with flow controller linear. * Remove flow_controller_conditions from base controller append and add stacklevel to deprecation warning * Misc updates * disable cyclic-import * Remove typecheck * Rename `PassmanagerMetadata` to `PassManagerState` This is primarily to avoid a potential conflict with the terminology `metadata` that's associated with the `input_program`, and because the object is the state object for a pass-manager execution. There is still a risk of confusion with `RunState`, but since that's a subcomponent of `PassManagerState`, it feels fair enough. * Correct warning stacklevel --------- Co-authored-by: Luciano Bello <bel@zurich.ibm.com> Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
- Loading branch information