Example #1
0
def array_dataset(experiment, request):
    meas = Measurement()
    param = ArraySetPointParam()
    meas.register_parameter(param, paramtype=request.param)

    with meas.run() as datasaver:
        datasaver.add_result((param, param.get(),))
    try:
        yield datasaver.dataset
    finally:
        datasaver.dataset.conn.close()
Example #2
0
def test_do1d_additional_setpoints_shape(_param, _param_complex, _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)
    ]
    start_p1 = 0
    stop_p1 = 0.5
    delay_p1 = 0

    x = 1
    y = 2

    additional_setpoints[0](x)
    additional_setpoints[1](y)
    results = do1d(_param_set,
                   start_p1,
                   stop_p1,
                   num_points_p1,
                   delay_p1,
                   _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
Example #3
0
def test_do1d_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

    results = do1d(_param_set,
                   start,
                   stop,
                   num_points,
                   delay,
                   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
Example #4
0
def test_do0d_verify_shape(_param, _param_complex, multiparamtype,
                           dummyinstrument, 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)

    results = do0d(arrayparam,
                   multiparam,
                   paramwsetpoints,
                   _param,
                   _param_complex,
                   do_plot=False)
    expected_shapes = {}
    for i, name in enumerate(multiparam.full_names):
        expected_shapes[name] = tuple(multiparam.shapes[i])
    expected_shapes['arrayparam'] = tuple(arrayparam.shape)
    expected_shapes['simple_parameter'] = (1, )
    expected_shapes['simple_complex_parameter'] = (1, )
    expected_shapes[paramwsetpoints.full_name] = (n_points_pws, )
    assert results[0].description.shapes == expected_shapes

    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]
Example #5
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
Example #6
0
def array_in_str_dataset(experiment, request):
    meas = Measurement()
    scalar_param = Parameter('textparam', set_cmd=None)
    param = ArraySetPointParam()
    meas.register_parameter(scalar_param, paramtype='text')
    meas.register_parameter(param, setpoints=(scalar_param,),
                            paramtype=request.param)

    with meas.run() as datasaver:
        for i in ['A', 'B', 'C']:
            scalar_param.set(i)
            datasaver.add_result((scalar_param, scalar_param.get()),
                                 (param, param.get()))
    try:
        yield datasaver.dataset
    finally:
        datasaver.dataset.conn.close()
Example #7
0
def array_in_scalar_dataset_unrolled(experiment):
    meas = Measurement()
    scalar_param = Parameter('scalarparam', set_cmd=None)
    param = ArraySetPointParam()
    meas.register_parameter(scalar_param)
    meas.register_parameter(param, setpoints=(scalar_param,),
                            paramtype='numeric')

    with meas.run() as datasaver:
        for i in range(1, 10):
            scalar_param.set(i)
            datasaver.add_result((scalar_param, scalar_param.get()),
                                 (param, param.get()))
    try:
        yield datasaver.dataset
    finally:
        datasaver.dataset.conn.close()
Example #8
0
def varlen_array_in_scalar_dataset(experiment):
    meas = Measurement()
    scalar_param = Parameter('scalarparam', set_cmd=None)
    param = ArraySetPointParam()
    meas.register_parameter(scalar_param)
    meas.register_parameter(param, setpoints=(scalar_param,),
                            paramtype='array')
    np.random.seed(0)
    with meas.run() as datasaver:
        for i in range(1, 10):
            scalar_param.set(i)
            param.setpoints = (np.arange(i),)
            datasaver.add_result((scalar_param, scalar_param.get()),
                                 (param, np.random.rand(i)))
    try:
        yield datasaver.dataset
    finally:
        datasaver.dataset.conn.close()
Example #9
0
def test_do2d_verify_shape(_param, _param_complex, _param_set, _param_set_2,
                           multiparamtype, dummyinstrument, sweep, columns,
                           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

    start_p2 = 0.1
    stop_p2 = 1.1
    delay_p2 = 0

    results = do2d(_param_set,
                   start_p1,
                   stop_p1,
                   num_points_p1,
                   delay_p1,
                   _param_set_2,
                   start_p2,
                   stop_p2,
                   num_points_p2,
                   delay_p2,
                   arrayparam,
                   multiparam,
                   paramwsetpoints,
                   _param,
                   _param_complex,
                   set_before_sweep=sweep,
                   flush_columns=columns,
                   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]
Example #10
0
def test_dond_0d_with_real_parameter(period, plot, plot_config):
    arrayparam = ArraySetPointParam(name="arrayparam")

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

    output = dond(arrayparam, write_period=period, 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
Example #11
0
def test_log_sweep_parameter_class(_param, _param_complex):
    start = 0
    stop = 1
    num_points = 5
    delay = 1
    sweep = LogSweep(_param, start, stop, num_points, delay)
    assert isinstance(sweep.param, _BaseParameter)

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

    arrayparam = ArraySetPointParam(name="arrayparam")
    sweep_3 = LogSweep(arrayparam, start, stop, num_points)
    assert isinstance(sweep_3.param, _BaseParameter)
Example #12
0
def array_in_scalar_dataset_unrolled(experiment):
    """
    This fixture yields a dataset where an array-valued parameter is registered
    as a 'numeric' type and has an additional single-valued setpoint. We
    expect data to be saved as individual scalars, with the scalar setpoint
    repeated.
    """
    meas = Measurement()
    scalar_param = Parameter('scalarparam', set_cmd=None)
    param = ArraySetPointParam()
    meas.register_parameter(scalar_param)
    meas.register_parameter(param,
                            setpoints=(scalar_param, ),
                            paramtype='numeric')

    with meas.run() as datasaver:
        for i in range(1, 10):
            scalar_param.set(i)
            datasaver.add_result((scalar_param, scalar_param.get()),
                                 (param, param.get()))
    try:
        yield datasaver.dataset
    finally:
        datasaver.dataset.conn.close()
Example #13
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
Example #14
0
def test_get_shape_for_array_parameter_from_shape(loop_shape, range_func):
    a = ArraySetPointParam(name='a')
    loop_sequence = tuple(range_func(x) for x in loop_shape)
    shape = detect_shape_of_measurement((a, ), loop_sequence)
    expected_shape = tuple(loop_shape) + tuple(a.shape)
    assert shape == {'a': expected_shape}
Example #15
0
def test_get_shape_for_array_parameter_from_len(loop_shape):
    a = ArraySetPointParam(name='a')
    shape = detect_shape_of_measurement((a, ), loop_shape)
    expected_shape = tuple(loop_shape) + tuple(a.shape)
    assert shape == {'a': expected_shape}
Example #16
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]