qcodes.dataset.measurements

The measurement module provides a context manager for registering parameters to measure and storing results. The user is expected to mainly interact with it using the Measurement class.

class qcodes.dataset.measurements.DataSaver(dataset: qcodes.dataset.data_set_protocol.DataSetProtocol, write_period: float, interdeps: qcodes.dataset.descriptions.dependencies.InterDependencies_)[source]

Bases: object

The class used by the Runner context manager to handle the datasaving to the database.

default_callback: Optional[Dict[Any, Any]] = None
add_result(*res_tuple: Tuple[Union[qcodes.instrument.parameter._BaseParameter, str], Union[str, complex, numpy.integer, numpy.floating, numpy.complexfloating, numpy.ndarray, Sequence[Union[str, complex, numpy.integer, numpy.floating, numpy.complexfloating]]]]) None[source]

Add a result to the measurement results. Represents a measurement point in the space of measurement parameters, e.g. in an experiment varying two voltages and measuring two currents, a measurement point is four dimensional (v1, v2, c1, c2). The corresponding call to this function would be

>>> datasaver.add_result((v1, 0.1), (v2, 0.2), (c1, 5), (c2, -2.1))

For better performance, this function does not immediately write to the database, but keeps the results in memory. Writing happens every write_period seconds and during the __exit__ method of this class.

Parameters

res_tuple – A tuple with the first element being the parameter name and the second element is the corresponding value(s) at this measurement point. The function takes as many tuples as there are results.

Raises
  • ValueError – If a parameter name is not registered in the parent Measurement object.

  • ValueError – If the shapes of parameters do not match, i.e. if a parameter gets values of a different shape than its setpoints (the exception being that setpoints can always be scalar)

  • ValueError – If multiple results are given for the same parameter.

  • ParameterTypeError – If a parameter is given a value not matching its type.

flush_data_to_database(block: bool = False) None[source]

Write the in-memory results to the database.

Parameters

block – If writing using a background thread block until the background thread has written all data to disc. The argument has no effect if not using a background thread.

export_data() None[source]

Export data at end of measurement as per export_type specification in “dataset” section of qcodes config

property run_id: int
property points_written: int
property dataset: qcodes.dataset.data_set_protocol.DataSetProtocol
class qcodes.dataset.measurements.Measurement(exp: Optional[qcodes.dataset.experiment_container.Experiment] = None, station: Optional[qcodes.station.Station] = None, name: str = '')[source]

Bases: object

Measurement procedure container. Note that multiple measurement instances cannot be nested.

Parameters
  • exp – Specify the experiment to use. If not given the default one is used. The default experiment is the latest one created.

  • station – The QCoDeS station to snapshot. If not given, the default one is used.

  • name – Name of the measurement. This will be passed down to the dataset produced by the measurement. If not given, a default value of ‘results’ is used for the dataset.

property parameters: Dict[str, qcodes.dataset.descriptions.param_spec.ParamSpecBase]
property write_period: float
register_parent(parent: qcodes.dataset.data_set.DataSet, link_type: str, description: str = '') qcodes.dataset.measurements.T[source]

Register a parent for the outcome of this measurement

Parameters
  • parent – The parent dataset

  • link_type – A name for the type of parent-child link

  • description – A free-text description of the relationship

register_parameter(parameter: qcodes.instrument.parameter._BaseParameter, setpoints: Optional[Sequence[Union[str, qcodes.instrument.parameter._BaseParameter]]] = None, basis: Optional[Sequence[Union[str, qcodes.instrument.parameter._BaseParameter]]] = None, paramtype: Optional[str] = None) qcodes.dataset.measurements.T[source]

Add QCoDeS Parameter to the dataset produced by running this measurement.

Parameters
  • parameter – The parameter to add

  • setpoints – The Parameter representing the setpoints for this parameter. If this parameter is a setpoint, it should be left blank

  • basis – The parameters that this parameter is inferred from. If this parameter is not inferred from any other parameters, this should be left blank.

  • paramtype – Type of the parameter, i.e. the SQL storage class, If None the paramtype will be inferred from the parameter type and the validator of the supplied parameter.

register_custom_parameter(name: str, label: Optional[str] = None, unit: Optional[str] = None, basis: Optional[Sequence[Union[str, qcodes.instrument.parameter._BaseParameter]]] = None, setpoints: Optional[Sequence[Union[str, qcodes.instrument.parameter._BaseParameter]]] = None, paramtype: str = 'numeric') qcodes.dataset.measurements.T[source]

Register a custom parameter with this measurement

Parameters
  • name – The name that this parameter will have in the dataset. Must be unique (will overwrite an existing parameter with the same name!)

  • label – The label

  • unit – The unit

  • basis – A list of either QCoDeS Parameters or the names of parameters already registered in the measurement that this parameter is inferred from

  • setpoints – A list of either QCoDeS Parameters or the names of of parameters already registered in the measurement that are the setpoints of this parameter

  • paramtype – Type of the parameter, i.e. the SQL storage class

unregister_parameter(parameter: Sequence[Union[str, qcodes.instrument.parameter._BaseParameter]]) None[source]

Remove a custom/QCoDeS parameter from the dataset produced by running this measurement

add_before_run(func: Callable[[...], Any], args: Sequence[Any]) qcodes.dataset.measurements.T[source]

Add an action to be performed before the measurement.

Parameters
  • func – Function to be performed

  • args – The arguments to said function

add_after_run(func: Callable[[...], Any], args: Sequence[Any]) qcodes.dataset.measurements.T[source]

Add an action to be performed after the measurement.

Parameters
  • func – Function to be performed

  • args – The arguments to said function

add_subscriber(func: Callable[[...], Any], state: Union[MutableSequence[Any], MutableMapping[Any, Any]]) qcodes.dataset.measurements.T[source]

Add a subscriber to the dataset of the measurement.

Parameters
  • func – A function taking three positional arguments: a list of tuples of parameter values, an integer, a mutable variable (list or dict) to hold state/writes updates to.

  • state – The variable to hold the state.

set_shapes(shapes: Optional[Dict[str, Tuple[int, ...]]]) None[source]

Set the shapes of the data to be recorded in this measurement.

Parameters

shapes – Dictionary from names of dependent parameters to a tuple of integers describing the shape of the measurement.

run(write_in_background: Optional[bool] = None, in_memory_cache: bool = True, dataset_class: Type[qcodes.dataset.data_set_protocol.DataSetProtocol] = <class 'qcodes.dataset.data_set.DataSet'>) qcodes.dataset.measurements.Runner[source]

Returns the context manager for the experimental run

Parameters
  • write_in_background – if True, results that will be added within the context manager with DataSaver.add_result will be stored in background, without blocking the main thread that is executing the context manager. By default the setting for write in background will be read from the qcodesrc.json config file.

  • in_memory_cache – Should measured data be keep in memory and available as part of the dataset.cache object.

  • dataset_class – Class implementing the dataset protocol interface used to store the data.

exception qcodes.dataset.measurements.ParameterTypeError[source]

Bases: Exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class qcodes.dataset.measurements.Runner(enteractions: Sequence[Tuple[Callable[[...], Any], Sequence[Any]]], exitactions: Sequence[Tuple[Callable[[...], Any], Sequence[Any]]], experiment: Optional[qcodes.dataset.experiment_container.Experiment] = None, station: Optional[qcodes.station.Station] = None, write_period: Optional[float] = None, interdeps: qcodes.dataset.descriptions.dependencies.InterDependencies_ = InterDependencies_(dependencies={}, inferences={}, standalones=frozenset()), name: str = '', subscribers: Optional[Sequence[Tuple[Callable[[...], Any], Union[MutableSequence[Any], MutableMapping[Any, Any]]]]] = None, parent_datasets: Sequence[Mapping[Any, Any]] = (), extra_log_info: str = '', write_in_background: bool = False, shapes: Optional[Dict[str, Tuple[int, ...]]] = None, in_memory_cache: bool = True, dataset_class: Type[qcodes.dataset.data_set_protocol.DataSetProtocol] = <class 'qcodes.dataset.data_set.DataSet'>)[source]

Bases: object

Context manager for the measurement.

Lives inside a Measurement and should never be instantiated outside a Measurement.

This context manager handles all the dirty business of writing data to the database. Additionally, it may perform experiment bootstrapping and clean-up after a measurement.