qiskit-documentation/docs/api/qiskit/qiskit.transpiler.PassManag...

157 lines
7.8 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: PassManager (latest version)
description: API reference for qiskit.transpiler.PassManager in the latest version of qiskit
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.transpiler.PassManager
---
# PassManager
<Class id="qiskit.transpiler.PassManager" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/transpiler/passmanager.py#L37-L257" signature="qiskit.transpiler.PassManager(passes=(), max_iteration=1000)" modifiers="class">
Bases: [`BasePassManager`](qiskit.passmanager.BasePassManager "qiskit.passmanager.passmanager.BasePassManager")
Manager for a set of Passes and their scheduling during transpilation.
Initialize an empty pass manager object.
**Parameters**
* **passes** (*Task |* [*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)")*\[Task]*) A pass set to be added to the pass manager schedule.
* **max\_iteration** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) The maximum number of iterations the schedule will be looped if the condition is not met.
## Methods
### append
<Function id="qiskit.transpiler.PassManager.append" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/transpiler/passmanager.py#L143-L155" signature="append(passes)">
Append a Pass Set to the schedule of passes.
**Parameters**
**passes** (*Task |* [*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)")*\[Task]*) A set of transpiler passes to be added to schedule.
**Raises**
[**TranspilerError**](transpiler#qiskit.transpiler.TranspilerError "qiskit.transpiler.TranspilerError") if a pass in passes is not a proper pass.
</Function>
### draw
<Function id="qiskit.transpiler.PassManager.draw" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/transpiler/passmanager.py#L233-L257" signature="draw(filename=None, style=None, raw=False)">
Draw the pass manager.
This function needs [pydot](https://github.com/erocarrera/pydot), which in turn needs [Graphviz](https://www.graphviz.org/) to be installed.
**Parameters**
* **filename** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")) file path to save image to.
* **style** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)")) 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*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)")) 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](https://pypi.org/project/Pillow/) is not installed.
**Return type**
Optional\[[PassManager](#qiskit.transpiler.PassManager "qiskit.transpiler.PassManager")]
**Raises**
[**ImportError**](https://docs.python.org/3/library/exceptions.html#ImportError "(in Python v3.13)") when nxpd or pydot not installed.
</Function>
### remove
<Function id="qiskit.transpiler.PassManager.remove" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/passmanager/passmanager.py#L96-L108" signature="remove(index)">
Removes a particular pass in the scheduler.
**Parameters**
**index** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) Pass index to remove, based on the position in [`passes()`](transpiler_passes#module-qiskit.transpiler.passes "qiskit.transpiler.passes").
**Raises**
[**PassManagerError**](passmanager#qiskit.passmanager.PassManagerError "qiskit.passmanager.PassManagerError") If the index is not found.
</Function>
### replace
<Function id="qiskit.transpiler.PassManager.replace" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/transpiler/passmanager.py#L157-L168" signature="replace(index, passes)">
Replace a particular pass in the scheduler.
**Parameters**
* **index** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) Pass index to replace, based on the position in passes().
* **passes** (*Task |* [*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)")*\[Task]*) A pass set to be added to the pass manager schedule.
</Function>
### run
<Function id="qiskit.transpiler.PassManager.run" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/transpiler/passmanager.py#L171-L231" signature="run(circuits, output_name=None, callback=None, num_processes=None)">
Run all the passes on the specified `circuits`.
**Parameters**
* **circuits** (*\_CircuitsT*) Circuit(s) to transform via all the registered passes.
* **output\_name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") *| 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:
```python
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
```
<Admonition title="Note" type="note">
Beware that the keyword arguments here are different to those used by the generic [`BasePassManager`](qiskit.passmanager.BasePassManager "qiskit.passmanager.BasePassManager"). This pass manager will translate those arguments into the form described above.
</Admonition>
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:
```python
def callback_func(**kwargs):
pass_ = kwargs['pass_']
dag = kwargs['dag']
time = kwargs['time']
property_set = kwargs['property_set']
count = kwargs['count']
...
```
* **num\_processes** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) The maximum number of parallel processes to launch if parallel execution is enabled. This argument overrides `num_processes` in the user configuration file, and the `QISKIT_NUM_PROCS` environment variable. If set to `None` the system default or local user configuration will be used.
**Returns**
The transformed circuit(s).
**Return type**
\_CircuitsT
</Function>
### to\_flow\_controller
<Function id="qiskit.transpiler.PassManager.to_flow_controller" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/passmanager/passmanager.py#L253-L261" signature="to_flow_controller()">
Linearize this manager into a single [`FlowControllerLinear`](qiskit.passmanager.FlowControllerLinear "qiskit.passmanager.FlowControllerLinear"), so that it can be nested inside another pass manager.
**Returns**
A linearized pass manager.
**Return type**
[*FlowControllerLinear*](qiskit.passmanager.FlowControllerLinear "qiskit.passmanager.flow_controllers.FlowControllerLinear")
</Function>
</Class>