mjolnir.measurements.sweeps#
This module provides classes to define parameter sweeps.
Sweeps implement (and sublcass) SweepProtocol s, which defines
binary operators to nest, parallelize, and concatenate sweeps.
Todo
labcore/quantify might be suitable to replace this
compose sweeps with different parameters (broadcast)
sweep arithmetic: +/-//*?
Classes
Abstract base class or sweeps. |
|
|
A sweep over arbitrary values. |
|
A linearly spaced sweep radiating out from a center position. |
|
Sweep values on a regularly spaced grid. |
|
A list of sweeps which will be executed nested. |
|
Protocol defining a parameter sweep. |
- class mjolnir.measurements.sweeps.AbstractSweep[source]#
Bases:
Sequence[_T]Abstract base class or sweeps.
The intended implementation is a dataclass that accepts the following attributes as initialization arguments. The attributes will be tuples with length corresponding to the number of parameters this sweep steps in parallel (see below). The only exception being num_points, which must be the same for all parameters and is therefore scalar.
- param#
One or more parameters that provide a set method. If multiple, all of them will be stepped in parallel (i.e., each parameter will be set at each point of a sweep).
- delay#
Time(s) to sleep after setting a value.
- Type:
- num_points#
The total number of points in the sweep (including all directions).
- init_actions#
A (tuple of) actions (callables that take no arguments) to run at the start of the first sweep direction when calling
initialize().- Type:
collections.abc.Sequence[collections.abc.Callable[[], None]] | collections.abc.Sequence[collections.abc.Sequence[collections.abc.Callable[[], None]]]
- post_actions#
A (tuple of) actions (callables that take the current setpoint as sole argument) to run after setting each value. For mulitple parameters, should also be a tuple of tuples of actions. If not, some logic is applied to “broadcast” the supplied actions to the parameters, but no guarantees.
- Type:
collections.abc.Sequence[collections.abc.Callable[[Any], None]] | collections.abc.Sequence[collections.abc.Sequence[collections.abc.Callable[[Any], None]]]
- get_after_set#
Should the parameter(s) be gotten after being set?
- Type:
- transform#
A callable with signature:
(val: _T) -> _T
that takes the set value and returns the transformed value. Post-actions are applied to the transformed value.
- Type:
collections.abc.Callable[[mjolnir.measurements.sweeps._T], mjolnir.measurements.sweeps._T] | collections.abc.Sequence[collections.abc.Callable[[mjolnir.measurements.sweeps._T], mjolnir.measurements.sweeps._T]]
- Parameters:
x (_T)
- Return type:
_T
- The following should be properties, not init fields
- start#
A tuple of starting values at which the sweep starts. These values are navigated to when calling
initialize().
- setpoints#
The parameter values that will be visited during the sweep. Should be a tuple of arrays of shape (n_directions, n_pts,), where the tuple is for each parameter and the first axis of the array is for multiple directions of the sweep. That is, first the first row of the array will be swept, then the second, etc. Hence, it is the axis along which the concatenation operator
@sequences sweeps.
- leak_measures#
A
MeasureSetof measures returning leakage currents. Defaults to an empty set.
- initialize(i=0)[source]#
Go to starting point for direction i and perform custom init tasks.
If i is 0, i.e, the initial direction, runs all init_actions.
Then sets params in reverse order so that going back to start after sweeping will always be reproducible and not run into parameter bounds.
- Parameters:
i (int)
- property leak_measures: MeasureSet#
A
MeasureSetof QDAC leakage parameters.
- param: ParameterBase | Sequence[ParameterBase]#
- set(*vals)[source]#
Set the parameters to vals.
Roughly equivalent to:
for param, trafo, val in zip(self.params, self.transforms, vals): param.set(trafo(val))
Todo
Threaded?
- Parameters:
vals (_T)
- Return type:
tuple[_T, …]
- property setpoints: tuple[Sequence[Sequence[_T]], ...]#
A tuple of 2d-arrays of setpoints.
The last axis enumerates parameters (i.e., is of size
len(self.param), the first axis enumerates setpoints (i.e., is of sizenum_points), and the tuple enumerates sweep directions.
- abstract property start: tuple[tuple[_T, ...], ...]#
The starting points of the sweep.
initialize()will set parameters to these values.
- transform()#
- Parameters:
x (_T)
- Return type:
_T
- class mjolnir.measurements.sweeps.ArraySweep(param, array, delay=0.0, init_actions=(), post_actions=(), get_after_set=False, transform=<function Id>)[source]#
Bases:
ArraySweep,ArraySweep,AbstractSweep,Sequence,Reversible,Collection,Sized,Iterable,Container,objectA sweep over arbitrary values.
See base class for common parameters.
- Parameters:
array (numpy._typing._array_like._Buffer | numpy._typing._array_like._SupportsArray[numpy.dtype[Any]] | numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]] | complex | bytes | str | numpy._typing._nested_sequence._NestedSequence[complex | bytes | str] | collections.abc.Sequence[numpy._typing._array_like._Buffer | numpy._typing._array_like._SupportsArray[numpy.dtype[Any]] | numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]] | complex | bytes | str | numpy._typing._nested_sequence._NestedSequence[complex | bytes | str]]) – The setpoints to visit in the sweep.
param (ParameterBase | Sequence[ParameterBase])
init_actions (_InitActionsT | Sequence[_InitActionsT])
post_actions (_PostActionsT | Sequence[_PostActionsT])
transform (Callable[[_T], _T] | Sequence[Callable[[_T], _T]])
- class mjolnir.measurements.sweeps.CenteredLinearSweep(param, rng, num_points, center=nan, delay=0.0, init_actions=(), post_actions=(), get_after_set=False, transform=<function Id>)[source]#
Bases:
CenteredLinearSweep,CenteredLinearSweep,AbstractSweep,Sequence,Reversible,Collection,Sized,Iterable,Container,objectA linearly spaced sweep radiating out from a center position.
See base class for common parameters.
- Parameters:
center (float | collections.abc.Sequence[float]) – The center (starting point) of the sweep.
param (ParameterBase | Sequence[ParameterBase])
num_points (int)
init_actions (Sequence[Callable[[], None]] | Sequence[Sequence[Callable[[], None]]])
post_actions (Sequence[Callable[[Any], None]] | Sequence[Sequence[Callable[[Any], None]]])
transform (Callable[[_T], _T] | Sequence[Callable[[_T], _T]])
- property num_points#
The total number of points that will be set.
- class mjolnir.measurements.sweeps.GridSweep(param, rng, num_points, spacing='lin', delay=0.0, init_actions=(), post_actions=(), get_after_set=False, transform=<function Id>)[source]#
Bases:
GridSweep,GridSweep,AbstractSweep,Sequence,Reversible,Collection,Sized,Iterable,Container,objectSweep values on a regularly spaced grid.
See base class for common parameters.
- Parameters:
spacing (Literal['lin', 'geom', 'log'] | collections.abc.Sequence[Literal['lin', 'geom', 'log']]) –
- The numpy function to use to grid the values.
param (ParameterBase | Sequence[ParameterBase])
num_points (int)
init_actions (Sequence[Callable[[], None]] | Sequence[Sequence[Callable[[], None]]])
post_actions (Sequence[Callable[[Any], None]] | Sequence[Sequence[Callable[[Any], None]]])
transform (Callable[[_T], _T] | Sequence[Callable[[_T], _T]])
- property num_points#
The total number of points that will be set.
- class mjolnir.measurements.sweeps.SweepList(sweeps)[source]#
Bases:
list[SweepProtocol[_T]]A list of sweeps which will be executed nested.
The first item in the list will be the outermost loop. Hence, measures will be gotten at each point of the sweep that is the last item in this list.
SweepLists can be composed via the usual list methods and in-place using the |= operator.- Parameters:
sweeps (Iterable[SweepProtocol[_T]])
- property leak_measures: MeasureSet#
All leakage measures of the complex sweep.
- property params: tuple[ParameterBase, ...]#
All parameters of the complex sweep.