Exemplo n.º 1
0
def test_dond_2d_additional_setpoints(_param, _param_complex, _param_set, _param_set_2):
    additional_setpoints = [
        Parameter(f"additional_setter_parameter_{i}", set_cmd=None, get_cmd=None)
        for i in range(2)
    ]

    start_p1 = 0
    stop_p1 = 0.5
    num_points_p1 = 5
    delay_p1 = 0
    sweep_1 = LinSweep(_param_set, start_p1, stop_p1, num_points_p1, delay_p1)
    start_p2 = 0.5
    stop_p2 = 1
    num_points_p2 = 5
    delay_p2 = 0.0
    sweep_2 = LinSweep(_param_set_2, start_p2, stop_p2, num_points_p2, delay_p2)

    for x in range(2):
        for y in range(3):
            additional_setpoints[0](x)
            additional_setpoints[1](y)
            results = dond(
                sweep_1,
                sweep_2,
                _param,
                _param_complex,
                additional_setpoints=additional_setpoints,
            )
            for deps in results[0].description.interdeps.dependencies.values():
                assert len(deps) == 2 + len(additional_setpoints)
            plt.close("all")
Exemplo n.º 2
0
def test_linear_sweep_get_setpoints(_param):
    start = 0
    stop = 1
    num_points = 5
    delay = 1
    sweep = LinSweep(_param, start, stop, num_points, delay)

    np.testing.assert_array_equal(
        sweep.get_setpoints(), np.linspace(start, stop, num_points)
    )
Exemplo n.º 3
0
def test_dond_2d_output_type(_param, _param_complex, _param_set, _param_set_2):

    sweep_1 = LinSweep(_param_set, 0, 0.5, 2, 0)
    sweep_2 = LinSweep(_param_set_2, 0.5, 1, 2, 0)

    data_1 = dond(sweep_1, _param, _param_complex)
    assert isinstance(data_1[0], DataSet) is True

    data_2 = dond(sweep_1, sweep_2, _param, _param_complex)
    assert isinstance(data_2[0], DataSet) is True
Exemplo n.º 4
0
def test_linear_sweep_parameter_class(_param, _param_complex):
    start = 0
    stop = 1
    num_points = 5
    delay = 1
    sweep = LinSweep(_param, start, stop, num_points, delay)
    assert isinstance(sweep.param, _BaseParameter)

    sweep_2 = LinSweep(_param_complex, start, stop, num_points)
    assert isinstance(sweep_2.param, _BaseParameter)

    arrayparam = ArraySetPointParam(name="arrayparam")
    sweep_3 = LinSweep(arrayparam, start, stop, num_points)
    assert isinstance(sweep_3.param, _BaseParameter)
Exemplo n.º 5
0
def test_linear_sweep_properties(_param, _param_complex):
    start = 0
    stop = 1
    num_points = 5
    delay = 1
    sweep = LinSweep(_param, start, stop, num_points, delay)
    assert isinstance(sweep.param, _BaseParameter)
    assert sweep.delay == delay
    assert sweep.param == _param
    assert sweep.num_points == num_points

    # test default delay 0 with complex param
    sweep_2 = LinSweep(_param_complex, start, stop, num_points)
    assert sweep_2.delay == 0
Exemplo n.º 6
0
def test_dond_2d_plot(_param_set, _param_set_2, _param, plot, plot_config):

    if plot_config is not None:
        config.dataset.dond_plot = plot_config

    sweep_1 = LinSweep(_param_set, 0, 1, 1, 0)
    sweep_2 = LinSweep(_param_set_2, 0.1, 1.1, 2, 0)

    output = dond(sweep_1, sweep_2, _param, do_plot=plot)

    assert len(output[1]) == 1
    if plot is True or plot is None and plot_config is True:
        assert isinstance(output[1][0], matplotlib.axes.Axes)
    else:
        assert output[1][0] is None
Exemplo n.º 7
0
def test_dond_1d_output_data(_param, _param_complex, _param_set):

    sweep_1 = LinSweep(_param_set, 0, 0.5, 5, 0)

    exp_1 = dond(sweep_1, _param, _param_complex)
    data_1 = exp_1[0]
    assert data_1.parameters == (
        f"{_param_set.name},{_param.name}," f"{_param_complex.name}"
    )
    loaded_data_1 = data_1.get_parameter_data()

    np.testing.assert_array_equal(
        loaded_data_1[_param.name][_param.name], np.ones(sweep_1._num_points)
    )
    np.testing.assert_array_equal(
        loaded_data_1[_param_complex.name][_param_complex.name],
        (1 + 1j) * np.ones(sweep_1._num_points),
    )
    np.testing.assert_array_equal(
        loaded_data_1[_param_complex.name][_param_set.name],
        np.linspace(sweep_1._start, sweep_1._stop, sweep_1._num_points),
    )
    np.testing.assert_array_equal(
        loaded_data_1[_param.name][_param_set.name],
        np.linspace(sweep_1._start, sweep_1._stop, sweep_1._num_points),
    )
