{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# The Experiment Container\n", "\n", "This notebook explains how the database works as an experiment container." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "import qcodes as qc\n", "from qcodes.dataset.sqlite.database import initialise_or_create_database_at" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Upgrading database; v0 -> v1: : 0it [00:00, ?it/s]\n", "Upgrading database; v1 -> v2: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 249.94it/s]\n", "Upgrading database; v2 -> v3: : 0it [00:00, ?it/s]\n", "Upgrading database; v3 -> v4: : 0it [00:00, ?it/s]\n", "Upgrading database; v4 -> v5: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 142.92it/s]\n", "Upgrading database; v5 -> v6: : 0it [00:00, ?it/s]\n", "Upgrading database; v6 -> v7: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 53.45it/s]\n", "Upgrading database; v7 -> v8: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 249.96it/s]\n" ] } ], "source": [ "db_file_path = os.path.join(os.getcwd(), 'exp_container_tutorial.db')\n", "initialise_or_create_database_at(db_file_path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The experiments inside the database" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The database holds a certain number of **experiments**. They may be viewed:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "from qcodes.dataset.experiment_container import experiments" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "experiments()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Not surprisingly, our new database is empty. Let us add some experiments." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "from qcodes.dataset.experiment_container import new_experiment, load_or_create_experiment" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "second_exp#brand_new_sample#3@C:\\Users\\a-halakh\\Documents\\Microsoft\\QcodesHarshit\\docs\\examples\\DataSet\\exp_container_tutorial.db\n", "---------------------------------------------------------------------------------------------------------------------------------" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "new_experiment('first_exp', sample_name='old_sample')\n", "new_experiment('second_exp', sample_name='slightly_newer_sample')\n", "# A more convenient function that can load an experiment\n", "# OR create a new one if it does not exist:\n", "load_or_create_experiment('second_exp', sample_name='brand_new_sample')" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[first_exp#old_sample#1@C:\\Users\\a-halakh\\Documents\\Microsoft\\QcodesHarshit\\docs\\examples\\DataSet\\exp_container_tutorial.db\n", " --------------------------------------------------------------------------------------------------------------------------,\n", " second_exp#slightly_newer_sample#2@C:\\Users\\a-halakh\\Documents\\Microsoft\\QcodesHarshit\\docs\\examples\\DataSet\\exp_container_tutorial.db\n", " --------------------------------------------------------------------------------------------------------------------------------------,\n", " second_exp#brand_new_sample#3@C:\\Users\\a-halakh\\Documents\\Microsoft\\QcodesHarshit\\docs\\examples\\DataSet\\exp_container_tutorial.db\n", " ---------------------------------------------------------------------------------------------------------------------------------]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "experiments()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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.\n", "\n", "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](Performing-measurements-using-qcodes-parameters-and-dataset.ipynb) notebook for detailed information on how to properly create and populate runs. We also refer to the [DataSet-class-walkthrough](DataSet-class-walkthrough.ipynb) 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." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "from qcodes.dataset.data_set import new_data_set" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "a_good_run #1@C:\\Users\\a-halakh\\Documents\\Microsoft\\QcodesHarshit\\docs\\examples\\DataSet\\exp_container_tutorial.db\n", "-----------------------------------------------------------------------------------------------------------------" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "new_data_set('a_good_run', exp_id=2)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "a_nother_run #2@C:\\Users\\a-halakh\\Documents\\Microsoft\\QcodesHarshit\\docs\\examples\\DataSet\\exp_container_tutorial.db\n", "-------------------------------------------------------------------------------------------------------------------" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "new_data_set('a_nother_run', exp_id=2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We may now inspect experiment 2." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "from qcodes.dataset.experiment_container import load_experiment" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "exp_2 = load_experiment(2)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "second_exp#slightly_newer_sample#2@C:\\Users\\a-halakh\\Documents\\Microsoft\\QcodesHarshit\\docs\\examples\\DataSet\\exp_container_tutorial.db\n", "--------------------------------------------------------------------------------------------------------------------------------------\n", "1-a_good_run-1--0\n", "2-a_nother_run-2--0\n" ] } ], "source": [ "# Printing the experiment will reveal the runs\n", "print(exp_2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In a similar way, we may of course add runs to the other two experiments.\n", "\n", "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." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.5" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }