Further workflow customisation
This user guide shows further workflow customisation methods, including flags, subflows, and task retries.
04_customising_workflows
This guide covers some of the same content from the 04_customising_workflows
examples in JupyterLab. If you have access to Jupyter, it might be a better idea to follow the examples there, as this will give you hands on experience navigating the different files required to run a workflow.
Flags¶
Sometimes you might want to run a workflow without executing every task. This could be to speed up repeated runs, for debugging, or because a specific experiment isn't needed.
You can easily include or exclude specific tasks using flags (--flags
). In the flow definition shown below, you can see that we're using two flags: run_on_flags
and skip_on_flags
.
name: onboarding-04-example-4-flags
qubits: [Q1, Q3]
couplings: []
stages:
init:
- name: schema
- name: bootstrap-kb
conditions:
run_on_flags:
- bootstrap
experiments:
qubit:
- name: ramsey
- name: time-t1
dependencies:
- ramsey
- name: readout-discriminator-train
dependencies:
- time-t1
- name: ramsey-ef
dependencies:
- readout-discriminator-train
conditions:
skip_on_flags:
- no-ramsey-ef
- name: t2star-qpt-ramsey
dependencies:
- ramsey-ef
coupling: []
As you might expect, the condition run_on_flags
means the bootstrap-kb
experiment will only run when the bootstrap
flag is passed, i.e. when you run the command
If you simply run, qruise flow run
(or use any other flags), the bootstrap-kb
experiment won't be executed.
Contrastingly, ramsey-ef
has the condition skip_on_flags
. To skip this experiment, you can use the command
Without this flag, the ramsey-ef
experiment will be executed.
Note
If an experiment task is dependent on a task that's skipped using a flag, it will inherit the dependency of the skipped task. For example, in this workflow, if ramsey-ef
is skipped using the flag no-ramsey-ef
, t2star-qpt-ramsey
will inherit the dependency readout-discriminator-train
.
Subflows¶
Subflows allow you to group experiments together. In fact, we've already been using subflows in the previous workflow user guides. If you look back at our earlier workflows, you'll see they're split into subflows such as init
and experiment
. This separates the initialisation tasks from the experiment tasks.
You can also define additional subflows to further organise your workflow. For example, grouping related experiments together, as shown in the code snippet below. This might be useful if you want to execute only a few experiments; for example, repeating a sequence until a certain condition is met, such as finding a suitable set of parameters or reaching a target fidelity.
The last experiment in the subflow can be used to check the condition and decide if the subflow should be repeated in case of a failure.
In the code snippet below, the subflow t-measurement
is highlighted in blue. To define the subflow, you need to give it a name
and then define the experiments as tasks
the way you would with any other workflow.
name: onboarding-04-example-5-subflows
qubits: [Q1, Q3]
couplings: []
stages:
init:
- name: schema
- name: bootstrap-kb
experiments:
qubit:
- name: t-measurement
tasks:
- name: ramsey
- name: time-t1
dependencies:
- ramsey
- name: readout-discriminator-train
dependencies:
- time-t1
- name: ramsey-ef
dependencies:
- t-measurement
- name: t2star-qpt-ramsey
dependencies:
- t-measurement
coupling: []
In the screen capture below, you can see that this workflow contains two subflows: init
and experiment
. Nested within the experiment
subflow is the t-measurement
subflow, which groups the ramsey
, time-t1
, and readout-discriminator-train
experiment tasks.
Retry¶
Some tasks in your workflow might have a tendency to fail due to noise or other instabilities. In this case, you might want to retry the same task multiple times for a higher chance of success.
You can see in the screen capture above that the readout-discriminator-train
task failed on both qubits. We can define a limited number of retries for this task, as shown in the code snippet below. If it succeeds within 4 retries, the workflow will proceed to the next task. If it still fails, the task will be marked as failed, and the subsequent tasks for that qubit will not be executed.
name: onboarding-04-example-6-retry
qubits: [Q1, Q3]
couplings: []
stages:
init:
- name: schema
- name: bootstrap-kb
experiments:
qubit:
- name: ramsey
- name: time-t1
dependencies:
- ramsey
- name: readout-discriminator-train
dependencies:
- time-t1
retry:
limit: 4
- name: ramsey-ef
dependencies:
- readout-discriminator-train
- name: t2star-qpt-ramsey
dependencies:
- ramsey-ef
coupling: []