コード例 #1
0
 def _deserialize_run_context(run_context: quantum.types.any_pb2.Any
                             ) -> Tuple[int, List[study.Sweep]]:
     import cirq.google.engine.engine as engine_base
     run_context_type = run_context.type_url[len(engine_base.TYPE_PREFIX):]
     if (run_context_type == 'cirq.google.api.v1.RunContext' or
             run_context_type == 'cirq.api.google.v1.RunContext'):
         raise ValueError('deserializing a v1 RunContext is not supported')
     if (run_context_type == 'cirq.google.api.v2.RunContext' or
             run_context_type == 'cirq.api.google.v2.RunContext'):
         v2_run_context = v2.run_context_pb2.RunContext.FromString(
             run_context.value)
         return v2_run_context.parameter_sweeps[0].repetitions, [
             v2.sweep_from_proto(s.sweep)
             for s in v2_run_context.parameter_sweeps
         ]
     raise ValueError(
         'unsupported run_context type: {}'.format(run_context_type))
コード例 #2
0
def test_sweep_from_proto_single_sweep_type_not_set():
    proto = run_context_pb2.Sweep()
    proto.single_sweep.parameter_key = 'foo'
    with pytest.raises(ValueError, match='single sweep type not set'):
        v2.sweep_from_proto(proto)
コード例 #3
0
def test_sweep_from_proto_sweep_function_not_set():
    proto = run_context_pb2.Sweep()
    proto.sweep_function.sweeps.add()
    with pytest.raises(ValueError, match='invalid sweep function type'):
        v2.sweep_from_proto(proto)
コード例 #4
0
def test_sweep_to_proto_roundtrip(sweep):
    msg = v2.sweep_to_proto(sweep)
    deserialized = v2.sweep_from_proto(msg)
    assert deserialized == sweep