Exemplo n.º 8
0
def test_dond_1d_additional_setpoints_shape(_param, _param_set, num_points_p1):
    arrayparam = ArraySetPointParam(name="arrayparam")
    array_shape = arrayparam.shape
    additional_setpoints = [
        Parameter(f"additional_setter_parameter_{i}", set_cmd=None, get_cmd=None)
        for i in range(2)
    ]

    sweep = LinSweep(_param_set, 0, 0.5, num_points_p1, 0)

    x = 1
    y = 2
    additional_setpoints[0](x)
    additional_setpoints[1](y)

    results = dond(
        sweep,
        _param,
        arrayparam,
        additional_setpoints=additional_setpoints,
        do_plot=False,
    )

    expected_shapes = {
        "arrayparam": (1, 1, num_points_p1, array_shape[0]),
        "simple_parameter": (1, 1, num_points_p1),
    }
    assert results[0].description.shapes == expected_shapes
Exemplo n.º 9
0
def test_dond_2d_additional_setpoints_shape(
    _param, _param_complex, _param_set, _param_set_2, num_points_p1, num_points_p2
):
    arrayparam = ArraySetPointParam(name="arrayparam")
    array_shape = arrayparam.shape
    additional_setpoints = [
        Parameter(f"additional_setter_parameter_{i}", set_cmd=None, get_cmd=None)
        for i in range(2)
    ]

    start_p1 = 0
    stop_p1 = 1
    delay_p1 = 0
    sweep_1 = LinSweep(_param_set, start_p1, stop_p1, num_points_p1, delay_p1)
    start_p2 = 0.1
    stop_p2 = 1.1
    delay_p2 = 0
    sweep_2 = LinSweep(_param_set_2, start_p2, stop_p2, num_points_p2, delay_p2)

    x = 1
    y = 2
    additional_setpoints[0](x)
    additional_setpoints[1](y)

    results = dond(
        sweep_1,
        sweep_2,
        _param,
        _param_complex,
        arrayparam,
        additional_setpoints=additional_setpoints,
        do_plot=False,
    )
    expected_shapes = {
        "arrayparam": (1, 1, num_points_p1, num_points_p2, array_shape[0]),
        "simple_complex_parameter": (1, 1, num_points_p1, num_points_p2),
        "simple_parameter": (1, 1, num_points_p1, num_points_p2),
    }
    assert results[0].description.shapes == expected_shapes
Exemplo n.º 10
0
def test_dond_2d_output_data(_param, _param_complex, _param_set, _param_set_2):
    sweep_1 = LinSweep(_param_set, 0, 0.5, 5, 0)
    sweep_2 = LinSweep(_param_set_2, 0.5, 1, 5, 0)
    exp_2 = dond(sweep_1, sweep_2, _param, _param_complex)
    data_2 = exp_2[0]
    assert data_2.parameters == (
        f"{_param_set.name},{_param_set_2.name}," f"{_param.name},{_param_complex.name}"
    )
    loaded_data_2 = data_2.get_parameter_data()
    expected_data_2 = np.ones(25).reshape(sweep_1._num_points, sweep_2._num_points)

    np.testing.assert_array_equal(
        loaded_data_2[_param.name][_param.name], expected_data_2
    )
    expected_data_3 = (1 + 1j) * np.ones(25).reshape(
        sweep_1._num_points, sweep_2._num_points
    )
    np.testing.assert_array_equal(
        loaded_data_2[_param_complex.name][_param_complex.name], expected_data_3
    )

    expected_setpoints_1 = np.repeat(
        np.linspace(sweep_1._start, sweep_1._stop, sweep_1._num_points),
        sweep_2._num_points,
    ).reshape(sweep_1._num_points, sweep_2._num_points)
    np.testing.assert_array_equal(
        loaded_data_2[_param_complex.name][_param_set.name], expected_setpoints_1
    )

    expected_setpoints_2 = np.tile(
        np.linspace(sweep_2._start, sweep_2._stop, sweep_2._num_points),
        sweep_1._num_points,
    ).reshape(sweep_1._num_points, sweep_2._num_points)
    np.testing.assert_array_equal(
        loaded_data_2[_param_complex.name][_param_set_2.name], expected_setpoints_2
    )
