Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cirq-google/cirq_google/engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
from cirq_google.engine.validating_sampler import ValidatingSampler

from cirq_google.engine.virtual_engine_factory import (
create_device_from_processor_id,
create_noiseless_virtual_engine_from_device,
create_noiseless_virtual_engine_from_proto,
create_noiseless_virtual_engine_from_templates,
Expand Down
16 changes: 16 additions & 0 deletions cirq-google/cirq_google/engine/virtual_engine_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,22 @@ def _create_device_spec_from_template(template_name: str) -> v2.device_pb2.Devic
return device_spec


def create_device_from_processor_id(processor_id: str) -> serializable_device.SerializableDevice:
"""Generates a `cirq_google.SerializableDevice` for a given processor ID.

Args:
processor_id: name of the processor to simulate.

Raises:
ValueError: if processor_id is not a supported QCS processor.
"""
template_name = MOST_RECENT_TEMPLATES.get(processor_id, None)
if template_name is None:
raise ValueError(f"Got processor_id={processor_id}, but no such processor is defined.")
device_specification = _create_device_spec_from_template(template_name)
return serializable_device.SerializableDevice.from_proto(device_specification, [FSIM_GATESET])


def create_noiseless_virtual_processor_from_template(
processor_id: str,
template_name: str,
Expand Down
8 changes: 8 additions & 0 deletions cirq-google/cirq_google/engine/virtual_engine_factory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def _test_processor(processor: cg.engine.abstract_processor.AbstractProcessor):
_ = processor.run(circuit, repetitions=100)


def test_create_device_from_processor_id():
device = factory.create_device_from_processor_id('rainbow')
assert device is not None

with pytest.raises(ValueError, match='no such processor is defined'):
_ = factory.create_device_from_processor_id('bad_processor')


def test_create_from_device():
engine = factory.create_noiseless_virtual_engine_from_device('sycamore', cg.Sycamore)
_test_processor(engine.get_processor('sycamore'))
Expand Down