quantify_core.measurement#

Import alias

Maps to

quantify_core.measurement.MeasurementControl

MeasurementControl

quantify_core.measurement.grid_setpoints

grid_setpoints

quantify_core.measurement.Gettable

Gettable

quantify_core.measurement.Settable

Settable

types#

Module containing the core types for use with the MeasurementControl.

class Gettable(obj: Any)[source]#

Defines the Gettable concept, which is considered complete if the given type satisfies the following: This class does not wrap the passed in object but simply verifies and returns it.

attributes

properties

  • name

identifier

oneOf

type

string

type

array

items

type

string

  • label

axis descriptor

oneOf

type

string

type

array

items

type

string

  • unit

unit of measurement

oneOf

type

string

type

array

items

type

string

  • batched

true if data is processed in batches, false otherwise

type

boolean

  • batch_size

When .batched=True, indicates the (maximum) size of the batch of datapoints that this gettable supports. The measurement loop will effectively use the min(settable(s).batch_size, gettable(s).batch_size).

type

integer

methods

properties

  • get

get values from this device

type

object

  • prepare

called before the acquisition loop

type

object

  • finish

called once after the acquisition loop

type

object

class Settable(obj: Any)[source]#

Defines the Settable concept, which is considered complete if the given type satisfies the following: This class does not wrap the passed in object but simply verifies and returns it.

attributes

properties

  • name

identifier

type

string

  • label

axis descriptor

type

string

  • unit

unit of measurement

type

string

  • batched

true if data is processed in batches, false otherwise

type

boolean

  • batch_size

When .batched=True, indicates the (maximum) size of the batch of datapoints that this settable supports. The measurement loop will effectively use the min(settable(s).batch_size, gettable(s).batch_size).

type

integer

methods

properties

  • set

send data to this device

type

object

  • prepare

called before the acquisition loop

type

object

  • finish

called once after the acquisition loop

type

object

is_batched(obj)[source]#
Return type:

bool

Returns:

the .batched attribute of the settable/gettable obj, False if not present.

is_object_or_function(checker, instance)[source]#

Checks if an instance is an object/function

Return type:

bool

Returns:

True if the instance is an object or a function, False otherwise

control#

Module containing the MeasurementControl.

class MeasurementControl(name)[source]#

Instrument responsible for controlling the data acquisition loop.

MeasurementControl (MC) is based on the notion that every experiment consists of the following steps:

  1. Set some parameter(s) (settable_pars)

  2. Measure some other parameter(s) (gettable_pars)

  3. Store the data.

Example

meas_ctrl.settables(mw_source1.freq)
meas_ctrl.setpoints(np.arange(5e9, 5.2e9, 100e3))
meas_ctrl.gettables(pulsar_QRM.signal)
dataset = meas_ctrl.run(name='Frequency sweep')

MC exists to enforce structure on experiments. Enforcing this structure allows:

  • Standardization of data storage.

  • Providing basic real-time visualization.

MC imposes minimal constraints and allows:

  • Iterative loops, experiments in which setpoints are processed step by step.

  • Batched loops, experiments in which setpoints are processed in batches.

  • Adaptive loops, setpoints are determined based on measured values.

Parameters:

name (str) – name of this instrument.

_curr_setpoint_idx()[source]#

Current position through the sweep

Return type:

int

Returns:

int setpoint_idx

_finish()[source]#

Call finish() on all Settables and Gettables, if finish() exists

Return type:

None

_get_fracdone()[source]#

Returns the fraction of the experiment that is completed.

Return type:

float

_get_max_setpoints()[source]#

The total number of setpoints to examine

Return type:

int

_init(name)[source]#

Initializes MC, such as creating the Dataset, experiment folder and such.

_iterative_set_and_get(setpoints, idx, lazy_set=False)[source]#

Processes one row of setpoints. Sets all settables, gets all gettables, encodes new data in dataset.

If lazy_set==True and any setpoint equals the corresponding previous setpoint, that setpoint is not set in its corresponding settable.

