Updating the knowledge base
To update the state of the knowledge base - either the schema or the data itself - you need to perform a commit. The correct way to do it depends on the use case, as described below.
Committing schema changes¶
As described in the Creating a schema user guide, the schema can be extended over time as you incorporate more experiments or hardware elements into your setup. However, the changes that you introduce to the schema.py
file have to be communicated to the knowledge base. The easiest way to achieve that is with the qruise kb commit
CLI command:
Note
Your commit message should describe the action you performed in the commit, so other users can easily see what you changed and why.
Using the CLI for updating the knowledge base schema is especially useful during initial development or when experimenting with a new setup. However, if you want to update the schema from within a Jupyter notebook, it's better to do it using pure Python code:
from qruise.kb import Schema, connect
from qruise.kb.configuration import get_global_configuration_manager
client = connect(configuration_manager=get_global_configuration_manager())
schema = Schema()
# read old schema
old_value = client.get_schema()
# prepare the schema migration
migration = schema.prepare_migration(old_value, "schema", replace=False)
# migrate the schema if any changes were detected
if migration.is_pending():
# Change the commit_msg paramter to change the commit message
migration.commit(client, commit_msg="Update schema")
If you have access to QruiseOS JupyterLab examples, you can see this approach in action in the Running multiple-qubit workflows example, in the ~/qruise/examples/04_customising_workflows/example_2_coupling/01-schema.ipynb
notebook, used to update the schema in the initial part of a workflow run.
Committing data changes¶
Besides the schema, the data changes as well. In fact, in the vast majority of cases, it changes much more often. Indeed, every time you run an experiment or a workflow, you probably want to update the values stored in the KB. This can be done with some Python code.
For instance, if you want to change the frequency of the Q1
qubit to 4.20 GHz, you can do so with the following:
from qruise.experiment.utils.kb_utils import create_kb_session
session = create_kb_session()
# load documents of type Qubit
session.load_documents(session.Qubit)
# select the Q1 qubit and change its frequency
q1 = session.Qubit["Q1"]
q1.freq.value = 4.20e9
# save the changes to the knowledge base
session.save("Update Q1 frequency")
Most of the data manipulation you'll do, however, comes from running experiments on QPUs – either manually or as part of a workflow. The knowledge base allows you to correlate the data with the experiment it came from. For instance, if you run the amplitude Rabi experiment to calibrate the amplitude of a \(\pi\)-pulse, you can update the calibrated value together with the information about where it came from, as shown in the excerpt below:
As you can see, in line 3 we create an ExperimentContext
object, which correlates the data with the experiment it came from. In this way, you can keep track of how and when the new value was obtained.
Note that the session
and analysis
variables are undefined in the above code block – you must create them beforehand. Take a look at the Running a single task tutorial to learn more about how to do it.