Skip to content

Commit

Permalink
Merge #3847
Browse files Browse the repository at this point in the history
3847: ArraySweep for dond r=astafan8 a=astafan8



Co-authored-by: Mikhail Astafev <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 20, 2022
2 parents f4c2fb6 + b87c978 commit cf19e0a
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 25 deletions.
2 changes: 2 additions & 0 deletions docs/changes/newsfragments/3847.new
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add ``ArraySweep`` sweep class for use with ``dond`` function
for sweeping parameters on arbitrary arrays of values

Large diffs are not rendered by default.

47 changes: 46 additions & 1 deletion qcodes/tests/dataset/test_doNd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
MultiSetPointParam,
)
from qcodes.utils import validators
from qcodes.utils.dataset.doNd import LinSweep, LogSweep, do0d, do1d, do2d, dond
from qcodes.utils.dataset.doNd import ArraySweep, LinSweep, LogSweep, do0d, do1d, do2d, dond
from qcodes.utils.validators import Arrays

from .conftest import ArrayshapedParam
Expand Down Expand Up @@ -1081,6 +1081,51 @@ def test_log_sweep_parameter_class(_param, _param_complex):
assert isinstance(sweep_3.param, _BaseParameter)


def test_array_sweep_get_setpoints(_param):
array = np.linspace(0, 1, 5)
delay = 1
sweep = ArraySweep(_param, array, delay)

np.testing.assert_array_equal(
sweep.get_setpoints(), array
)

array2 = [1, 2, 3, 4, 5, 5.2]
sweep2 = ArraySweep(_param, array2)

np.testing.assert_array_equal(
sweep2.get_setpoints(), np.array(array2)
)


def test_array_sweep_properties(_param):
array = np.linspace(0, 1, 5)
delay = 1
sweep = ArraySweep(_param, array, delay)
assert isinstance(sweep.param, _BaseParameter)
assert sweep.delay == delay
assert sweep.param == _param
assert sweep.num_points == len(array)

# test default delay 0
sweep_2 = ArraySweep(_param, array)
assert sweep_2.delay == 0


def test_array_sweep_parameter_class(_param, _param_complex):
array = np.linspace(0, 1, 5)

sweep = ArraySweep(_param, array)
assert isinstance(sweep.param, _BaseParameter)

sweep_2 = ArraySweep(_param_complex, array)
assert isinstance(sweep_2.param, _BaseParameter)

arrayparam = ArraySetPointParam(name="arrayparam")
sweep_3 = ArraySweep(arrayparam, array)
assert isinstance(sweep_3.param, _BaseParameter)


def test_dond_explicit_exp_meas_sample(_param, experiment):
experiment_2 = new_experiment("new-exp", "no-sample")

Expand Down
43 changes: 43 additions & 0 deletions qcodes/utils/dataset/doNd.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,49 @@ def post_actions(self) -> ActionsT:
return self._post_actions


class ArraySweep(AbstractSweep):
"""
Sweep the values of a given array.
Args:
param: Qcodes parameter for sweep.
array: array with values to sweep.
delay: Time in seconds between two consecutive sweep points.
post_actions: Actions to do after each sweep point.
"""

def __init__(
self,
param: _BaseParameter,
array: Union[Sequence[float], np.ndarray],
delay: float = 0,
post_actions: ActionsT = (),
):
self._param = param
self._array = np.array(array)
self._delay = delay
self._post_actions = post_actions

def get_setpoints(self) -> np.ndarray:
return self._array

@property
def param(self) -> _BaseParameter:
return self._param

@property
def delay(self) -> float:
return self._delay

@property
def num_points(self) -> int:
return len(self._array)

@property
def post_actions(self) -> ActionsT:
return self._post_actions


def dond(
*params: Union[AbstractSweep, Union[ParamMeasT, Sequence[ParamMeasT]]],
write_period: Optional[float] = None,
Expand Down

0 comments on commit cf19e0a

Please sign in to comment.