Note

Note: some lines in this function are redundant depending on mode (sweep vs adaptive). Specifically:

  • in sweep, the x dimensions are already filled

  • in adaptive, soft_avg is always 1

_prepare_gettables()[source]#

Call prepare() on the Gettable, if prepare() exists

Return type:

None

_prepare_settables()[source]#

Call prepare() on all Settable, if prepare() exists

Return type:

None

_reset(save_data=True)[source]#

Resets all experiment specific variables for a new run.

_reset_post()[source]#

Resets specific variables that can change before .run().

_safe_write_dataset()[source]#

Uses a lock when writing the file to stay safe for multiprocessing. Locking files are written into a temporary dir to avoid polluting the experiment container.

_update(print_message=None)[source]#

Do any updates to/from external systems, such as saving, plotting, etc.

clear_experiment_data()[source]#

Remove all experiment_data parameters from the experiment_data submodule

get_idn()[source]#

Parse a standard VISA *IDN? response into an ID dict.

Even though this is the VISA standard, it applies to various other types as well, such as IPInstruments, so it is included here in the Instrument base class.

Override this if your instrument does not support *IDN? or returns a nonstandard IDN string. This string is supposed to be a comma-separated list of vendor, model, serial, and firmware, but semicolon and colon are also common separators so we accept them here as well.

Return type:

dict[str, str | None]

Returns:

A dict containing vendor, model, serial, and firmware.

gettables(gettable_pars)[source]#

Define the parameters to be acquired during the acquisition loop.

The Gettable helper class defines the requirements for a Gettable object.

Parameters:

gettable_pars

parameter(s) to be get during the acquisition loop, accepts:
  • list or tuple of multiple Gettable objects

  • a single Gettable object

measurement_description()[source]#

Return a serializable description of the latest measurement

Users can add additional information to the description manually.

Return type:

Dict[str, Any]

Returns:

: Dictionary with description of the measurement

print_progress(progress_message=None)[source]#

Prints the provided progress_messages or displays tqdm progress bar; and calls the callback specified by on_progress_callback.

NB: if called with no progress message (progress bar is used),

self.pbar attribute should be closed and removed.

Printing and progress bar display can be suppressed with .verbose(False).

run(name='', soft_avg=1, lazy_set=None, save_data=True)[source]#

Starts a data acquisition loop.

Parameters:
  • name (str (default: '')) – Name of the measurement. It is included in the name of the data files.

  • soft_avg (int (default: 1)) – Number of software averages to be performed by the measurement control. E.g. if soft_avg=3 the full dataset will be measured 3 times and the measured values will be averaged element-wise, the averaged dataset is then returned.

  • lazy_set (Optional[bool] (default: None)) –

    If True and a setpoint equals the previous setpoint, the .set method of the settable will not be called for that iteration. If this argument is None, the .lazy_set() ManualParameter is used instead (which by default is False).

    Warning

    This feature is not available yet when running in batched mode.

  • save_data (bool (default: True)) – If True that the measurement data is stored.

Return type:

Dataset

run_adaptive(name, params, lazy_set=None)[source]#

Starts a data acquisition loop using an adaptive function.

Warning

The functionality of this mode can be complex - it is recommended to read the relevant long form documentation.

Parameters:
  • name – Name of the measurement. This name is included in the name of the data files.

  • params – Key value parameters describe the adaptive function to use, and any further parameters for that function.

  • lazy_set (Optional[bool] (default: None)) – If True and a setpoint equals the previous setpoint, the .set method of the settable will not be called for that iteration. If this argument is None, the .lazy_set() ManualParameter is used instead (which by default is False).

Return type:

Dataset

set_experiment_data(experiment_data, overwrite=True)[source]#

Populates the experiment_data submodule with experiment_data parameters

