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]:
import json
import os
from pprint import pprint

import qcodes as qc
from qcodes.station import Station
from qcodes.instrument_drivers.mock_instruments import DummyInstrument

from qcodes_loop.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 = Station(dmm, dac)
Logging hadn't been started.
Activating auto-logging. Current session state plus future input saved.
Filename       : C:\Users\a-halakh\.qcodes\logs\command_history.log
Mode           : append
Output logging : True
Raw input log  : False
Timestamping   : True
State          : active
Qcodes Logfile : C:\Users\a-halakh\.qcodes\logs\200324-30512-qcodes.log
False

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.instrument.parameter.Parameter',
 'full_name': 'dmm_v1',
 'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
 'instrument_name': 'dmm',
 'inter_delay': 0,
 'label': 'Gate v1',
 'name': 'v1',
 'post_delay': 0,
 'raw_value': 0,
 'ts': '2020-03-24 18:47:43',
 '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.instrument_drivers.mock_instruments.DummyInstrument',
 'functions': {},
 'name': 'dmm',
 'parameters': {'IDN': {'__class__': 'qcodes.instrument.parameter.Parameter',
                        'full_name': 'dmm_IDN',
                        'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                        'instrument_name': 'dmm',
                        'inter_delay': 0,
                        'label': 'IDN',
                        'name': 'IDN',
                        'post_delay': 0,
                        'raw_value': {'firmware': None,
                                      'model': 'dmm',
                                      'serial': None,
                                      'vendor': None},
                        'ts': '2020-03-24 18:47:43',
                        'unit': '',
                        'vals': '<Anything>',
                        'value': {'firmware': None,
                                  'model': 'dmm',
                                  'serial': None,
                                  'vendor': None}},
                'v1': {'__class__': 'qcodes.instrument.parameter.Parameter',
                       'full_name': 'dmm_v1',
                       'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                       'instrument_name': 'dmm',
                       'inter_delay': 0,
                       'label': 'Gate v1',
                       'name': 'v1',
                       'post_delay': 0,
                       'raw_value': 0,
                       'ts': '2020-03-24 18:47:43',
                       'unit': 'V',
                       'vals': '<Numbers -800<=v<=400>',
                       'value': 0},
                'v2': {'__class__': 'qcodes.instrument.parameter.Parameter',
                       'full_name': 'dmm_v2',
                       'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                       'instrument_name': 'dmm',
                       'inter_delay': 0,
                       'label': 'Gate v2',
                       'name': 'v2',
                       'post_delay': 0,
                       'raw_value': 0,
                       'ts': '2020-03-24 18:47:43',
                       '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.instrument.parameter.Parameter',
               'full_name': 'dac_ch1',
               'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
               'instrument_name': 'dac',
               'inter_delay': 0,
               'label': 'Gate ch1',
               'name': 'ch1',
               'post_delay': 0,
               'raw_value': 0,
               'ts': '2020-03-24 18:47:43',
               '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 qcodes_loop.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.instrument.parameter.Parameter',
              'full_name': 'dmm_v1',
              'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
              'instrument_name': 'dmm',
              'inter_delay': 0,
              'label': 'Gate v1',
              'name': 'v1',
              'post_delay': 0,
              'raw_value': 0,
              'ts': '2020-03-24 18:47:43',
              'unit': 'V',
              'vals': '<Numbers -800<=v<=400>',
              'value': 0}],
 'delay': 0,
 'sweep_values': {'parameter': {'__class__': 'qcodes.instrument.parameter.Parameter',
                                'full_name': 'dac_ch1',
                                'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                                'instrument_name': 'dac',
                                'inter_delay': 0,
                                'label': 'Gate ch1',
                                'name': 'ch1',
                                'post_delay': 0,
                                'raw_value': 0,
                                'ts': '2020-03-24 18:47:43',
                                '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 2020-03-24 18:47:43
DataSet:
   location = 'data/2020-03-24/#014_{name}_18-47-43'
   <Type>   | <array_id>  | <array.name> | <array.shape>
   Setpoint | dac_ch1_set | ch1          | (10,)
   Measured | dmm_v1      | v1           | (10,)
Finished at 2020-03-24 18:47:43
{'__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.instrument_drivers.mock_instruments.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.instrument_drivers.mock_instruments.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='C:\\\\Users\\\\a-halakh\\\\Documents\\\\Microsoft\\\\Qcodes\\\\docs\\\\examples\\\\legacy'>",
 'location': 'data/2020-03-24/#014_{name}_18-47-43',
 'loop': {'__class__': 'qcodes.loops.ActiveLoop',
          'actions': [{'__class__': 'qcodes.instrument.parameter.Parameter',
                       'full_name': 'dmm_v1',
                       'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                       'instrument_name': 'dmm',
                       'inter_delay': 0,
                       'label': 'Gate v1',
                       'name': 'v1',
                       'post_delay': 0,
                       'raw_value': 0,
                       'ts': '2020-03-24 18:47:43',
                       'unit': 'V',
                       'vals': '<Numbers -800<=v<=400>',
                       'value': 0}],
          'delay': 0,
          'sweep_values': {'parameter': {'__class__': 'qcodes.instrument.parameter.Parameter',
                                         'full_name': 'dac_ch1',
                                         'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                                         'instrument_name': 'dac',
                                         'inter_delay': 0,
                                         'label': 'Gate ch1',
                                         'name': 'ch1',
                                         'post_delay': 0,
                                         'raw_value': 0,
                                         'ts': '2020-03-24 18:47:43',
                                         'unit': 'V',
                                         'vals': '<Numbers -800<=v<=400>',
                                         'value': 0},
                           'values': [{'first': 0.0,
                                       'last': 1.0,
                                       'num': 10,
                                       'type': 'linear'}]},
          'then_actions': [],
          'ts_end': '2020-03-24 18:47:43',
          'ts_start': '2020-03-24 18:47:43',
          'use_threads': 'data/dataset'},
 'station': {'components': {},
             'config': None,
             'default_measurement': [],
             'instruments': {'dac': {'__class__': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                                     'functions': {},
                                     'name': 'dac',
                                     'parameters': {'IDN': {'__class__': 'qcodes.instrument.parameter.Parameter',
                                                            'full_name': 'dac_IDN',
                                                            'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                                                            'instrument_name': 'dac',
                                                            'inter_delay': 0,
                                                            'label': 'IDN',
                                                            'name': 'IDN',
                                                            'post_delay': 0,
                                                            'raw_value': {'firmware': None,
                                                                          'model': 'dac',
                                                                          'serial': None,
                                                                          'vendor': None},
                                                            'ts': '2020-03-24 '
                                                                  '18:47:43',
                                                            'unit': '',
                                                            'vals': '<Anything>',
                                                            'value': {'firmware': None,
                                                                      'model': 'dac',
                                                                      'serial': None,
                                                                      'vendor': None}},
                                                    'ch1': {'__class__': 'qcodes.instrument.parameter.Parameter',
                                                            'full_name': 'dac_ch1',
                                                            'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                                                            'instrument_name': 'dac',
                                                            'inter_delay': 0,
                                                            'label': 'Gate ch1',
                                                            'name': 'ch1',
                                                            'post_delay': 0,
                                                            'raw_value': 0,
                                                            'ts': '2020-03-24 '
                                                                  '18:47:43',
                                                            'unit': 'V',
                                                            'vals': '<Numbers '
                                                                    '-800<=v<=400>',
                                                            'value': 0},
                                                    'ch2': {'__class__': 'qcodes.instrument.parameter.Parameter',
                                                            'full_name': 'dac_ch2',
                                                            'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                                                            'instrument_name': 'dac',
                                                            'inter_delay': 0,
                                                            'label': 'Gate ch2',
                                                            'name': 'ch2',
                                                            'post_delay': 0,
                                                            'raw_value': 0,
                                                            'ts': '2020-03-24 '
                                                                  '18:47:43',
                                                            'unit': 'V',
                                                            'vals': '<Numbers '
                                                                    '-800<=v<=400>',
                                                            'value': 0}},
                                     'submodules': {}},
                             'dmm': {'__class__': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                                     'functions': {},
                                     'name': 'dmm',
                                     'parameters': {'IDN': {'__class__': 'qcodes.instrument.parameter.Parameter',
                                                            'full_name': 'dmm_IDN',
                                                            'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                                                            'instrument_name': 'dmm',
                                                            'inter_delay': 0,
                                                            'label': 'IDN',
                                                            'name': 'IDN',
                                                            'post_delay': 0,
                                                            'raw_value': {'firmware': None,
                                                                          'model': 'dmm',
                                                                          'serial': None,
                                                                          'vendor': None},
                                                            'ts': '2020-03-24 '
                                                                  '18:47:43',
                                                            'unit': '',
                                                            'vals': '<Anything>',
                                                            'value': {'firmware': None,
                                                                      'model': 'dmm',
                                                                      'serial': None,
                                                                      'vendor': None}},
                                                    'v1': {'__class__': 'qcodes.instrument.parameter.Parameter',
                                                           'full_name': 'dmm_v1',
                                                           'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                                                           'instrument_name': 'dmm',
                                                           'inter_delay': 0,
                                                           'label': 'Gate v1',
                                                           'name': 'v1',
                                                           'post_delay': 0,
                                                           'raw_value': 0,
                                                           'ts': '2020-03-24 '
                                                                 '18:47:43',
                                                           'unit': 'V',
                                                           'vals': '<Numbers '
                                                                   '-800<=v<=400>',
                                                           'value': 0},
                                                    'v2': {'__class__': 'qcodes.instrument.parameter.Parameter',
                                                           'full_name': 'dmm_v2',
                                                           'instrument': 'qcodes.instrument_drivers.mock_instruments.DummyInstrument',
                                                           'instrument_name': 'dmm',
                                                           'inter_delay': 0,
                                                           'label': 'Gate v2',
                                                           'name': 'v2',
                                                           'post_delay': 0,
                                                           'raw_value': 0,
                                                           'ts': '2020-03-24 '
                                                                 '18:47:43',
                                                           'unit': 'V',
                                                           'vals': '<Numbers '
                                                                   '-800<=v<=400>',
                                                           'value': 0}},
                                     'submodules': {}}},
             'parameters': {}}}
[ ]: