qcodes.utils.magic
- class qcodes.utils.magic.QCoDeSMagic(**kwargs: Any)[source]
Bases:
Magics
Magics related to code management (loading, saving, editing, …).
Setup Magic. All args and kwargs are passed to super class.
- measurement(line, cell=None)[source]
Create
qcodes.Loop
measurement mimicking Pythonfor
syntax via iPython magic.Upon execution of a notebook cell, the code is transformed from the for loop structure to a QCoDeS Loop before being executed. Can be run by having
%%measurement
in the first line of a cell, followed by the measurement name (see below for an example).The for loop syntax differs slightly from a Python
for
loop, as it usesfor {iterable}
instead offor {element} in {iterable}
. The reason is that{element}
cannot be accessed (yet) in QCoDeS loops.Comments (#) are ignored in the loop. Any code after the loop will also be run, if separated by a blank line from the loop.
The Loop object is by default stored in a variable named
loop
, and the dataset indata
, and these can be overridden using options. Must be run in a Jupyter Notebook. Delays can be provided in a loop by adding-d {delay}
afterfor
.The following options can be passed along with the measurement name (e.g.
%%measurement -px -d data_name {measurement_name})
:-p : print transformed code -x : Do not execute code -d <dataset_name> : Use custom name for dataset -l <loop_name> : Use custom name for Loop
An example for a loop cell is as follows:
%%measurement {-options} {measurement_name} for {sweep_vals}: {measure_parameter1} {measure_parameter2} for -d 1 {sweep_vals2}: {measure_parameter3} ...
which will be internally transformed to:
import qcodes loop = qcodes.Loop({sweep_vals}).each( {measure_parameter1}, {measure_parameter2}, qcodes.Loop({sweep_vals2}, delay=1).each( {measure_parameter3})) data = loop.get_data_set(name={measurement_name}) ...
An explicit example of the line
for {sweep_vals}:
could befor sweep_parameter.sweep(0, 42, step=1):
- magics = {'cell': {'measurement': 'measurement'}, 'line': {'measurement': 'measurement'}}
- registered = True
- qcodes.utils.magic.register_magic_class(cls=<class 'qcodes.utils.magic.QCoDeSMagic'>, magic_commands=True)[source]
Registers a iPython magic class.
- Parameters
cls – Magic class to register.
magic_commands (List) – List of magic commands within the class to register. If not specified, all magic commands are registered.