Skip to content

Commit b0a1751

Browse files
authored
Add list_virtual_processors function to the QVM factory (quantumlib#7375)
Convenience function to get the valid `processor_id` strings for QVM factories. Follow-up to quantumlib#7369
1 parent 66b3d71 commit b0a1751

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

cirq-google/cirq_google/engine/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
create_noiseless_virtual_engine_from_proto as create_noiseless_virtual_engine_from_proto,
8888
create_noiseless_virtual_engine_from_templates as create_noiseless_virtual_engine_from_templates,
8989
create_noiseless_virtual_engine_from_latest_templates as create_noiseless_virtual_engine_from_latest_templates,
90+
list_virtual_processors as list_virtual_processors,
9091
load_device_noise_properties as load_device_noise_properties,
9192
load_median_device_calibration as load_median_device_calibration,
9293
load_sample_device_zphase as load_sample_device_zphase,

cirq-google/cirq_google/engine/virtual_engine_factory.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def load_device_noise_properties(processor_id: str) -> cirq_google.GoogleNoisePr
116116
117117
Args:
118118
processor_id: name of the processor to simulate.
119+
Use `list_virtual_processors` to obtain available names.
119120
120121
Raises:
121122
ValueError: if processor_id is not a supported QCS processor.
@@ -141,6 +142,7 @@ def load_median_device_calibration(processor_id: str) -> calibration.Calibration
141142
142143
Args:
143144
processor_id: name of the processor to simulate.
145+
Use `list_virtual_processors` to obtain available names.
144146
145147
Raises:
146148
ValueError: if processor_id is not a supported QCS processor.
@@ -234,9 +236,8 @@ def create_noiseless_virtual_engine_from_device(
234236
a default validator, and a provided device.
235237
236238
Args:
237-
processor_id: name of the processor to simulate. This is an arbitrary
238-
string identifier and does not have to match the processor's name
239-
in QCS.
239+
processor_id: name of the virtual processor to simulate.
240+
Use `list_virtual_processors` to obtain available names.
240241
device: A `cirq.Device` to validate circuits against.
241242
device_specification: a` DeviceSpecification` proto that the processor
242243
should return if `get_device_specification()` is queried.
@@ -255,9 +256,8 @@ def create_noiseless_virtual_processor_from_proto(
255256
and can be retrieved from a stored "proto.txt" file or from the QCS API.
256257
257258
Args:
258-
processor_id: name of the processor to simulate. This is an arbitrary
259-
string identifier and does not have to match the processor's name
260-
in QCS.
259+
processor_id: name of the processor to simulate.
260+
Use `list_virtual_processors` to obtain available names.
261261
device_specification: `v2.device_pb2.DeviceSpecification` proto to create
262262
a validating device from.
263263
gate_sets: Iterable of serializers to use in the processor.
@@ -283,6 +283,7 @@ def create_noiseless_virtual_engine_from_proto(
283283
processor_ids: names of the processors to simulate. These are arbitrary
284284
string identifiers and do not have to match the processors' names
285285
in QCS. This can be a single string or list of strings.
286+
Use `list_virtual_processors` to obtain recognized names.
286287
device_specifications: `v2.device_pb2.DeviceSpecification` proto to create
287288
validating devices from. This can be a single DeviceSpecification
288289
or a list of them. There should be one DeviceSpecification for each
@@ -323,6 +324,7 @@ def create_device_spec_from_processor_id(processor_id: str) -> v2.device_pb2.Dev
323324
324325
Args:
325326
processor_id: name of the processor to simulate.
327+
Use `list_virtual_processors` to obtain available names.
326328
327329
Raises:
328330
ValueError: if processor_id is not a supported QCS processor.
@@ -338,6 +340,7 @@ def create_device_from_processor_id(processor_id: str) -> grid_device.GridDevice
338340
339341
Args:
340342
processor_id: name of the processor to simulate.
343+
Use `list_virtual_processors` to obtain available names.
341344
342345
Raises:
343346
ValueError: if processor_id is not a supported QCS processor.
@@ -352,9 +355,8 @@ def create_noiseless_virtual_processor_from_template(
352355
"""Creates a simulated local processor from a device specification template.
353356
354357
Args:
355-
processor_id: name of the processor to simulate. This is an arbitrary
356-
string identifier and does not have to match the processor's name
357-
in QCS.
358+
processor_id: name of the processor to simulate.
359+
Use `list_virtual_processors` to obtain available names.
358360
template_name: File name of the device specification template, see
359361
cirq_google/devices/specifications for valid templates.
360362
gate_sets: Iterable of serializers to use in the processor.
@@ -373,7 +375,7 @@ def create_noiseless_virtual_engine_from_templates(
373375
processor_ids: names of the processors to simulate. These are arbitrary
374376
string identifiers and do not have to match the processors' names
375377
in QCS. There can be a single string or a list of strings for multiple
376-
processors.
378+
processors. Use `list_virtual_processors` to obtain recognized names.
377379
template_names: File names of the device specification templates, see
378380
cirq_google/devices/specifications for valid templates. There can
379381
be a single str for a template name or a list of strings. Each
@@ -421,6 +423,7 @@ def create_default_noisy_quantum_virtual_machine(
421423
422424
Args:
423425
processor_id: The string name of a processor that has available noise data.
426+
Use `list_virtual_processors` to obtain available names.
424427
simulator_class: The class of the type of simulator to be initialized. The
425428
simulator class initializer needs to support the `noise` parameter.
426429
**kwargs: Other arguments which are passed through to the simulator initializer.
@@ -495,3 +498,11 @@ def extract_gate_times_ns_from_device(
495498
# cirq.WaitGate has variable duration and should not be included here.
496499
_ = gate_times_ns.pop(cirq.WaitGate, None)
497500
return gate_times_ns
501+
502+
503+
def list_virtual_processors() -> list[str]:
504+
"""Return a sorted list of known virtual processor names.
505+
506+
These are accepted for the ``processor_id`` argument in factory functions.
507+
"""
508+
return sorted(MOST_RECENT_TEMPLATES.keys())

cirq-google/cirq_google/engine/virtual_engine_factory_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,7 @@ def test_extract_gate_times_ns_from_device_without_durations() -> None:
267267
)
268268
device_without_durations = cg.GridDevice(metadata_without_durations)
269269
assert factory.extract_gate_times_ns_from_device(device_without_durations) == {}
270+
271+
272+
def test_list_virtual_processors() -> None:
273+
assert factory.list_virtual_processors() == ['rainbow', 'weber', 'willow_pink']

0 commit comments

Comments
 (0)