BasePassManager

class qiskit.passmanager.BasePassManager(tasks=(), max_iteration=1000)[source]

Bases: ABC

Pass manager base class.

Initialize an empty pass manager object.

Parameters:
  • tasks (Task | list[Task]) – A pass set to be added to the pass manager schedule.

  • max_iteration (int) – The maximum number of iterations the schedule will be looped if the condition is not met.

Methods

append(tasks)[source]

Append tasks to the schedule of passes.

Parameters:

tasks (Task | list[Task]) – A set of pass manager tasks to be added to schedule.

Raises:

TypeError – When any element of tasks is not a subclass of passmanager Task.

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, tasks)[source]

Replace a particular pass in the scheduler.

Parameters:
  • index (int) – Task index to replace, based on the position in tasks()

  • tasks (Task | list[Task]) – A set of pass manager tasks to be added to schedule.

Raises:
  • TypeError – When any element of tasks is not a subclass of passmanager Task.

  • PassManagerError – If the index is not found.

run(in_programs, callback=None, **kwargs)[source]

Run all the passes on the specified in_programs.

Parameters:
  • in_programs (Any | list[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:

    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:

    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

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:

FlowControllerLinear