This page was generated from docs/examples/legacy/The Snapshot.ipynb. Interactive online version: Binder badge.

The Snapshot

This notebook sheds some light on the snapshot of instruments.

NOTE: this notebook uses a depreated Loop construct for some of its examples. Please, instead, refer to Working with snapshots notebook from ``docs/examples/DataSet` <DataSet/Working%20with%20snapshots.ipynb>`__.

[1]:
from pprint import pprint
import json
import os

import qcodes as qc

from qcodes.tests.instrument_mocks import DummyInstrument
from qcodes.loops import Loop

# For this tutorial, we initialise our favourite pair of mock instruments,
# a DMM and a DAC

dmm = DummyInstrument('dmm', gates=['v1', 'v2'])
dac = DummyInstrument('dac', gates=['ch1', 'ch2'])

station = qc.Station(dmm, dac)

The main point of having a Station is that it snapshots the state of all added instruments. But what does that mean? Recall that an instrument is, loosely speaking, a collection of Parameters.

Parameter snapshot

[2]:
# Each parameter has a snapshot, containing information about its current value,
# when that value was set, what the allowed values are, etc.
pprint(dmm.v1.snapshot())
{'__class__': 'qcodes.parameters.parameter.Parameter',
 'full_name': 'dmm_v1',
 'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
 'instrument_name': 'dmm',
 'inter_delay': 0,
 'label': 'Gate v1',
 'name': 'v1',
 'post_delay': 0,
 'raw_value': 0,
 'ts': '2022-07-01 15:01:28',
 'unit': 'V',
 'vals': '<Numbers -800<=v<=400>',
 'value': 0}

Instrument snapshot

[3]:
# Each instrument has a snapshot that is basically the snapshots of all the parameters
pprint(dmm.snapshot())
{'__class__': 'qcodes.tests.instrument_mocks.DummyInstrument',
 'functions': {},
 'name': 'dmm',
 'parameters': {'IDN': {'__class__': 'qcodes.parameters.parameter.Parameter',
                        'full_name': 'dmm_IDN',
                        'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                        'instrument_name': 'dmm',
                        'inter_delay': 0,
                        'label': 'IDN',
                        'name': 'IDN',
                        'post_delay': 0,
                        'raw_value': {'firmware': 'NA',
                                      'model': '<class '
                                               "'qcodes.tests.instrument_mocks.DummyInstrument'>",
                                      'seral': 'NA',
                                      'vendor': 'QCoDeS'},
                        'ts': '2022-07-01 15:01:28',
                        'unit': '',
                        'vals': '<Anything>',
                        'value': {'firmware': 'NA',
                                  'model': '<class '
                                           "'qcodes.tests.instrument_mocks.DummyInstrument'>",
                                  'seral': 'NA',
                                  'vendor': 'QCoDeS'}},
                'v1': {'__class__': 'qcodes.parameters.parameter.Parameter',
                       'full_name': 'dmm_v1',
                       'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                       'instrument_name': 'dmm',
                       'inter_delay': 0,
                       'label': 'Gate v1',
                       'name': 'v1',
                       'post_delay': 0,
                       'raw_value': 0,
                       'ts': '2022-07-01 15:01:28',
                       'unit': 'V',
                       'vals': '<Numbers -800<=v<=400>',
                       'value': 0},
                'v2': {'__class__': 'qcodes.parameters.parameter.Parameter',
                       'full_name': 'dmm_v2',
                       'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                       'instrument_name': 'dmm',
                       'inter_delay': 0,
                       'label': 'Gate v2',
                       'name': 'v2',
                       'post_delay': 0,
                       'raw_value': 0,
                       'ts': '2022-07-01 15:01:28',
                       'unit': 'V',
                       'vals': '<Numbers -800<=v<=400>',
                       'value': 0}},
 'submodules': {}}

Sweep snapshot

[4]:
# When running QCoDeS loops, something is being swept. This is controlled with the `sweep` of a parameter.
# Sweeps also have snapshots
a_sweep = dac.ch1.sweep(0, 10, num=25)
pprint(a_sweep.snapshot())
{'parameter': {'__class__': 'qcodes.parameters.parameter.Parameter',
               'full_name': 'dac_ch1',
               'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
               'instrument_name': 'dac',
               'inter_delay': 0,
               'label': 'Gate ch1',
               'name': 'ch1',
               'post_delay': 0,
               'raw_value': 0,
               'ts': '2022-07-01 15:01:28',
               'unit': 'V',
               'vals': '<Numbers -800<=v<=400>',
               'value': 0},
 'values': [{'first': 0.0, 'last': 10.0, 'num': 25, 'type': 'linear'}]}

Loop/Measurement snapshot

[5]:
# All this is of course nice since a snapshot is saved every time a measurement is
# performed. Let's see this in action with a Loop.

# This is a qc.loop, sweeping a dac gate and reading a dmm voltage
lp = Loop(dac.ch1.sweep(0, 1, num=10), 0).each(dmm.v1)

