This notebook explains how the database works as an experiment container.
import os
import qcodes as qc
from qcodes.dataset.sqlite.database import initialise_or_create_database_at
db_file_path = os.path.join(os.getcwd(), 'exp_container_tutorial.db')
initialise_or_create_database_at(db_file_path)
Upgrading database; v0 -> v1: : 0it [00:00, ?it/s] Upgrading database; v1 -> v2: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 249.94it/s] Upgrading database; v2 -> v3: : 0it [00:00, ?it/s] Upgrading database; v3 -> v4: : 0it [00:00, ?it/s] Upgrading database; v4 -> v5: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 142.92it/s] Upgrading database; v5 -> v6: : 0it [00:00, ?it/s] Upgrading database; v6 -> v7: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 53.45it/s] Upgrading database; v7 -> v8: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 249.96it/s]
The database holds a certain number of experiments. They may be viewed:
from qcodes.dataset.experiment_container import experiments
experiments()
[]
Not surprisingly, our new database is empty. Let us add some experiments.
from qcodes.dataset.experiment_container import new_experiment, load_or_create_experiment
new_experiment('first_exp', sample_name='old_sample')
new_experiment('second_exp', sample_name='slightly_newer_sample')
# A more convenient function that can load an experiment
# OR create a new one if it does not exist:
load_or_create_experiment('second_exp', sample_name='brand_new_sample')
second_exp#brand_new_sample#3@C:\Users\a-halakh\Documents\Microsoft\QcodesHarshit\docs\examples\DataSet\exp_container_tutorial.db ---------------------------------------------------------------------------------------------------------------------------------
experiments()
[first_exp#old_sample#1@C:\Users\a-halakh\Documents\Microsoft\QcodesHarshit\docs\examples\DataSet\exp_container_tutorial.db --------------------------------------------------------------------------------------------------------------------------, second_exp#slightly_newer_sample#2@C:\Users\a-halakh\Documents\Microsoft\QcodesHarshit\docs\examples\DataSet\exp_container_tutorial.db --------------------------------------------------------------------------------------------------------------------------------------, second_exp#brand_new_sample#3@C:\Users\a-halakh\Documents\Microsoft\QcodesHarshit\docs\examples\DataSet\exp_container_tutorial.db ---------------------------------------------------------------------------------------------------------------------------------]
We notice that each experiment is labelled by an integer. This is the exp_id that can be used when looking up properties of each experiment.
Let us add some runs to experiment 2 ("second_exp"). For the sake of clarity, we don't add any data to the runs here. We refer to the Performing measurements using qcodes parameters and dataset notebook for detailed information on how to properly create and populate runs. We also refer to the DataSet-class-walkthrough notebook for more details on the DataSet
class. Note that the new_data_set
function is used here ONLY for the sake of exercise and should NOT be used in the actual experiment.
from qcodes.dataset.data_set import new_data_set
new_data_set('a_good_run', exp_id=2)
a_good_run #1@C:\Users\a-halakh\Documents\Microsoft\QcodesHarshit\docs\examples\DataSet\exp_container_tutorial.db -----------------------------------------------------------------------------------------------------------------
new_data_set('a_nother_run', exp_id=2)
a_nother_run #2@C:\Users\a-halakh\Documents\Microsoft\QcodesHarshit\docs\examples\DataSet\exp_container_tutorial.db -------------------------------------------------------------------------------------------------------------------
We may now inspect experiment 2.
from qcodes.dataset.experiment_container import load_experiment
exp_2 = load_experiment(2)
# Printing the experiment will reveal the runs
print(exp_2)
second_exp#slightly_newer_sample#2@C:\Users\a-halakh\Documents\Microsoft\QcodesHarshit\docs\examples\DataSet\exp_container_tutorial.db -------------------------------------------------------------------------------------------------------------------------------------- 1-a_good_run-1--0 2-a_nother_run-2--0
In a similar way, we may of course add runs to the other two experiments.
Now, the alert reader will have noticed that exp_id
is a keyword argument in new_data_set
. What is the default then? -- The default is that the run is added to the experiment with the highest exp_id
in the database.