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

The Location Formatter

The Location Formatter controls the format of the location to which data are saved.

This notebook shows some examples of setting different location formats.

[1]:
%matplotlib nbagg
import matplotlib.pyplot as plt
import time
import numpy as np

import qcodes as qc
from qcodes.loops import Loop
from qcodes.data.location import FormatLocation
[2]:
# First we set up some mock experiment
from qcodes.tests.instrument_mocks import DummyInstrument

gates = DummyInstrument('some_gates', gates=['plunger', 'left', 'topo'])
meter = DummyInstrument('meter', gates=['voltage', 'current'])

station = qc.Station(gates, meter)

The formatter in action

Now let’s run some loops to get datasets and see where they end up.

When writing the location format, some fields are automatically filled out.

That is the fields ‘{date}’, ‘{time}’, and ‘{counter}’. All other fields must have their values provided via the record dict.

[3]:
loc_fmt='{date}/#{counter}_{name}_{date}_{time}'  # set the desired location format
rcd={'name': 'unicorn'}  # provide a value for 'name'
loc_provider = FormatLocation(fmt=loc_fmt, record=rcd)  # create a location provider using that format

loop = Loop(gates.plunger.sweep(0, 1, num=25), 0).each(meter.voltage)
data2 = loop.run(location=loc_provider)
Started at 2022-07-04 11:39:29
DataSet:
   location = '2022-07-04/#001_unicorn_2022-07-04_11-39-29'
   <Type>   | <array_id>             | <array.name> | <array.shape>
   Setpoint | some_gates_plunger_set | plunger      | (25,)
   Measured | meter_voltage          | voltage      | (25,)
Finished at 2022-07-04 11:39:29
[4]:
# Now let's do that a few times with different formats

import numpy as np

loc_fmt='my_custom_folder/#{counter}_randomnumber_{name}_{date}_{time}'
rcd = {'name': str(np.random.randint(1, 100))}
loc_provider = FormatLocation(fmt=loc_fmt, record=rcd)

loop = Loop(gates.plunger.sweep(0, 1, num=25), 0).each(meter.voltage)
data2 = loop.run(location=loc_provider)
Started at 2022-07-04 11:39:29
DataSet:
   location = 'my_custom_folder/#001_randomnumber_98_2022-07-04_11-39-29'
   <Type>   | <array_id>             | <array.name> | <array.shape>
   Setpoint | some_gates_plunger_set | plunger      | (25,)
   Measured | meter_voltage          | voltage      | (25,)
Finished at 2022-07-04 11:39:29
[5]:
# You can also overwrite the custom fields

loc_fmt='{date}/#{counter}_{name}_{date}_{time}'
rcd = {'time': 'hammer_time'}
loc_provider = FormatLocation(fmt=loc_fmt, record=rcd)

loop = Loop(gates.plunger.sweep(0, 1, num=25), 0).each(meter.voltage)
data2 = loop.run(location=loc_provider)
Started at 2022-07-04 11:39:29
DataSet:
   location = '2022-07-04/#002_{name}_2022-07-04_hammer_time'
   <Type>   | <array_id>             | <array.name> | <array.shape>
   Setpoint | some_gates_plunger_set | plunger      | (25,)
   Measured | meter_voltage          | voltage      | (25,)
Finished at 2022-07-04 11:39:29
[ ]: