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 @@ -87,6 +87,7 @@
create_noiseless_virtual_engine_from_proto as create_noiseless_virtual_engine_from_proto,
create_noiseless_virtual_engine_from_templates as create_noiseless_virtual_engine_from_templates,
create_noiseless_virtual_engine_from_latest_templates as create_noiseless_virtual_engine_from_latest_templates,
load_device_noise_properties as load_device_noise_properties,
load_median_device_calibration as load_median_device_calibration,
load_sample_device_zphase as load_sample_device_zphase,
)
Expand Down
21 changes: 21 additions & 0 deletions cirq-google/cirq_google/engine/virtual_engine_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,27 @@ def _create_perfect_calibration(device: cirq.Device) -> calibration.Calibration:
return calibration.Calibration(calibration=snapshot, metrics=all_metrics)


def load_device_noise_properties(processor_id: str) -> cirq_google.GoogleNoiseProperties:
"""Loads NoiseProperties for the given device.

This combines calibration data for the device with gate times from its specification, and
the Z phases data, if available, to construct NoiseProperties for device simulation.

Args:
processor_id: name of the processor to simulate.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we either specify valid processor names or tell where to find them?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, there seems to be no public API to get those names apart from reading the code. I will add a list_virtual_processors function in next PR.


Raises:
ValueError: if processor_id is not a supported QCS processor.
"""
device = create_device_from_processor_id(processor_id)
calibration = load_median_device_calibration(processor_id)
zphase_data = load_sample_device_zphase(processor_id) if processor_id in ZPHASE_DATA else None
gate_times_ns = extract_gate_times_ns_from_device(device)
return noise_properties_from_calibration(
calibration=calibration, zphase_data=zphase_data, gate_times_ns=gate_times_ns
)


def load_median_device_calibration(processor_id: str) -> calibration.Calibration:
"""Loads a median `cirq_google.Calibration` for the given device.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ def test_create_from_device():
_test_processor(engine.get_processor('sycamore'))


def test_load_device_noise_properties() -> None:
noise_properties = factory.load_device_noise_properties("rainbow")
assert noise_properties.readout_errors[cirq.GridQubit(9, 4)] == [0.0124, 0.0464]
assert noise_properties.gate_times_ns[cirq.PhasedXZGate] == 25
op_id = cirq.OpIdentifier(cirq.ISwapPowGate, cirq.GridQubit(3, 2), cirq.GridQubit(4, 2))
assert noise_properties.fsim_errors[op_id].zeta == -0.004952147720840733
assert noise_properties.fsim_errors[op_id].gamma == -0.04094895320428251


def test_median_rainbow_device():
q0, q1 = cirq.GridQubit.rect(1, 2, 5, 3)
cal = factory.load_median_device_calibration('rainbow')
Expand Down