Exemplo n.º 11
0
def test_dond_1d_parameter_with_array_vals(_param_set):
    param = ArrayshapedParam(name="paramwitharrayval", vals=Arrays(shape=(10,)))
    start = 0
    stop = 1
    num_points = 15  # make param
    sweep = LinSweep(_param_set, start, stop, num_points)

    results = dond(sweep, param, do_plot=False)
    expected_shapes = {"paramwitharrayval": (num_points, 10)}

    ds = results[0]

    assert ds.description.shapes == expected_shapes

    data = ds.get_parameter_data()

    for name, data in data.items():
        for param_data in data.values():
            assert param_data.shape == expected_shapes[name]
Exemplo n.º 12
0
def test_dond_1d_additional_setpoints(_param, _param_complex, _param_set):
    additional_setpoints = [
        Parameter(f"additional_setter_parameter_{i}", set_cmd=None, get_cmd=None)
        for i in range(2)
    ]
    sweep = LinSweep(_param_set, 0, 1, 5, 0)

    for x in range(3):
        for y in range(4):
            additional_setpoints[0](x)
            additional_setpoints[1](y)
            results = dond(
                sweep, _param, _param_complex, additional_setpoints=additional_setpoints
            )
            for deps in results[0].description.interdeps.dependencies.values():
                assert len(deps) == 1 + len(additional_setpoints)
            # Calling the fixture won't work here due to loop-scope.
            # Thus, we make an explicit call to close plots. This will be
            # repeated in similarly design tests.
            plt.close("all")
Exemplo n.º 13
0
def test_dond_1d_verify_shape(
    _param,
    _param_complex,
    _param_set,
    multiparamtype,
    dummyinstrument,
    num_points,
    n_points_pws,
):
    arrayparam = ArraySetPointParam(name="arrayparam")
    multiparam = multiparamtype(name="multiparam")
    paramwsetpoints = dummyinstrument.A.dummy_parameter_with_setpoints
    dummyinstrument.A.dummy_start(0)
    dummyinstrument.A.dummy_stop(1)
    dummyinstrument.A.dummy_n_points(n_points_pws)

    start = 0
    stop = 1
    delay = 0

    sweep_1 = LinSweep(_param_set, start, stop, num_points, delay)

    results = dond(
        sweep_1,
        arrayparam,
        multiparam,
        paramwsetpoints,
        _param,
        _param_complex,
        do_plot=False,
    )
    expected_shapes = {}
    for i, name in enumerate(multiparam.full_names):
        expected_shapes[name] = (num_points,) + tuple(multiparam.shapes[i])
    expected_shapes["arrayparam"] = (num_points,) + tuple(arrayparam.shape)
    expected_shapes["simple_parameter"] = (num_points,)
    expected_shapes["simple_complex_parameter"] = (num_points,)
    expected_shapes[paramwsetpoints.full_name] = (num_points, n_points_pws)
    assert results[0].description.shapes == expected_shapes
Exemplo n.º 14
0
def test_dond_2d_verify_shape(
    _param,
    _param_complex,
    _param_set,
    _param_set_2,
    multiparamtype,
    dummyinstrument,
    num_points_p1,
    num_points_p2,
    n_points_pws,
):
    arrayparam = ArraySetPointParam(name="arrayparam")
    multiparam = multiparamtype(name="multiparam")
    paramwsetpoints = dummyinstrument.A.dummy_parameter_with_setpoints
    dummyinstrument.A.dummy_start(0)
    dummyinstrument.A.dummy_stop(1)
    dummyinstrument.A.dummy_n_points(n_points_pws)

    start_p1 = 0
    stop_p1 = 1
    delay_p1 = 0
    sweep_1 = LinSweep(_param_set, start_p1, stop_p1, num_points_p1, delay_p1)
    start_p2 = 0.1
    stop_p2 = 1.1
    delay_p2 = 0
    sweep_2 = LinSweep(_param_set_2, start_p2, stop_p2, num_points_p2, delay_p2)

    results = dond(
        sweep_1,
        sweep_2,
        arrayparam,
        multiparam,
        paramwsetpoints,
        _param,
        _param_complex,
        do_plot=False,
    )
    expected_shapes = {}
    for i, name in enumerate(multiparam.full_names):
        expected_shapes[name] = (num_points_p1, num_points_p2) + tuple(
            multiparam.shapes[i]
        )
    expected_shapes["arrayparam"] = (num_points_p1, num_points_p2) + tuple(
        arrayparam.shape
    )
    expected_shapes["simple_parameter"] = (num_points_p1, num_points_p2)
    expected_shapes["simple_complex_parameter"] = (num_points_p1, num_points_p2)
    expected_shapes[paramwsetpoints.full_name] = (
        num_points_p1,
        num_points_p2,
        n_points_pws,
    )

    assert results[0].description.shapes == expected_shapes
    ds = results[0]

    data = ds.get_parameter_data()

    for name, data in data.items():
        for param_data in data.values():
            assert param_data.shape == expected_shapes[name]