Beispiel #1
0
def test_gen_sweep_points():
    points = [0.5, 1.0, 1.5, 2.0, 2.5]
    sweep = SingleSweep()
    sweep.parameter_key = 'foo'
    sweep.points.points.extend(points)
    out = params._sweep_from_single_param_sweep(sweep)
    assert out == Points('foo', [0.5, 1.0, 1.5, 2.0, 2.5])
Beispiel #2
0
def test_gen_sweep_linspace():
    sweep = SingleSweep()
    sweep.parameter_key = 'bar'
    sweep.linspace.first_point = 0
    sweep.linspace.last_point = 10
    sweep.linspace.num_points = 11
    out = params._sweep_from_single_param_sweep(sweep)
    assert out == Linspace('bar', 0, 10, 11)
Beispiel #3
0
def _single_param_sweep_to_proto(
        sweep: SingleSweep,
        msg: params_pb2.SingleSweep = None) -> params_pb2.SingleSweep:
    if msg is None:
        msg = params_pb2.SingleSweep()
    if isinstance(sweep, Linspace):
        msg.parameter_key = sweep.key
        msg.linspace.first_point = sweep.start
        msg.linspace.last_point = sweep.stop
        msg.linspace.num_points = sweep.length
    elif isinstance(sweep, Points):
        msg.parameter_key = sweep.key
        msg.points.points.extend(sweep.points)
    else:
        raise ValueError('invalid single-parameter sweep: {}'.format(sweep))
    return msg
Beispiel #4
0
def _single_param_sweep_to_proto(
        sweep: SingleSweep,
        msg: params_pb2.SingleSweep = None
) -> params_pb2.SingleSweep:
    if msg is None:
        msg = params_pb2.SingleSweep()
    if isinstance(sweep, Linspace):
        msg.parameter_key = sweep.key
        msg.linspace.first_point = sweep.start
        msg.linspace.last_point = sweep.stop
        msg.linspace.num_points = sweep.length
    elif isinstance(sweep, Points):
        msg.parameter_key = sweep.key
        msg.points.points.extend(sweep.points)
    else:
        raise ValueError('invalid single-parameter sweep: {}'.format(sweep))
    return msg
Beispiel #5
0
def _sweep_from_single_param_sweep(
        single_param_sweep: params_pb2.SingleSweep) -> Sweep:
    key = single_param_sweep.parameter_key
    which = single_param_sweep.WhichOneof('sweep')
    if which == 'points':
        sp = single_param_sweep.points
        return Points(key, list(sp.points))
    elif which == 'linspace':
        sl = single_param_sweep.linspace
        return Linspace(key, sl.first_point, sl.last_point, sl.num_points)
    else:
        raise ValueError('unknown single param sweep type: {}'.format(which))