8. Scripting

This chapter describes how to write scripts to perform sequence of experiments. Scripting is useful for running multiple experiments after each other, or for defining sequences where some properties of a measurement is updated depending on the result of a previous measurement.

In a typical scripting setup, the user would first create a number of Measurement configurations using the standard Measurement configuration dialog, and then save those configurations files to a folder on disk. The script would then be programmed to execute those configurations, either as they are or by first updating one or multiple parameters of the Measurement configurations.

The most basic way of implementing scripting is to call the Measurement program with command-line arguments, as described in Section console below. The advantage of this method is that one can use any programming language that supports calling an external program for writing the script, the disadvantage is that the function calls can become rather long and difficult to read. If you plan to script experiments using the programming language Python, there are a number of helper functions that will simplify the procedure. These helper functions are described in Section scriptPython.

8.1. Console options

In addition to the user-interface based Measurement configuration dialog, it is also possible to start experiment from the command line. The program is called Measurement-Console.exe, and is located in the main program folder (see Section Installation for the folder structure). The command-line arguments are:

Measurement-Console.exe [-h] -i INPUT_PATH [-u CHANNEL VALUE TYPE]
           [-m CHANNEL] [-o OUTPUT_PATH] [-e EXPORT_PATH] [-r CHANNEL]
-h, –help:
Show a help message and exit
-i INPUT_PATH:
Path to the measurement configuration file to execute or rearrange.
-u CHANNEL VALUE TYPE:
Update the step item CHANNEL with a new value. The TYPE-argument defines what property of the step item to update, and must be one of SINGLE, START, STOP, CENTER, SPAN, STEP, N_PTS. Note that scripted measurements do not raise an error if updating an inactive step item. Instead, the step item is automatically switched to the new step type. For example, if the original step type is SINGLE, and the user updates the START value, the step type is changed to START-STOP. Note that it is up to the user to ensure that all other relevant quantities are updated as well (in the example, the STOP value and the STEP or N_PTS value).
-m CHANNEL:
Specifies the master channel name. Values of all other updated channels will be defined by look-up tables relative to the master channel values.
-o OUTPUT_PATH:
Specifies the path of the output log file. If not given, the data will be be saved to the input measurement configuration file.
-e EXPORT_PATH:
After completed measurement, export the last trace to the specified text file. Any previous contents in that file will be overwritten. This is useful for creating scripts where future measurements depend on the results of previous measurements.
-r CHANNEL:
Re-arrange a log with N 1-dimensional entries of length M to a 2-dimensional log with dimensions (N, M). The CHANNEL 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 -r Channel 1 1.0, 2.0, 3.0 Channel 2 1.0, 2.0. 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, not by the order they are listed after the -r command. Also, note that no measurement will be performed when running the program with this option.

If no arguments are given, the program will open the standard user interface window for configuring the experiment.

8.2. Scripting using Python

The Python scripting helper functions are part of the Labber API, located in the Script folder of the main program directory (see Section Folders for an overview of folder locations). To provide easy access to the Labber API, it’s recommended to add the Script folder to your Python path. For more information on the Python API, see Section PythonAPI.

The helper functions in the ScriptTools module are designed for repeatedly performing a number of Measurements that each contain one-dimensional sweeps, and where one or multiple parameters of the Measurement configurations are updated between each measurement. The 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 f_0 of resonator
  4. Measure qubit, while keeping the resonator at f_0
  5. Repeat for all values of magnetic flux

The file ExampleScript.py in the Script folder contain 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.