# before the loop runs, the snapshot is quite modest; it contains the snapshots of
# the two involved parameters and the sweep
pprint(lp.snapshot())
{'__class__': 'qcodes.loops.ActiveLoop',
 'actions': [{'__class__': 'qcodes.parameters.parameter.Parameter',
              'full_name': 'dmm_v1',
              'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
              'instrument_name': 'dmm',
              'inter_delay': 0,
              'label': 'Gate v1',
              'name': 'v1',
              'post_delay': 0,
              'raw_value': 0,
              'ts': '2022-07-01 15:01:28',
              'unit': 'V',
              'vals': '<Numbers -800<=v<=400>',
              'value': 0}],
 'delay': 0,
 'sweep_values': {'parameter': {'__class__': 'qcodes.parameters.parameter.Parameter',
                                'full_name': 'dac_ch1',
                                'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                                'instrument_name': 'dac',
                                'inter_delay': 0,
                                'label': 'Gate ch1',
                                'name': 'ch1',
                                'post_delay': 0,
                                'raw_value': 0,
                                'ts': '2022-07-01 15:01:28',
                                'unit': 'V',
                                'vals': '<Numbers -800<=v<=400>',
                                'value': 0},
                  'values': [{'first': 0.0,
                              'last': 1.0,
                              'num': 10,
                              'type': 'linear'}]},
 'then_actions': []}
[6]:
# After the loop has run, the dataset contains more information, in particular the
# snapshots for ALL parameters off ALL instruments in the station
data = lp.run('data/dataset')
pprint(data.snapshot())

# This is the snapshot that get's saved to disk alongside your data.
# It's worthwhile familiarising yourself with it, so that you may retrieve
# valuable information down the line!
Started at 2022-07-01 15:01:28
DataSet:
   location = 'data/2022-07-01/#011_{name}_15-01-28'
   <Type>   | <array_id>  | <array.name> | <array.shape>
   Setpoint | dac_ch1_set | ch1          | (10,)
   Measured | dmm_v1      | v1           | (10,)
