{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Write data to cache\n", "\n", "This notebook is meant to be used together with [Read data from cache](./read_data_from_cache.ipynb) to demonstate the use of the datasets cache." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First we setup a simple experiment. This is copied from another notebook and can be ignored in this context." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Logging hadn't been started.\n", "Activating auto-logging. Current session state plus future input saved.\n", "Filename : C:\\Users\\Jens-Work\\.qcodes\\logs\\command_history.log\n", "Mode : append\n", "Output logging : True\n", "Raw input log : False\n", "Timestamping : True\n", "State : active\n", "Qcodes Logfile : C:\\Users\\Jens-Work\\.qcodes\\logs\\200924-21124-qcodes.log\n" ] } ], "source": [ "%matplotlib notebook\n", "import numpy.random as rd\n", "import matplotlib.pyplot as plt\n", "from functools import partial\n", "import numpy as np\n", "\n", "from time import sleep, monotonic\n", "\n", "import qcodes as qc\n", "from qcodes import Station, load_or_create_experiment, \\\n", " initialise_database, Measurement, load_by_run_spec, load_by_guid\n", "from qcodes.tests.instrument_mocks import DummyInstrument, DummyInstrumentWithMeasurement\n", "from qcodes.dataset.plotting import plot_dataset\n", "import time" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# preparatory mocking of physical setup\n", "\n", "dac = DummyInstrument('dac', gates=['ch1', 'ch2'])\n", "dmm = DummyInstrumentWithMeasurement('dmm', setter_instr=dac)\n", "\n", "station = qc.Station(dmm, dac)" ] }, { "cell_type": "code", "execution_count": 3, "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, 499.56it/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, 499.62it/s]\n", "Upgrading database; v5 -> v6: : 0it [00:00, ?it/s]\n", "Upgrading database; v6 -> v7: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 200.02it/s]\n", "Upgrading database; v7 -> v8: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 332.93it/s]\n", "Upgrading database; v8 -> v9: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 332.83it/s]\n" ] } ], "source": [ "initialise_database()\n", "exp = load_or_create_experiment(experiment_name='dataset_cache_test',\n", " sample_name=\"no sample\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we are ready to run an experiment. Once this experiment is running, take note of the id of the run (also accessible via ``dataset.captured_run_id``) created and open the [Read data from cache](./read_data_from_cache.ipynb) notebook and use there this id. After 20 sec this notebook will start writing actual data to the dataset." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Starting experimental run with id: 170. \n", "done sleeping\n" ] } ], "source": [ "\n", "\n", "# And then run an experiment\n", "\n", "meas = Measurement(exp=exp)\n", "meas.register_parameter(dac.ch1) # register the first independent parameter\n", "meas.register_parameter(dmm.v1, setpoints=(dac.ch1,)) # now register the dependent oone\n", "\n", "meas.write_period = 2\n", "\n", "\n", "with meas.run() as datasaver:\n", " time.sleep(20)\n", " # While sleeping here start loader. From load_cached_notebook.ipynb\n", " # this is done by loading this new run via ``captured_run_id`` printed when the measurement starts\n", " print(\"done sleeping\")\n", " for set_v in np.linspace(0, 25, 100):\n", " dac.ch1.set(set_v)\n", " get_v = dmm.v1.get()\n", " datasaver.add_result((dac.ch1, set_v),\n", " (dmm.v1, get_v))\n", " # flush so this always works\n", " datasaver.flush_data_to_database(block=True)\n", " time.sleep(0.1)\n", "\n", " \n", " dataset = datasaver.dataset # convenient to have for plotting\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.9" }, "nbsphinx": { "timeout": 60 }, "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": 2 }