Skip to content

Further workflow customisation

This user guide shows further workflow customisation methods, including flags, subflows, and task retries.

For this user guide, we'll use the qruise-flow.yaml given in the foldable codeblock below. You can copy it from here and paste it into your own yaml file.

qruise-flow.yaml
name: demo-example-5-flags
qubits: [Q1, Q3]
couplings: []
stages:
  init:
    - name: schema
    - name: bootstrap-kb
      conditions:
        run_on_flags:
          - bootstrap
    - name: update-kb
  experiments:
    qubit:
      - name: t-measurement
        tasks:
          - name: ramsey
          - name: time-t1
            dependencies:
              - ramsey
          - name: readout-discriminator-train
            dependencies:
              - time-t1
            retry:
              limit: 0
      - name: ramsey-ef
        dependencies:
          - t-measurement
      - name: t2star-qpt-ramsey
        dependencies:
          - t-measurement
        conditions:
          skip_on_flags:
            - no-qpt
    coupling: []

04_customizing_workflows

This guide covers some of the same content from the 04_customizing_workflows example in JupyterLab. If you have access, 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 simply because a specific experiment isn't needed.

You can easily include or exclude specific tasks using flags (--flags). In the snippet below, you can see that we're using two flags: run_on_flags and skip_on_flags.

# ...
stages:
  init:
    - name: schema
    - name: bootstrap-kb
      conditions:
        run_on_flags:
          - bootstrap
    # ...
  experiments:
    qubit:
      # ...
      - name: t2star-qpt-ramsey
        dependencies:
          - t-measurement
        conditions:
          skip_on_flags:
            - no-qpt
    # ...

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

qruise flow run --flags bootstrap

If you simply run, qruise flow run (or use any other flags), the bootstrap-kb experiment won't be executed.

Contrastingly, t2star-qpt-ramsey has the condition skip_on_flags. To skip this experiment, you can use the command

qruise flow run --flags no-qpt

Without this flag, the t2star-qpt-ramsey experiment will be executed.

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 just need to give it a name and then define the experiments as tasks the way you would with any other workflow.

# ...
experiments:
  qubit:
    - name: t-measurement
      tasks:
        - name: ramsey
        - name: time-t1
          dependencies:
            - ramsey
        - name: readout-discriminator-train
          dependencies:
            - time-t1
          # ...
    - name: t2star-qpt-ramsey
      dependencies:
        - t-measurement
    # ...

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.

03_adding_new_task_to_workflow folder

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 ramsey-ef 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: ramsey-ef
  dependencies:
    - t-measurement
  retry:
    limit: 4
  # ...

Note

In the qruise-flow.yaml given at the start of this guide, the number of retries is set to 0. You'll need to change this.