Skip to main contentIBM Quantum Documentation
You are viewing the API reference for an old version of Qiskit SDK. Switch to latest version

StagedPassManager

StagedPassManager(stages=None, **kwargs)

GitHub(opens in a new tab)

Bases: qiskit.transpiler.passmanager.PassManager

A Pass manager pipeline built up of individual stages

This class enables building a compilation pipeline out of fixed stages. Each StagedPassManager defines a list of stages which are executed in a fixed order, and each stage is defined as a standalone PassManager instance. There are also pre_ and post_ stages for each defined stage. This enables easily composing and replacing different stages and also adding hook points to enable programmtic modifications to a pipeline. When using a staged pass manager you are not able to modify the individual passes and are only able to modify stages.

By default instances of StagedPassManager define a typical full compilation pipeline from an abstract virtual circuit to one that is optimized and capable of running on the specified backend. The default pre-defined stages are:

  1. init - any initial passes that are run before we start embedding the circuit to the backend
  2. layout - This stage runs layout and maps the virtual qubits in the circuit to the physical qubits on a backend
  3. routing - This stage runs after a layout has been run and will insert any necessary gates to move the qubit states around until it can be run on backend’s compuling map.
  4. translation - Perform the basis gate translation, in other words translate the gates in the circuit to the target backend’s basis set
  5. optimization - The main optimization loop, this will typically run in a loop trying to optimize the circuit until a condtion (such as fixed depth) is reached.
  6. scheduling - Any hardware aware scheduling passes
Note

For backwards compatibility the relative positioning of these default stages will remain stable moving forward. However, new stages may be added to the default stage list in between current stages. For example, in a future release a new phase, something like logical_optimization, could be added immediately after the existing init stage in the default stage list. This would preserve compatibility for pre-existing StagedPassManager users as the relative positions of the stage are preserved so the behavior will not change between releases.

These stages will be executed in order and any stage set to None will be skipped. If a stage is provided multiple times (i.e. at diferent relative positions), the associated passes, including pre and post, will run once per declaration. If a PassManager input is being used for more than 1 stage here (for example in the case of a Pass that covers both Layout and Routing) you will want to set that to the earliest stage in sequence that it covers.

Initialize a new StagedPassManager object

Parameters

  • stages (Iterable[str]) – An optional list of stages to use for this instance. If this is not specified the default stages list ['init', 'layout', 'routing', 'translation', 'optimization', 'scheduling'] is used. After instantiation, the final list will be immutable and stored as tuple. If a stage is provided multiple times (i.e. at diferent relative positions), the associated passes, including pre and post, will run once per declaration.
  • kwargs – The initial PassManager values for any stages defined in stages. If a argument is not defined the stages will default to None indicating an empty/undefined stage.

Raises

  • AttributeError – If a stage in the input keyword arguments is not defined.
  • ValueError – If an invalid stage name is specified.

Methods

append

StagedPassManager.append(passes, max_iteration=None, **flow_controller_conditions)

Append a Pass Set to the schedule of passes.

Parameters

  • passes (Union[BasePass, List[BasePass]]) – 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 FlowController instance and the rest of the parameter will be ignored.
  • max_iteration (Optional[int]) – max number of iterations of passes.
  • flow_controller_conditions (Any) – control flow plugins.

Raises

TranspilerError – if a pass in passes is not a proper pass.

See also

RunningPassManager.add_flow_controller() for more information about the control flow plugins.

Return type

None

draw

StagedPassManager.draw(filename=None, style=None, raw=False)

Draw the pass manager.

This function needs pydot(opens in a new tab), which in turn needs Graphviz(opens in a new tab) 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(opens in a new tab) is not installed.

Return type

Optional[PassManager]

Raises

ImportError – when nxpd or pydot not installed.

passes

StagedPassManager.passes()

Return a list structure of the appended passes and its options.

Return type

List[Dict[str, BasePass]]

Returns

A list of pass sets, as defined in append().

remove

StagedPassManager.remove(index)

Removes a particular pass in the scheduler.

Parameters

index (int) – Pass index to replace, based on the position in passes().

Raises

TranspilerError – if the index is not found.

Return type

None

replace

StagedPassManager.replace(index, passes, max_iteration=None, **flow_controller_conditions)

Replace a particular pass in the scheduler.

Parameters

  • index (int) – Pass index to replace, based on the position in passes().
  • passes (Union[BasePass, List[BasePass]]) – A pass set (as defined in qiskit.transpiler.PassManager.append()) to be added to the pass manager schedule.
  • max_iteration (Optional[int]) – max number of iterations of passes.
  • flow_controller_conditions (Any) – control flow plugins.

Raises

TranspilerError – if a pass in passes is not a proper pass or index not found.

See also

RunningPassManager.add_flow_controller() for more information about the control flow plugins.

Return type

None

run

StagedPassManager.run(circuits, output_name=None, callback=None)

Run all the passes on the specified circuits.

Parameters

  • circuits (Union[QuantumCircuit, List[QuantumCircuit]]) – Circuit(s) to transform via all the registered passes.

  • output_name (Optional[str]) – The output circuit name. If None, it will be set to the same as the input circuit name.

  • callback (Optional[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

    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']
        ...

Return type

Union[QuantumCircuit, List[QuantumCircuit]]

Returns

The transformed circuit(s).

to_flow_controller

StagedPassManager.to_flow_controller()

Linearize this manager into a single FlowController, so that it can be nested inside another PassManager.

Return type

FlowController


Attributes

expanded_stages

Expanded Pass manager stages including pre_ and post_ phases.

Return type

Tuple[str, ...]

invalid_stage_regex

= re.compile('\\s|\\+|\\-|\\*|\\/|\\\\|\\%|\\<|\\>|\\@|\\!|\\~|\\^|\\&|\\:|\\[|\\]|\\{|\\}|\\(|\\)')

stages

Pass manager stages

Return type

Tuple[str, ...]

Was this page helpful?
Report a bug or request content on GitHub.