This page was generated from docs/examples/DataSet/Measuring X as a function of time.ipynb. Interactive online version: Binder badge.

Measuring X as a function of time

Sometimes we’d like to measure something as a function of elapsed wall clock time. QCoDeS provides a convenient default way of doing such a measurement, namely by using the ElapsedTimeParameter.

The main utility of having a default way of measuring time is the uniformity in data of different experiments.

import os

import numpy as np

from qcodes.instrument.specialized_parameters import ElapsedTimeParameter
from qcodes.instrument.parameter import Parameter
from qcodes.dataset import initialise_or_create_database_at
from qcodes.dataset.measurements import Measurement
from qcodes.dataset.experiment_container import load_or_create_experiment
from qcodes.dataset.plotting import plot_dataset

Prepatory footwork: setup database and experiment

initialise_or_create_database_at(os.path.join(os.getcwd(), 'x_as_a_function_of_time.db'))
load_or_create_experiment('tutorial', 'no_sample')
Upgrading database; v0 -> v1: : 0it [00:00, ?it/s]
Upgrading database; v1 -> v2: 100%|██████████| 1/1 [00:00<00:00, 491.77it/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, 579.64it/s]
Upgrading database; v5 -> v6: : 0it [00:00, ?it/s]
Upgrading database; v6 -> v7: 100%|██████████| 1/1 [00:00<00:00, 331.67it/s]
Upgrading database; v7 -> v8: 100%|██████████| 1/1 [00:00<00:00, 932.69it/s]
Upgrading database; v8 -> v9: 100%|██████████| 1/1 [00:00<00:00, 603.67it/s]

The measurement itself

We’ll measure some Brownian motion. We set up a parameter for the noise.

noise = Parameter('noise',
                  get_cmd=lambda: np.random.randn())
time = ElapsedTimeParameter('time')
meas = Measurement()
meas.register_parameter(noise, setpoints=[time])
<qcodes.dataset.measurements.Measurement at 0x7fad70e675e0>
with as datasaver:
    pos = 0
    for _ in range(100):
        pos += noise()
        now = time()
        datasaver.add_result((noise, pos), (time, now))

dataset = datasaver.dataset
Starting experimental run with id: 1.
axs, cbs = plot_dataset(dataset)
[ ]: