Exemple #1
0
def sweep(
        parameter: Union[Parameter, SweepFunction],
        set_points: Iterator = None,
        start: float = None,
        stop: float = None,
        step_size: float = None,
        step_count: int = None,
        step_delay: float = 0,
        parameter_type: str = None
) -> BaseSweepObject:
    """
    Create a sweep object which sweeps the given parameter.

    Args:
        parameter: The parameter to sweep
        set_points: The set point values to sweep over.
            If the set points are not given, the start,
            stop and step or step_count values are needed.
        start: The start value of the sweep
            This value is required if a set point iterator is not provided
        stop: The stop value of the sweep
            This value is required if a set point iterator is not provided
        step_size: The step size of the sweep.
            If the set point iterator is not provided, we either need this
            value or a value for `step_count`. Please note that there need
            to fit an integer number of steps between the start and stop values.
            If this is not the case, we round of to the nearest integer number
            of steps and issue a warning that the step_value has changed.
        step_count: the number of step in the sweep.
            If the set point iterator is not provided, we either need this
            value or a value for `step`.
        step_delay: At each iteration, wait for the specified number of seconds
        parameter_type: ['array', 'numeric', 'text', 'complex']
            The type of parameter which is being swept. The default value
            is 'numeric'
    """

    if isinstance(parameter, Parameter):
        fun = parameter_setter(parameter, paramtype=parameter_type)
    elif isinstance(parameter, SweepFunction):
        fun = parameter
    else:
        raise ValueError(
            "Can only sweep a QCoDeS parameter or a function "
            "decorated with qsweep.setter"
        )

    if set_points is None:
        set_points = make_setpoints_array(
            start, stop, step_size, step_count
        )

    if not callable(set_points):
        sweep_object = Sweep(fun, fun.parameter_table, lambda: set_points)
    else:
        sweep_object = Sweep(fun, fun.parameter_table, set_points)

    sweep_object.add_post_step(lambda: time.sleep(step_delay))

    return sweep_object
Exemple #2
0
def test_post_call(indep_params):
    class PostCaller:
        def __init__(self):
            self.call_count = 0

        def __call__(self):
            self.call_count += 1

    post_call = PostCaller()

    px, x, table = indep_params["x"]

    sweep_values = [0, 1, 2]
    parameter_sweep = Sweep(x, table, lambda: sweep_values)
    parameter_sweep.add_post_step(post_call)

    assert list(parameter_sweep) == [{"x": value} for value in sweep_values]
    assert post_call.call_count == len(sweep_values)