Finished at 2022-07-01 15:01:28
{'__class__': 'qcodes.data.data_set.DataSet',
 'arrays': {'dac_ch1_set': {'__class__': 'qcodes.data.data_array.DataArray',
                            'action_indices': (),
                            'array_id': 'dac_ch1_set',
                            'full_name': 'dac_ch1',
                            'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                            'instrument_name': 'dac',
                            'inter_delay': 0,
                            'is_setpoint': True,
                            'label': 'Gate ch1',
                            'name': 'ch1',
                            'post_delay': 0,
                            'raw_value': 0,
                            'shape': (10,),
                            'unit': 'V',
                            'vals': '<Numbers -800<=v<=400>'},
            'dmm_v1': {'__class__': 'qcodes.data.data_array.DataArray',
                       'action_indices': (0,),
                       'array_id': 'dmm_v1',
                       'full_name': 'dmm_v1',
                       'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                       'instrument_name': 'dmm',
                       'inter_delay': 0,
                       'is_setpoint': False,
                       'label': 'Gate v1',
                       'name': 'v1',
                       'post_delay': 0,
                       'raw_value': 0,
                       'shape': (10,),
                       'unit': 'V',
                       'vals': '<Numbers -800<=v<=400>'}},
 'formatter': 'qcodes.data.gnuplot_format.GNUPlotFormat',
 'io': '<DiskIO, '
       "base_location='/home/runner/work/Qcodes/Qcodes/docs/examples/legacy'>",
 'location': 'data/2022-07-01/#011_{name}_15-01-28',
 'loop': {'__class__': 'qcodes.loops.ActiveLoop',
          'actions': [{'__class__': 'qcodes.parameters.parameter.Parameter',
                       'full_name': 'dmm_v1',
                       'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                       'instrument_name': 'dmm',
                       'inter_delay': 0,
                       'label': 'Gate v1',
                       'name': 'v1',
                       'post_delay': 0,
                       'raw_value': 0,
                       'ts': '2022-07-01 15:01:28',
                       'unit': 'V',
                       'vals': '<Numbers -800<=v<=400>',
                       'value': 0}],
          'delay': 0,
          'sweep_values': {'parameter': {'__class__': 'qcodes.parameters.parameter.Parameter',
                                         'full_name': 'dac_ch1',
                                         'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                                         'instrument_name': 'dac',
                                         'inter_delay': 0,
                                         'label': 'Gate ch1',
                                         'name': 'ch1',
                                         'post_delay': 0,
                                         'raw_value': 0,
                                         'ts': '2022-07-01 15:01:28',
                                         'unit': 'V',
                                         'vals': '<Numbers -800<=v<=400>',
                                         'value': 0},
                           'values': [{'first': 0.0,
                                       'last': 1.0,
                                       'num': 10,
                                       'type': 'linear'}]},
          'then_actions': [],
          'ts_end': '2022-07-01 15:01:28',
          'ts_start': '2022-07-01 15:01:28',
          'use_threads': 'data/dataset'},
 'station': {'components': {},
             'config': None,
             'instruments': {'dac': {'__class__': 'qcodes.tests.instrument_mocks.DummyInstrument',
                                     'functions': {},
                                     'name': 'dac',
                                     'parameters': {'IDN': {'__class__': 'qcodes.parameters.parameter.Parameter',
                                                            'full_name': 'dac_IDN',
                                                            'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                                                            'instrument_name': 'dac',
                                                            'inter_delay': 0,
                                                            'label': 'IDN',
                                                            'name': 'IDN',
                                                            'post_delay': 0,
                                                            'raw_value': {'firmware': 'NA',
                                                                          'model': '<class '
                                                                                   "'qcodes.tests.instrument_mocks.DummyInstrument'>",
                                                                          'seral': 'NA',
                                                                          'vendor': 'QCoDeS'},
                                                            'ts': '2022-07-01 '
                                                                  '15:01:28',
                                                            'unit': '',
                                                            'vals': '<Anything>',
                                                            'value': {'firmware': 'NA',
                                                                      'model': '<class '
                                                                               "'qcodes.tests.instrument_mocks.DummyInstrument'>",
                                                                      'seral': 'NA',
                                                                      'vendor': 'QCoDeS'}},
                                                    'ch1': {'__class__': 'qcodes.parameters.parameter.Parameter',
                                                            'full_name': 'dac_ch1',
                                                            'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                                                            'instrument_name': 'dac',
                                                            'inter_delay': 0,
                                                            'label': 'Gate ch1',
                                                            'name': 'ch1',
                                                            'post_delay': 0,
                                                            'raw_value': 0,
                                                            'ts': '2022-07-01 '
                                                                  '15:01:28',
                                                            'unit': 'V',
                                                            'vals': '<Numbers '
                                                                    '-800<=v<=400>',
                                                            'value': 0},
                                                    'ch2': {'__class__': 'qcodes.parameters.parameter.Parameter',
                                                            'full_name': 'dac_ch2',
                                                            'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                                                            'instrument_name': 'dac',
                                                            'inter_delay': 0,
                                                            'label': 'Gate ch2',
                                                            'name': 'ch2',
                                                            'post_delay': 0,
                                                            'raw_value': 0,
                                                            'ts': '2022-07-01 '
                                                                  '15:01:28',
                                                            'unit': 'V',
                                                            'vals': '<Numbers '
                                                                    '-800<=v<=400>',
                                                            'value': 0}},
                                     'submodules': {}},
                             'dmm': {'__class__': 'qcodes.tests.instrument_mocks.DummyInstrument',
                                     'functions': {},
                                     'name': 'dmm',
                                     'parameters': {'IDN': {'__class__': 'qcodes.parameters.parameter.Parameter',
                                                            'full_name': 'dmm_IDN',
                                                            'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                                                            'instrument_name': 'dmm',
                                                            'inter_delay': 0,
                                                            'label': 'IDN',
                                                            'name': 'IDN',
                                                            'post_delay': 0,
                                                            'raw_value': {'firmware': 'NA',
                                                                          'model': '<class '
                                                                                   "'qcodes.tests.instrument_mocks.DummyInstrument'>",
                                                                          'seral': 'NA',
                                                                          'vendor': 'QCoDeS'},
                                                            'ts': '2022-07-01 '
                                                                  '15:01:28',
                                                            'unit': '',
                                                            'vals': '<Anything>',
                                                            'value': {'firmware': 'NA',
                                                                      'model': '<class '
                                                                               "'qcodes.tests.instrument_mocks.DummyInstrument'>",
                                                                      'seral': 'NA',
                                                                      'vendor': 'QCoDeS'}},
                                                    'v1': {'__class__': 'qcodes.parameters.parameter.Parameter',
                                                           'full_name': 'dmm_v1',
                                                           'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                                                           'instrument_name': 'dmm',
                                                           'inter_delay': 0,
                                                           'label': 'Gate v1',
                                                           'name': 'v1',
                                                           'post_delay': 0,
                                                           'raw_value': 0,
                                                           'ts': '2022-07-01 '
                                                                 '15:01:28',
                                                           'unit': 'V',
                                                           'vals': '<Numbers '
                                                                   '-800<=v<=400>',
                                                           'value': 0},
                                                    'v2': {'__class__': 'qcodes.parameters.parameter.Parameter',
                                                           'full_name': 'dmm_v2',
                                                           'instrument': 'qcodes.tests.instrument_mocks.DummyInstrument',
                                                           'instrument_name': 'dmm',
                                                           'inter_delay': 0,
                                                           'label': 'Gate v2',
                                                           'name': 'v2',
                                                           'post_delay': 0,
                                                           'raw_value': 0,
                                                           'ts': '2022-07-01 '
                                                                 '15:01:28',
                                                           'unit': 'V',
                                                           'vals': '<Numbers '
                                                                   '-800<=v<=400>',
                                                           'value': 0}},
                                     'submodules': {}}},
             'parameters': {}}}
[ ]: