qlauncher.launcher.aql.aql#

Wrapper for QLauncher that enables the user to launch tasks asynchronously (futures + multiprocessing)

Summary#

Classes:

AQL

Launches QLauncher task asynchronously.

Reference#

class qlauncher.launcher.aql.aql.AQL(mode: Literal['default', 'optimize_session'] = 'default')[source]#

Bases: object

Launches QLauncher task asynchronously.

tasks#

list of submitted tasks.

Type:

list[AQLTask]

mode#

Execution mode.

Type:

Literal['default', 'optimize_session']

Usage Example#

aql = AQL(mode='optimize_session')

t_real = aql.add_task(
    (
        GraphColoring.from_preset('small'),
        QAOA(),
        AQTBackend(token='valid_token', name='device')
    ),
    constraints_weight=5,
    costs_weight=1
    )

aql.add_task(
    (
        GraphColoring.from_preset('small'),
        QAOA(),
        QiskitBackend('local_simulator')
    ),
    dependencies=[t_real],
    constraints_weight=5,
    costs_weight=1
)

aql.start()
result_real, result_sim = aql.results(timeout=15)
running_task_count() int[source]#
Returns:

Amount of tasks that are currently executing.

Return type:

int

cancel_running_tasks()[source]#

Cancel all running tasks assigned to this AQL instance.

results(timeout: float | int | None = None, cancel_tasks_on_timeout: bool = True) list[Result | None][source]#

Get a list of results from tasks. Results are ordered in the same way the tasks were added. Blocks the thread until all tasks are finished.

Parameters:
  • timeout (float | int | None, optional) – The maximum amount to wait for execution to finish. If None, wait forever. If not None and time runs out, raises TimeoutError. Defaults to None.

  • cancel_tasks_on_timeout (bool) – Whether to cancel all other tasks when one task raises a TimeoutError.

Returns:

Task results.

Return type:

list[Result | None]

add_task(launcher: QLauncher | tuple[Problem, Algorithm, Backend], dependencies: list[AQLTask] | None = None, callbacks: list[Callable] | None = None, **kwargs) AQLTask[source]#

Add a QLauncher task to the execution queue.

Parameters:
  • launcher (QLauncher | tuple[Problem, Algorithm, Backend]) – Launcher instance that will be run.

  • dependencies (list[AQLTask] | None, optional) – Tasks that must finish first before this task. Defaults to None.

  • callbacks (list[Callable] | None, optional) – Functions to run when the task finishes. The task will be passed to the function as the only parameter. Defaults to None.

Returns:

Pointer to the submitted task.

Return type:

AQLTask

start()[source]#

Start tasks execution.