qruise flow init
Initialise directory structure for a Qruise flow.
Syntax¶
Description¶
The qruise flow init
command initialises a directory with the basic scaffolding for a Qruise flow. The following files will be created:
.QKB.json
- basic configuration of the knowledge base01-schema.ipynb
- Jupyter notebook for schema migration during flow execution02-bootstrap-kb.ipynb
- Jupyter notebook for bootstrapping the data in the knowledge basebootstrap.yaml
- used by02-bootstrap-kb.ipynb
to bootstrap the knowledge baseconfig.py
- basic Python configuration fileqruise-flow.yaml
- basic flow fileschema.py
- empty schema file to be used by the flowutils.py
- a collection of utility functions to be used in the flow notebooks
Manual steps after running qruise flow init
After running the qruise flow init
the flow is not ready to be run immediately. See the text below for details.
The exact contents of the above-mentioned files depends on the command-line parameters used (see also the Examples section). At the very least, you must provide the contents of the bootstrap.yaml
and schema.py
files. Furthermore, if the --profile
flag was not used, you have to manually edit the .QKB.json
and config.py
files and put it there.
Autogenerated flags
The flow defined by the autogenerated qruise-flow.yaml
file will only excute the 02-bootstrap-kb.ipynb
notebook if the bootstrap
flag is provided. Read more about running flows with flags here.
Options¶
Option |
Description |
---|---|
|
Name of the flow to use. Default: |
|
Path of the directory to initialise. If no path is specified, the current working directory will be used. |
|
Specify qubits present on the QPU. Must have the list format. |
|
Specify couplings between the qubits on the QPU. Must have the pair list format. |
|
Overwrite files in the target directory. |
|
Specify default profile for the flow. |
|
Show a help message and exit. |
Examples¶
Basic usage¶
To create a basic directory structure for running QruiseOS flows, start by creating an empty directory and switching to it:
Then simply call qruise flow init
without any parameters:
The autogenerated qruise-flow.yaml
file should have the following content:
name: Qruise flow (autogenerated)
qubits:
- Q1
- Q2
- Q3
couplings:
- - Q1
- Q2
- - Q2
- Q3
stages:
init:
- name: schema
- dependencies:
- schema
name: bootstrap-kb
conditions:
run_on_flags:
- bootstrap
experiments:
qubit: []
coupling: []
final: []
Before running the flow, however, you have to perform the following steps:
- Change the flow name and specify qubits and couplings
Open theqruise-flow.yaml
file and editname
,qubits
, andcouplings
fields to match the layout of your QPU. - Provide the profile name in the
.QKB.json
file
Open the.QKB.json
file in a text editor of choice and find the line containing"profile": null
. Replace thenull
with the profile name in double quotation marks. - Provide the profile name in the
config.py
file
Open theconfig.py
file in a text editor of choice and find the line containgPROFILE = "<PROFILE>"
. Replace<PROFILE>
with the profile name. - Provide a valid schema for the flow
Edit theschema.py
and provide a correct schema. - Provide valid bootstrap data
Edit thebootstrap.yaml
file and provide correct bootstrap data.
After completing the above steps, your flow should be ready to run. You can verify it by running the following:
The above command should start a flow in the bootstrap mode, and a long log should be printed to the output. If no errors are present in the log, it means your setup is complete and you can now start developing your flow and experiments!
Specifying qubits, couplings, and profile¶
The process of generating the flow file can be simplfied by providing appropriate options to the CLI. For instance, assume that you have a 5-qubit QPU with linear topology, as shown in the diagram below:
Linear topology QPU with 5 qubits and 4 couplers.
Furthermore, assume that you want to use a profile called linear-5-qubits
and name the resulting flow Daily flow
. You can achieve this in a single CLI call in the following way:
qruise flow init --name "Daily flow" --profile linear-5-qubits --qubits Q1,Q2,Q3,Q4,Q5 --couplings Q1-Q2,Q2-Q3,Q3-Q4,Q4-Q5
Passing lists in Qruise CLI
Note the syntax for the list of qubits and couplings. You can read more about it here
The resulting flow file will now have the following structure:
name: Daily flow
qubits:
- Q1
- Q2
- Q3
- Q4
- Q5
couplings:
- - Q1
- Q2
- - Q2
- Q3
- - Q3
- Q4
- - Q4
- Q5
stages:
init:
- name: schema
- dependencies:
- schema
name: bootstrap-kb
conditions:
run_on_flags:
- bootstrap
experiments:
qubit: []
coupling: []
final: []
As you can see, we're ready to add experiments without any further modifications. Similarly, both .QKB.json
and config.py
files are correctly initialised with the profile name.
This method of creating flows is especially useful for automation purposes or when working with bigger QPUs, for which managing all qubits and couplings manually is too cumbersome.
Overwriting directory content¶
By default, running qruise flow init
in a non-empty directory will fail:
$ mkdir -p $HOME/flows/my-flow
$ cd $HOME/flows/my-flow
$ touch empty-file.txt
$ qruise flow init
Failed to initialise flow: target directory is not empty, and no force-overwrite flag was specified.
This behaviour is meant to prevent accidental overwriting and loss of sensitive flow files. However, it can be changed by specifying a --force
flag:
With great power comes great responsibility...
If you do not use any other forms of protection, e.g. version control or regular backups, using the --force
flag can lead to an irreversible loss of data. Use with care.