Beispiel #1
0
 def engine(self):
     if self._engine is None:
         project_id = os.environ['GOOGLE_CLOUD_PROJECT']
         engine = cg_engine.Engine(project_id=project_id,
                                   proto_version=cg_engine.ProtoVersion.V2)
         self._engine = engine
     return self._engine
Beispiel #2
0
def get_engine_sampler(processor_id: str, gate_set_name: str,
                       project_id: Optional[str] = None) \
        -> 'cirq.google.QuantumEngineSampler':
    """Get an EngineSampler assuming some sensible defaults.

    This uses the environment variable GOOGLE_GLOUD_PROJECT for the Engine
    project_id, unless set explicitly.

    Args:
        processor_id: Engine processor ID (from Cloud console or
            ``Engine.list_processors``).
        gate_set_name: One of ['sqrt_iswap', 'sycamore'].
            See `cirq.google.NAMED_GATESETS`.
        project_id: Optional explicit Google Cloud project id. Otherwise,
            this defaults to the environment variable GOOGLE_CLOUD_PROJECT.
            By using an environment variable, you can avoid hard-coding
            personal project IDs in shared code.
    """
    try:
        gate_set = gate_sets.NAMED_GATESETS[gate_set_name]
    except KeyError:
        raise ValueError(f"Please use one of the following gateset names: "
                         f"{sorted(gate_sets.NAMED_GATESETS.keys())}")

    if project_id is None:
        project_id = os.environ['GOOGLE_CLOUD_PROJECT']

    return engine.Engine(project_id=project_id,
                         proto_version=engine.ProtoVersion.V2) \
        .sampler(processor_id=processor_id, gate_set=gate_set)
Beispiel #3
0
 def __init__(self, processor_id: str, gateset: str):
     project_id = os.environ['GOOGLE_CLOUD_PROJECT']
     engine = cg_engine.Engine(project_id=project_id,
                               proto_version=cg_engine.ProtoVersion.V2)
     self.engine = engine
     self.processor_id = processor_id
     if gateset == 'sycamore':
         self.gate_set = gate_sets.SYC_GATESET
     elif gateset == 'sqrt-iswap':
         self.gate_set = gate_sets.SQRT_ISWAP_GATESET
     else:
         raise ValueError("Unknown gateset {}".format(gateset))