task
Specifies a task to be run within a flow. The contents of the task are specified in a Jupyter notebook.
Schema¶
name: str
conditions: executionConditions | None
retry: retryStrategy | None
batch_group: str | None
Properties¶
Property | Type | Description | References |
---|---|---|---|
name |
str |
Name of the notebook defining the task. | |
conditions |
executionConditions | None |
Conditions for execution of the task. | executionConditions |
retry |
retryStrategy | None |
Task failure retry strategy. | retryStrategy |
batch_group |
str | None |
Name of the batch group that the task should use. | |
dependencies |
List[str] | None |
List of task dependencies. |
Remarks¶
The batch_group
property must be either empty or reference one of the batch groups defined by the flow via the flow.batch_groups
property. If it is not specified, the task will be:
- run for each qubit separately if it is specified in the
flow.stages.experiments.qubits
, - run once if it is specified elsewhere.
The batch groups that a task references must be defined in the flow.batch_groups
property.
Examples¶
Simple task definition¶
At its bare minimumum, a task can be defined by just the name. For instance, if you have an experiment defined in a notebook my-experiment.ipynb
, you can create a task running this notebook by just specifying its name:
Conditional task execution¶
Some tasks do not have to be run in every flow. Instead, a task can be included or skipped based on the conditions
property. Continuing with the previous example, you might want to run my-experiment
only when a flag weekly-calibration
is specified:
Timeout and retry¶
Under normal circumstances, a failure of a task within a flow results in a failure of the flow and its immediate termination. However, due to the quantum nature of the experiments run within a flow, you may want to retry a task a certain number of times before aborting the flow. For instance, you might say that a task is considered successful if it can be finished in at most 3 attempts (i.e. 2 retries). In this case, you can simply use specify the retryStrategy
for the task as:
In this case, a task must fail three times in a row in order to stop the flow.
Similarly, you might expect a task to be finished within reasonable time - if it takes too long, it might mean that there is a problem with your code or that a hardware problem has occurred. A long-running task can block access to the QPU. Hence you can specify a timeout for a task, such that when it is reached, a task is terminated and considered failed. For instance, the task definition below specifies a 30 second timeout using the retry.timeout
property:
Parallel execution using batch groups¶
If you are running a task in the experiments.qubits
stage, you can specify batch groups for it. For instance, if you have a batch group called parallel-qubits
defined in the flow, you can apply it to the task by using the batch_group
property: