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

130 lines
5.3 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
description: API reference for qiskit.passmanager.BasePassManager
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/0.45/qiskit/passmanager/passmanager.py" 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.12)")
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.12)")*\[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.12)")) The maximum number of iterations the schedule will be looped if the condition is not met.
## Methods
### append
<Function id="qiskit.passmanager.BasePassManager.append" 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.12)")*\[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.12)") When any element of tasks is not a subclass of passmanager Task.
</Function>
### remove
<Function id="qiskit.passmanager.BasePassManager.remove" 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.12)")) 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" 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.12)")) 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.12)")*\[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.12)") 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" signature="run(in_programs, callback=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.12)")*\[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']
...
```
* **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" 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>