PassManager¶
- class qiskit.transpiler.PassManager(passes=(), max_iteration=1000)[source]¶
Bases:
BasePassManager
Manager for a set of Passes and their scheduling during transpilation.
Initialize an empty pass manager object.
- Parameters:
Methods
- append(passes, max_iteration=None, **flow_controller_conditions)[source]¶
Append a Pass Set to the schedule of passes.
Deprecated since version 0.25_pending:
qiskit.transpiler.passmanager.PassManager.append()
’s argumentmax_iteration
is pending deprecation as of qiskit-terra 0.25. It will be marked deprecated in a future release, and then removed no earlier than 3 months after the release date. ‘max_iteration’ can be set in the constructor.- Parameters:
passes (Task | list[Task]) – A set of passes (a pass set) to be added to schedule. A pass set is a list of passes that are controlled by the same flow controller. If a single pass is provided, the pass set will only have that pass a single element. It is also possible to append a
BaseFlowController
instance and the rest of the parameter will be ignored.max_iteration (int) – max number of iterations of passes.
flow_controller_conditions (Any) –
Dictionary of control flow plugins. Following built-in controllers are available by default:
do_while: The passes repeat until the callable returns False. Corresponds to
DoWhileController
.condition: The passes run only if the callable returns True. Corresponds to
ConditionalController
.
In general, you have more control simply by creating the controller you want and passing it to
append()
.
- Raises:
TranspilerError – if a pass in passes is not a proper pass.
- draw(filename=None, style=None, raw=False)[source]¶
Draw the pass manager.
This function needs pydot, which in turn needs Graphviz to be installed.
- Parameters:
filename (str) – file path to save image to.
style (dict) – keys are the pass classes and the values are the colors to make them. An example can be seen in the DEFAULT_STYLE. An ordered dict can be used to ensure a priority coloring when pass falls into multiple categories. Any values not included in the provided dict will be filled in from the default dict.
raw (bool) – If
True
, save the raw Dot output instead of the image.
- Returns:
an in-memory representation of the pass manager, or
None
if no image was generated or Pillow is not installed.- Return type:
Optional[PassManager]
- Raises:
ImportError – when nxpd or pydot not installed.
- remove(index)[source]¶
Removes a particular pass in the scheduler.
- Parameters:
index (int) – Pass index to remove, based on the position in
passes()
.- Raises:
PassManagerError – If the index is not found.
- replace(index, passes, max_iteration=None, **flow_controller_conditions)[source]¶
Replace a particular pass in the scheduler.
Deprecated since version 0.25_pending:
qiskit.transpiler.passmanager.PassManager.replace()
’s argumentmax_iteration
is pending deprecation as of qiskit-terra 0.25. It will be marked deprecated in a future release, and then removed no earlier than 3 months after the release date. ‘max_iteration’ can be set in the constructor.- Parameters:
index (int) – Pass index to replace, based on the position in passes().
passes (Task | list[Task]) – A pass set to be added to the pass manager schedule.
max_iteration (int) – max number of iterations of passes.
flow_controller_conditions (Any) – Dictionary of control flow plugins. See
qiskit.transpiler.PassManager.append()
for details.
- run(circuits, output_name=None, callback=None)[source]¶
Run all the passes on the specified
circuits
.- Parameters:
circuits (_CircuitsT) – Circuit(s) to transform via all the registered passes.
output_name (str | None) – The output circuit name. If
None
, it will be set to the same as the input circuit name.callback (Callable) –
A callback function that will be called after each pass execution. The function will be called with 5 keyword arguments:
pass_ (Pass): the pass being run dag (DAGCircuit): the dag output of the pass time (float): the time to execute the pass property_set (PropertySet): the property set count (int): the index for the pass execution
Note
Beware that the keyword arguments here are different to those used by the generic
BasePassManager
. This pass manager will translate those arguments into the form described above.The exact arguments pass expose the internals of the pass manager and are subject to change as the pass manager internals change. If you intend to reuse a callback function over multiple releases be sure to check that the arguments being passed are the same.
To use the callback feature you define a function that will take in kwargs dict and access the variables. For example:
def callback_func(**kwargs): pass_ = kwargs['pass_'] dag = kwargs['dag'] time = kwargs['time'] property_set = kwargs['property_set'] count = kwargs['count'] ...
- Returns:
The transformed circuit(s).
- Return type:
_CircuitsT
- to_flow_controller()[source]¶
Linearize this manager into a single
FlowControllerLinear
, so that it can be nested inside another pass manager.- Returns:
A linearized pass manager.
- Return type:
RunningPassManager