qiskit-documentation/docs/api/qiskit/1.2/qiskit.passmanager.BasePass...

132 lines
6.2 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: BasePassManager (v1.2)
description: API reference for qiskit.passmanager.BasePassManager in qiskit v1.2
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.passmanager.BasePassManager
---
# BasePassManager
<Class id="qiskit.passmanager.BasePassManager" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/passmanager/passmanager.py#L33-L267" signature="qiskit.passmanager.BasePassManager(tasks=(), max_iteration=1000)" modifiers="class">
Bases: [`ABC`](https://docs.python.org/3/library/abc.html#abc.ABC "(in Python v3.13)")
Pass manager base class.
Initialize an empty pass manager object.
**Parameters**
* **tasks** (*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.passmanager.BasePassManager.append" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/passmanager/passmanager.py#L57-L74" signature="append(tasks)">
Append tasks to the schedule of passes.
**Parameters**
**tasks** (*Task |* [*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)")*\[Task]*) A set of pass manager tasks to be added to schedule.
**Raises**
[**TypeError**](https://docs.python.org/3/library/exceptions.html#TypeError "(in Python v3.13)") When any element of tasks is not a subclass of passmanager Task.
</Function>
### remove
<Function id="qiskit.passmanager.BasePassManager.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()`.
**Raises**
[**PassManagerError**](passmanager#qiskit.passmanager.PassManagerError "qiskit.passmanager.PassManagerError") If the index is not found.
</Function>
### replace
<Function id="qiskit.passmanager.BasePassManager.replace" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/passmanager/passmanager.py#L76-L94" signature="replace(index, tasks)">
Replace a particular pass in the scheduler.
**Parameters**
* **index** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) Task index to replace, based on the position in `tasks()`
* **tasks** (*Task |* [*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)")*\[Task]*) A set of pass manager tasks to be added to schedule.
**Raises**
* [**TypeError**](https://docs.python.org/3/library/exceptions.html#TypeError "(in Python v3.13)") When any element of tasks is not a subclass of passmanager Task.
* [**PassManagerError**](passmanager#qiskit.passmanager.PassManagerError "qiskit.passmanager.PassManagerError") If the index is not found.
</Function>
### run
<Function id="qiskit.passmanager.BasePassManager.run" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/passmanager/passmanager.py#L172-L251" signature="run(in_programs, callback=None, num_processes=None, **kwargs)">
Run all the passes on the specified `in_programs`.
**Parameters**
* **in\_programs** (*Any |* [*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)")*\[Any]*) Input programs to transform via all the registered passes. A single input object cannot be a Python builtin list object. A list object is considered as multiple input objects to optimize.
* **callback** (*Callable*)
A callback function that will be called after each pass execution. The function will be called with 4 keyword arguments:
```python
task (GenericPass): the pass being run
passmanager_ir (Any): depending on pass manager subclass
property_set (PropertySet): the property set
running_time (float): the time to execute the pass
count (int): the index for the pass execution
```
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):
task = kwargs['task']
passmanager_ir = kwargs['passmanager_ir']
property_set = kwargs['property_set']
running_time = kwargs['running_time']
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.
* **kwargs** Arbitrary arguments passed to the compiler frontend and backend.
**Returns**
The transformed program(s).
**Return type**
Any
</Function>
### to\_flow\_controller
<Function id="qiskit.passmanager.BasePassManager.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>