Esempio n. 1
0
def example_sweeps():
    empty_sweep = params_pb2.ParameterSweep()
    empty_product = params_pb2.ParameterSweep(sweep=params_pb2.ProductSweep())
    empty_zip = params_pb2.ParameterSweep(sweep=params_pb2.ProductSweep(
        factors=[params_pb2.ZipSweep(),
                 params_pb2.ZipSweep()]))
    full_sweep = params_pb2.ParameterSweep(sweep=params_pb2.ProductSweep(
        factors=[
            params_pb2.ZipSweep(sweeps=[
                params_pb2.SingleSweep(
                    parameter_key='11',
                    linspace=params_pb2.Linspace(
                        first_point=0, last_point=10, num_points=5)),
                params_pb2.SingleSweep(parameter_key='12',
                                       points=params_pb2.Points(
                                           points=range(7)))
            ]),
            params_pb2.ZipSweep(sweeps=[
                params_pb2.SingleSweep(
                    parameter_key='21',
                    linspace=params_pb2.Linspace(
                        first_point=0, last_point=10, num_points=11)),
                params_pb2.SingleSweep(parameter_key='22',
                                       points=params_pb2.Points(
                                           points=range(13)))
            ])
        ]))
    return [empty_sweep, empty_product, empty_zip, full_sweep]
Esempio n. 2
0
def test_gen_sweep_linspace():
    sweep = params_pb2.SingleSweep(parameter_key='foo',
                                   linspace=params_pb2.Linspace(first_point=0,
                                                                last_point=10,
                                                                num_points=11))
    out = params._sweep_from_single_param_sweep_proto(sweep)
    assert out == cirq.Linspace('foo', 0, 10, 11)
Esempio n. 3
0
def test_param_sweep_size():
    ps = params_pb2.ParameterSweep(sweep=params_pb2.ProductSweep(factors=[
        params_pb2.ZipSweep(sweeps=[
            params_pb2.SingleSweep(parameter_key='11',
                                   linspace=params_pb2.Linspace(first_point=0,
                                                                last_point=10,
                                                                num_points=5)),
            params_pb2.SingleSweep(parameter_key='12',
                                   points=params_pb2.Points(points=range(7)))
        ]),
        params_pb2.ZipSweep(sweeps=[
            params_pb2.SingleSweep(
                parameter_key='21',
                linspace=params_pb2.Linspace(
                    first_point=0, last_point=10, num_points=11)),
            params_pb2.SingleSweep(parameter_key='22',
                                   points=params_pb2.Points(points=range(13)))
        ])
    ]))
    # Sweeps sx1 and sx2 are zipped, so should use num number of points.
    # These are then producted, so this should multiply number of points.
    assert len(params.sweep_from_proto(ps)) == 5 * 11
Esempio n. 4
0
def _single_param_sweep_to_proto(
        sweep: sweeps.SingleSweep) -> params_pb2.SingleSweep:
    if isinstance(sweep, sweeps.Linspace):
        return params_pb2.SingleSweep(parameter_key=sweep.key,
                                      linspace=params_pb2.Linspace(
                                          first_point=sweep.start,
                                          last_point=sweep.stop,
                                          num_points=sweep.length))
    elif isinstance(sweep, sweeps.Points):
        return params_pb2.SingleSweep(
            parameter_key=sweep.key,
            points=params_pb2.Points(points=sweep.points))
    else:
        raise ValueError('invalid single-parameter sweep: {}'.format(sweep))