Qkit Sample Objects

The sample objects are very general and basic objects in qkit. They can be used to store any parameters of your current measurement sample. Sample objects are used as default in some measurement scripts like timedomain measurements to reduce the number of parameters that is passed as arguments.

The sample object can basically be seen as a dict, where you can store any information you want. This is particularly helpful if you write your own measurement notebook and want to apply it to different samples with different parameters. You can then simply exchange the loaded sample at the beginning of your notebook and leave the rest untouched.

Get started


In [1]:
import qkit
qkit.cfg['datadir'] = r'c:\data'
qkit.cfg['run_id'] = 'Run0'
qkit.cfg['user'] = 'qkit_user'

import qkit.measure.samples_class as sc


QKIT configuration initialized -> available as qkit.cfg[...]

In [2]:
demo = sc.Sample()

We start by creating an empty sample, which only has comment and name as attributes.

You can either use the sample.get_all() function to get a string of all attributes, or you directly use sample.attribute to access the attribute directly.


In [3]:
print demo.get_all()


comment:   
name:   Arbitrary Sample


In [4]:
demo.name


Out[4]:
'Arbitrary Sample'

In [5]:
demo.comment = "This sample looks promising."

Adding new attributes is easy, you can just set them:


In [6]:
demo.frequency = 8e9

In [7]:
print demo.get_all()


comment:   This sample looks promising.
frequency:   8000000000.0
name:   Arbitrary Sample

The sample class has also a get function, which can be used to set a default. (the same as in a dict)


In [8]:
demo.get('frequency',1e9)


Out[8]:
8000000000.0

In [9]:
demo.get('current',0)


Out[9]:
0

Saving samples

The save function saves the full sample object into a JSON serialized file. You can pass a filename argument:

  • None (default): save to datadir/ID.sample
  • absolute filepath: save to filepath
  • any other string: save to datadir/ID_string.sample

Here, datadir is qkit.cfg['datadir'] and ID is the measurement ID as it would be given for a regular measurement.


In [10]:
demo.save()


Out[10]:
'c:\\data\\Run0\\qkit_user\\P8PWYL.sample'

In [11]:
demo.save('sweet_spot')


Out[11]:
'c:\\data\\Run0\\qkit_user\\P8PWYL_sweet_spot.sample'

In [12]:
demo.save(u'C:/Users/Public/qkitsample')


Out[12]:
u'C:/Users/Public/qkitsample.sample'

Loading samples

You can either use an existig sample with sample.load(filename) or generate a new sample Sample(filename)


In [13]:
demo.load('Run0/qkit_user/P8PWYL.sample') # path can be specified relaive to the datadir

In [14]:
demo2 = sc.Sample(u'C:/Users/Public/qkitsample.sample') # absolute pathname is also fine

Make sure to update all references if you create a new sample object or overwrite it. If you use the load function, the reference will stay the same.