示例#1
0
def test_interleave_1d_2d(indep_params, dep_params):
    px, x, tablex = indep_params["x"]
    py, y, tabley = indep_params["y"]

    pi, i, tablei = dep_params["i"]
    pj, j, tablej = dep_params["j"]

    def f(vx):
        return vx**2

    pi.get = lambda: f(px())

    def g(vx, vy):
        return vx**2 + vy**2

    pj.get = lambda: g(px(), py())

    sweep_values_x = [0, 1, 2]
    sweep_values_y = [4, 5, 6]

    sweep_object = Nest(
        Sweep(x, tablex, lambda: sweep_values_x),
        Chain(
            Measure(i, tablei),
            Nest(Sweep(y, tabley, lambda: sweep_values_y), Measure(j,
                                                                   tablej))))

    for xvalue in sweep_values_x:
        assert next(sweep_object) == {"x": xvalue, "i": f(xvalue)}
        for yvalue in sweep_values_y:
            assert next(sweep_object) == {
                "x": xvalue,
                "y": yvalue,
                "j": g(xvalue, yvalue)
            }
示例#2
0
def test_error_no_nest_in_chain_2(indep_params, dep_params):
    px, x, tablex = indep_params["x"]
    pi, i, tablei = dep_params["i"]
    pj, j, tablej = dep_params["j"]

    sweep_values = [0, 1, 2]

    sweep_object = Nest(Sweep(x, tablex, lambda: sweep_values),
                        Chain(Measure(i, tablei)))

    with pytest.raises(TypeError):
        Nest(sweep_object, Measure(j, tablej))
示例#3
0
def test_nest_3d(indep_params, dep_params):
    px, x, tablex = indep_params["x"]
    py, y, tabley = indep_params["y"]
    pz, z, tablez = indep_params["z"]

    def f(vx, vy, vz):
        return vx**2 + vy**2 + vz**2

    pi, i, tablei = dep_params["i"]
    pi.get = lambda: f(px(), py(), pz())

    sweep_values_x = [0, 1, 2]
    sweep_values_y = [5, 6, 7]
    sweep_values_z = [8, 9, 10]

    nest = Nest(Sweep(x, tablex, lambda: sweep_values_x),
                Sweep(y, tabley, lambda: sweep_values_y),
                Sweep(z, tablez, lambda: sweep_values_z), Measure(i, tablei))

    assert list(nest) == [{
        "x": xval,
        "y": yval,
        "z": zval,
        "i": f(xval, yval, zval)
    }
                          for xval, yval, zval in itertools.product(
                              sweep_values_x, sweep_values_y, sweep_values_z)]
示例#4
0
def measure(fun_or_param, paramtype: str = None):

    if isinstance(fun_or_param, Parameter):
        fun = parameter_getter(fun_or_param, paramtype=paramtype)
    elif isinstance(fun_or_param, MeasureFunction):
        fun = fun_or_param
    else:
        raise ValueError("Can only measure a QCoDeS parameter or a function "
                         "decorated with pytopo.getter")

    return Measure(fun, fun.parameter_table)
示例#5
0
def test_error_no_nest_in_chain(indep_params, dep_params):
    px, x, tablex = indep_params["x"]
    py, y, tabley = indep_params["y"]

    pi, i, tablei = dep_params["i"]

    sweep_values_x = [0, 1, 2]
    sweep_values_y = [4, 5, 6]

    with pytest.raises(TypeError):
        Nest(
            Chain(Sweep(x, tablex, lambda: sweep_values_x),
                  Sweep(y, tabley, lambda: sweep_values_y)),
            Measure(i, tablei))
示例#6
0
def test_nest(indep_params, dep_params):

    px, x, tablex = indep_params["x"]
    pi, i, tablei = dep_params["i"]

    def f(value):
        return value**2

    pi.get = lambda: f(px())

    sweep_values = [0, 1, 2]

    nest = Nest(Sweep(x, tablex, lambda: sweep_values), Measure(i, tablei))

    assert list(nest) == [{"x": xval, "i": f(xval)} for xval in sweep_values]
示例#7
0
def test_error_no_nest_in_measurable(indep_params, dep_params):
    px, x, tablex = indep_params["x"]
    pi, i, tablei = dep_params["i"]

    with pytest.raises(TypeError):
        Nest(Measure(i, tablei), Sweep(x, tablex, lambda: []))