4. Script tools

The helper functions in the ScriptTools module are designed for repeatedly performing Measurements that each contain one-dimensional sweeps, and where one or multiple parameters of the Measurement configurations are updated between each measurement.

4.1. Initialization

The ScriptTools functions call the Measurement executable for performing the measurements. Before the tools can be used, the path to the executable must be set using the function setExePath() defined below.

Note that in Labber version 1.1 and later, the ScriptTools module has been moved into the Labber module. To make scripts written for older versions of Labber work with version 1.1 and later, replace import ScriptTools with from Labber import ScriptTools.

4.2. Example

The ScriptTools functions are best explained by an example, which we’ll take from the domain of superconducting qubits. For the purpose of this example, we can view the qubit as a slightly anharmonic oscillators whose frequency tunes with applied magnetic flux. The qubit is read out by coupling it to microwave resonators, and the coupling is arranged in a way that changing the qubit frequency will cause a slight shift of the resonator frequency.

Now, say that we want to probe the qubit frequency as a function of applied flux. The difficulty is that the changing the flux will affect both the qubit and the resonator frequencies, which means that we can not use a fixed-frequency read-out tone. Instead, we need to implement the following procedure:

  1. Set new magnetic flux value.
  2. Measure resonator.
  3. Find resonance frequency of resonator.
  4. Measure qubit, while keeping the resonator at resonance frequency.
  5. Repeat for all values of magnetic flux.

The Python code below shows an example script for performing the sequence described above. The script assumes that the user has created two Measurement configurations, one for measuring the resonator, and one for measuring the qubit, and that both Measurement configurations have a single-valued step item called ’Flux bias’ that control the magnetic flux.

import os
import numpy as np

from Labber import ScriptTools
# set path to executable
ScriptTools.setExePath('C:\Program Files (x86)\Labber\Program')


# define list of points
vFlux = np.linspace(-1E-3, 1E-3, 101)

# define measurement objects
sPath = os.path.dirname(os.path.abspath(__file__))
MeasResonator = ScriptTools.MeasurementObject(\
                os.path.join(sPath, 'TestResonator.hdf5'),
                os.path.join(sPath, 'TestResonatorOut.hdf5'))
MeasQubit = ScriptTools.MeasurementObject(\
            os.path.join(sPath, 'TestQubit.hdf5'),
            os.path.join(sPath, 'TestQubitOut.hdf5'))
# set the master channel that defines the third data dimension
MeasResonator.setMasterChannel('Flux bias')
MeasQubit.setMasterChannel('Flux bias')

# go through list of points
for n1, value_1 in enumerate(vFlux):
    print('Flux [mA]:', 1000*value_1)
    # set flux bias
    MeasResonator.updateValue('Flux bias', value_1)
    MeasQubit.updateValue('Flux bias', value_1)
    # measure resonator
    (x,y) = MeasResonator.performMeasurement()
    # for this example, y is complex, take absolute value
    y = abs(y)
    # look for peak position
    print('Resonator position [GHz]:', x[np.argmax(y)]/1E9)
    # set new frequency position
    MeasQubit.updateValue('RF - Frequency', x[np.argmax(y)])
    # measure qubit
    (x,y) = MeasQubit.performMeasurement()

4.3. Function definitions

Labber.ScriptTools.setExePath(path)

Set path to the Measurement program, must be done before running scripts

Parameters:path (str) – Path to Measurement.exe program. On Windows, the path is typically ‘C:\Program Files (x86)\Labber\Program’.

4.4. MeasurementObject class

class Labber.ScriptTools.MeasurementObject(sCfgFileIn, sCfgFileOut)

Bases: object

Class for updating measurement objects and running experiments

Parameters:
  • sCfgFileIn (str) – Path of template config file that defines the Measurement.
  • sCfgFileOut (str) – Path to output file that will be created when running the Measurement. This should typically be different from the template file, since the dimensionally of the configuration may change as data is added.
performMeasurement(return_data=True)

Perform measurement and return (x,y)-tuple.

The function will start the application Measurement.exe.

Parameters:return_data (bool, optional) – If True, the function will return a tuple with (x,y) data (see below). Default is True.
Returns:(x,y) – A tuple with x and y data as 1-d numpy arrays. The x-data is taken from the first step channel, the y-data is taken from the first log channel.
Return type:tuple
rearrangeLog(channel_name, *extra_arg)

Re-arrange a log with N 1D entries of length M to a 2D log with dimension (N, M).

The “channel_name” determines which data to use when defining the second dimension. It is also possible to rearrange into a multi-dimensional log by specifying multiple channels, but if so lists of step values for each dimension need to be specified as well. For example, to rearrange a log with 6 entries into a multi-dimensional log with 3*2 entries, use: rearrangeLog(“Channel 1”, [1.0, 2.0, 3.0], “Channel 2”, [1.0, 2.0]) Also, note that the internal order of the new dimensions is defined by the order in which they appear in the step list of the original Measurement configuration file

Parameters:
  • channel_name (str) – Path to log file.
  • values (list of float, optional) – Step value of channel_name. If not specified, the values will be taken from log file.
setMasterChannel(channel_name)

Specifiy the master channel name.

Values of all other updated channels will be defined by look-up tables relative to the master channel values.

Parameters:channel_name (str) – Name of master channel.
setOutputFile(filename)

Set output file when performing the measurement

Parameters:filename (str) – Path to output file.
updateValue(channel_name, value, itemType=u'SINGLE')

Update a single value in the config file.

The values are kept track of internally until the Measurement.exe program is called.

Parameters:
  • channel_name (str) – Name of channel to update.
  • value (float) – New value to set to channel.
  • itemType (str, optional) – Step item parameter to set, must be one of {SINGLE, START, STOP, CENTER, SPAN, STEP, N_PTS}. Default is SINGLE.