This page was generated from docs/examples/DataSet/Cache/write_for_caching.ipynb. Interactive online version: Binder badge.

Write data to cache

This notebook is meant to be used together with Read data from cache to demonstate the use of the datasets cache.

First we setup a simple experiment. This is copied from another notebook and can be ignored in this context.

%matplotlib notebook
import time

import numpy as np

import qcodes as qc
from qcodes.dataset import Measurement, initialise_database, load_or_create_experiment
from qcodes.instrument_drivers.mock_instruments import (
Logging hadn't been started.
Activating auto-logging. Current session state plus future input saved.
Filename       : /home/runner/.qcodes/logs/command_history.log
Mode           : append
Output logging : True
Raw input log  : False
Timestamping   : True
State          : active
Qcodes Logfile : /home/runner/.qcodes/logs/240527-20387-qcodes.log
# preparatory mocking of physical setup

dac = DummyInstrument('dac', gates=['ch1', 'ch2'])
dmm = DummyInstrumentWithMeasurement('dmm', setter_instr=dac)

station = qc.Station(dmm, dac)
exp = load_or_create_experiment(experiment_name='dataset_cache_test',
                          sample_name="no sample")

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 notebook and use there this id. After 20 sec this notebook will start writing actual data to the dataset.

# And then run an experiment

meas = Measurement(exp=exp)
meas.register_parameter(dac.ch1)  # register the first independent parameter
meas.register_parameter(dmm.v1, setpoints=(dac.ch1,))  # now register the dependent oone

meas.write_period = 2

with as datasaver:
    # While sleeping here start loader. From load_cached_notebook.ipynb
    # this is done by loading this new run via ``captured_run_id`` printed when the measurement starts
    print("done sleeping")
    for set_v in np.linspace(0, 25, 100):
        get_v = dmm.v1.get()
        datasaver.add_result((dac.ch1, set_v),
                             (dmm.v1, get_v))
        # flush so this always works

    dataset = datasaver.dataset  # convenient to have for plotting
Starting experimental run with id: 1.
done sleeping
[ ]: