quantify_core.measurement
#
Import alias |
Maps to |
---|---|
|
|
|
|
|
|
|
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
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:
Set some parameter(s) (settable_pars)
Measure some other parameter(s) (gettable_pars)
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.
See also
- Parameters:
name (
str
) – name of this instrument.
- _curr_setpoint_idx()[source]#
Current position through the sweep
- Return type:
- Returns:
int setpoint_idx
- _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
- _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.
- 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 isNone
, the.lazy_set()
ManualParameter is used instead (which by default isFalse
).Warning
This feature is not available yet when running in batched mode.
save_data (
bool
(default:True
)) – IfTrue
that the measurement data is stored.
- Return type:
- 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
)) – IfTrue
and a setpoint equals the previous setpoint, the.set
method of the settable will not be called for that iteration. If this argument isNone
, the.lazy_set()
ManualParameter is used instead (which by default isFalse
).
- Return type:
- 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.
See also
- 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.
- _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 thelazy_set
argument passed to therun()
andrun_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 tostd_out
during experiments.
- class _KeyboardInterruptManager(n_forced=5)[source]#
Support class for handling keyboard interrupts in a controlled way.
- 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.