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

FlowController

class qiskit.passmanager.FlowController(options=None)

GitHub(opens in a new tab)

Bases: BaseController

A legacy factory for other flow controllers.

Warning

This class is primarily for compatibility with legacy versions of Qiskit, and in general, you should prefer simply instantiating the controller you want, and adding it to the relevant PassManager or other controller. Its use is deprecated.

This allows syntactic sugar for writing pipelines. For example:

FlowController.add_flow_controller("my_condition", CustomController)
 
controller = FlowController.controller_factory(
    [PassA(), PassB()],
    {"max_iteration": 1000},
    condition=lambda prop_set: prop_set["x"] == 0,
    do_while=lambda prop_set: prop_set["x"] < 100,
    my_condition=lambda prop_set: prop_set["y"] = "abc",
)

This creates a nested flow controller that runs when the value x in the PropertySet is zero and repeats the pipeline until the value becomes 100. In each innermost loop, the custom iteration condition provided by the CustomController is also evaluated.

Warning

BaseController must be directly subclassed to define a custom flow controller. This class provides a controller factory method, which consumes a class variable registered_controllers. Subclassing FlowController may cause unexpected behavior in the factory method. Note that factory method implicitly determines the priority of the builtin controllers when multiple controllers are called together, and the behavior of generated controller is hardly debugged.

Create new flow controller.

Parameters

options (dict(opens in a new tab)[str(opens in a new tab), Any] | None) – Option for this flow controller.


Attributes

hierarchy

Default value: ['condition', 'do_while']

registered_controllers

Default value: {'condition': <class 'qiskit.passmanager.flow_controllers.ConditionalController'>, 'do_while': <class 'qiskit.passmanager.flow_controllers.DoWhileController'>}


Methods

add_flow_controller

classmethod add_flow_controller(name, controller)

Adds a flow controller.

Deprecated since version 0.45.0

The method qiskit.passmanager.flow_controllers.FlowController.add_flow_controller() is deprecated as of qiskit 0.45.0. It will be removed no earlier than 3 months after the release date. Controller factory method is deprecated and managing the custom flow controllers with alias no longer helps building the task pipeline. Controllers must be explicitly instantiated and appended to the pipeline.

Parameters

controller_factory

classmethod controller_factory(passes, options, **controllers)

Create a new flow controller with normalization.

Deprecated since version 0.45.0

The method qiskit.passmanager.flow_controllers.FlowController.controller_factory() is deprecated as of qiskit 0.45.0. It will be removed no earlier than 3 months after the release date. Controller object must be explicitly instantiated. Building controller with keyword arguments may yield race condition when multiple keyword arguments are provided together, which is likely unsafe.

Parameters

Returns

An instance of normalized flow controller.

execute

execute(passmanager_ir, state, callback=None)

Execute optimization task for input Qiskit IR.

Parameters

Returns

Optimized Qiskit IR and state of the workflow.

Return type

tuple(opens in a new tab)[Any(opens in a new tab), qiskit.passmanager.compilation_status.PassManagerState]

iter_tasks

abstract iter_tasks(state)

A custom logic to choose a next task to run.

Controller subclass can consume the state to build a proper task pipeline. The updated state after a task execution will be fed back in as the “return” value of any yield statements. This indicates the order of task execution is only determined at running time. This method is not allowed to mutate the given state object.

Parameters

  • state (PassManagerState) – The state of the passmanager workflow at the beginning of this flow controller’s execution.
  • state – the state of pass manager after the execution of the last task that was yielded. The generator does not need to inspect this if it is irrelevant to its logic, nor update it.

Yields

Task – Next task to run.

Return type

Generator(opens in a new tab)[Task, PassManagerState, None]

remove_flow_controller

classmethod remove_flow_controller(name)

Removes a flow controller.

Deprecated since version 0.45.0

The method qiskit.passmanager.flow_controllers.FlowController.remove_flow_controller() is deprecated as of qiskit 0.45.0. It will be removed no earlier than 3 months after the release date. Controller factory method is deprecated and managing the custom flow controllers with alias no longer helps building the task pipeline. Controllers must be explicitly instantiated and appended to the pipeline.

Parameters

name (str(opens in a new tab)) – Alias of the controller to remove.

Raises

KeyError(opens in a new tab) – If the controller to remove was not registered.

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