class qcodes.utils.magic.QCoDeSMagic(**kwargs)[source]

Bases: IPython.core.magic.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 Python for 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 uses for {iterable} instead of for {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 in data, 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} after for.

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}:
    for -d 1 {sweep_vals2}:


which will be internally transformed to:

import qcodes
loop = qcodes.Loop({sweep_vals}).each(
    qcodes.Loop({sweep_vals2}, delay=1).each(
data = loop.get_data_set(name={measurement_name})


An explicit example of the line for {sweep_vals}: could be for 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.

  • 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.