Parameters:
  • experiment_data (Dict[str, Any]) –

    Dict specifying the names of the experiment_data parameters and their values. Follows the format:

    {
        "parameter_name": {
            "value": 10.2
            "label": "parameter label"
            "unit": "Hz"
        }
    }
    

  • overwrite (bool (default: True)) – If True, clear all previously saved experiment_data parameters and save new ones. If False, keep all previously saved experiment_data parameters and change their values if necessary

setpoints(setpoints)[source]#

Set setpoints that determine values to be set in acquisition loop.

Tip

Use column_stack() to reshape multiple 1D arrays when setting multiple settables.

Parameters:

setpoints (ndarray) – An array that defines the values to loop over in the experiment. The shape of the array has to be either (N,) or (N,1) for a 1D loop; or (N, M) in the case of an MD loop.

setpoints_grid(setpoints)[source]#

Makes a grid from the provided setpoints assuming each array element corresponds to an orthogonal dimension. The resulting gridded points determine values to be set in the acquisition loop.

The gridding is such that the inner most loop corresponds to the batched settable with the smallest .batch_size.

Parameters:

setpoints (Iterable[ndarray]) – The values to loop over in the experiment. The grid is reshaped in the same order.

settables(settable_pars)[source]#

Define the settable parameters for the acquisition loop.

The Settable helper class defines the requirements for a Settable object.

Parameters:

settable_pars – parameter(s) to be set during the acquisition loop, accepts a list or tuple of multiple Settable objects or a single Settable object.

show()[source]#

Print short representation of the object to stdout.

_gettable_pars: list[Gettable]#

Parameter(s) to be get during the acquisition loop.

_setpoints: list[np.ndarray]#

An (M, N) matrix of N setpoints for M settables.

_setpoints_input: Iterable[np.ndarray]#

The values to loop over in the experiment.

_settable_pars: list[Settable]#

Parameter(s) to be set during the acquisition loop.

instr_plotmon = InstrumentRefParameter( vals=vals.MultiType(vals.Strings(), vals.Enum(None)), instrument=self, name="instr_plotmon", )#

Instrument responsible for live plotting. Can be set to None to disable live plotting.

lazy_set = ManualParameter( vals=vals.Bool(), initial_value=False, name="lazy_set", instrument=self, )#

If set to True, only set any settable if the setpoint differs from the previous setpoint. Note that this parameter is overridden by the lazy_set argument passed to the run() and run_adaptive() methods.

on_progress_callback = ManualParameter( vals=vals.Callable(), instrument=self, name="on_progress_callback", )#

A callback to communicate progress. This should be a callable accepting floats between 0 and 100 indicating the percentage done.

update_interval = ManualParameter( initial_value=0.5, vals=vals.Numbers(min_value=0.1), instrument=self, name="update_interval", )#

Interval for updates during the data acquisition loop, every time more than update_interval time has elapsed when acquiring new data points, data is written to file (and the live monitoring detects updated).

verbose = ManualParameter( vals=vals.Bool(), initial_value=True, instrument=self, name="verbose", )#

If set to True, prints to std_out during experiments.

class _KeyboardInterruptManager(n_forced=5)[source]#

Support class for handling keyboard interrupts in a controlled way.

raise_if_interrupted()[source]#

Verifies if the user has signaled the interruption of the experiment.

Intended to be used after each iteration or after each batch of data.

Return type:

None

class _SupportsMul(*args, **kwargs)[source]#

A type that supports multiplication (*).

grid_setpoints(setpoints, settables=None)[source]#

Make gridded setpoints.

If settables is provided, the gridding is such that the inner most loop corresponds to the batched settable with the smallest .batch_size.

Parameters:
  • setpoints (Sequence[Sequence]) – A list of arrays that defines the values to loop over in the experiment for each orthogonal dimension. The grid is reshaped in the same order.

  • settables (Iterable | None (default: None)) – A list of settable objects to which the elements in the setpoints correspond to. Used to correctly grid data when mixing batched and iterative settables.

Return type:

list[np.ndarray]

Returns:

list[np.ndarray] A 2D array where the first axis corresponds to the settables, and the second axis to individual setpoints.