Skip to content

Deprecate SerializableDevice #5522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
54 changes: 29 additions & 25 deletions cirq-google/cirq_google/devices/grid_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,33 +459,37 @@ def test_to_proto_backward_compatibility():
out=spec,
)

# Deserialize both ways
serializable_dev = cirq_google.SerializableDevice.from_proto(spec, [cirq_google.FSIM_GATESET])
grid_dev = cirq_google.GridDevice.from_proto(spec)

assert serializable_dev.metadata.qubit_set == grid_dev.metadata.qubit_set
assert serializable_dev.metadata.qubit_pairs == grid_dev.metadata.qubit_pairs

assert serializable_dev.metadata.gateset == cirq.Gateset(
cirq.FSimGate,
cirq.ISwapPowGate,
cirq.CZPowGate,
cirq.PhasedXPowGate,
cirq.XPowGate,
cirq.YPowGate,
cirq.ZPowGate,
cirq.PhasedXZGate,
cirq.MeasurementGate,
cirq.WaitGate,
cirq.GlobalPhaseGate,
)
with cirq.testing.assert_deprecated('Use cirq_google.GridDevice', deadline='v0.16', count=None):
# Deserialize both ways
serializable_dev = cirq_google.SerializableDevice.from_proto(
spec, [cirq_google.FSIM_GATESET]
)
grid_dev = cirq_google.GridDevice.from_proto(spec)

assert serializable_dev.metadata.qubit_set == grid_dev.metadata.qubit_set
assert serializable_dev.metadata.qubit_pairs == grid_dev.metadata.qubit_pairs

assert serializable_dev.metadata.gateset == cirq.Gateset(
cirq.FSimGate,
cirq.ISwapPowGate,
cirq.CZPowGate,
cirq.PhasedXPowGate,
cirq.XPowGate,
cirq.YPowGate,
cirq.ZPowGate,
cirq.PhasedXZGate,
cirq.MeasurementGate,
cirq.WaitGate,
cirq.GlobalPhaseGate,
)

assert grid_dev.metadata.gateset == device_info.expected_gateset
assert (
tuple(grid_dev.metadata.compilation_target_gatesets) == device_info.expected_target_gatesets
)
assert grid_dev.metadata.gateset == device_info.expected_gateset
assert (
tuple(grid_dev.metadata.compilation_target_gatesets)
== device_info.expected_target_gatesets
)

assert grid_dev.metadata.gate_durations == device_info.expected_gate_durations
assert grid_dev.metadata.gate_durations == device_info.expected_gate_durations


def test_to_proto_empty():
Expand Down
18 changes: 15 additions & 3 deletions cirq-google/cirq_google/devices/known_devices_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ def test_multiple_gate_sets():


def test_sycamore_circuitop_device():
with cirq.testing.assert_deprecated('no longer be available', deadline='v0.16', count=1):
# Deprecations: cirq_google.SerializableDevice and
# cirq_google.devices.known_devices.create_device_proto_from_diagram
with cirq.testing.assert_deprecated(
'Use cirq_google.GridDevice', 'no longer be available', deadline='v0.16', count=3
):
circuitop_gateset = cirq_google.SerializableGateSet(
gate_set_name='circuitop_gateset',
serializers=[cgc.CIRCUIT_OP_SERIALIZER],
Expand Down Expand Up @@ -316,7 +320,11 @@ def test_proto_with_circuitop():


def test_proto_with_waitgate():
with cirq.testing.assert_deprecated('no longer be available', deadline='v0.16', count=1):
# Deprecations: cirq_google.SerializableDevice and
# cirq_google.devices.known_devices.create_device_proto_from_diagram
with cirq.testing.assert_deprecated(
'Use cirq_google.GridDevice', 'no longer be available', deadline='v0.16', count=3
):
wait_gateset = cirq_google.SerializableGateSet(
gate_set_name='wait_gateset',
serializers=[cgc.WAIT_GATE_SERIALIZER],
Expand Down Expand Up @@ -379,7 +387,11 @@ def test_proto_with_waitgate():


def test_adding_gates_multiple_times():
with cirq.testing.assert_deprecated('no longer be available', deadline='v0.16', count=1):
# Deprecations: cirq_google.SerializableDevice and
# cirq_google.devices.known_devices.create_device_proto_from_diagram
with cirq.testing.assert_deprecated(
'Use cirq_google.GridDevice', 'no longer be available', deadline='v0.16', count=3
):
waiting_for_godot = cirq_google.SerializableGateSet(
gate_set_name='wait_gateset',
serializers=[
Expand Down
7 changes: 7 additions & 0 deletions cirq-google/cirq_google/devices/serializable_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from typing import Any, Callable, cast, Dict, Iterable, List, Optional, Set, Tuple, Type, Union
import cirq
from cirq import _compat
from cirq_google.serialization import serializable_gate_set
from cirq_google.api import v2

Expand Down Expand Up @@ -66,6 +67,7 @@ def __eq__(self, other):
_GateOrFrozenCircuitTypes = Union[Type[cirq.Gate], Type[cirq.FrozenCircuit]]


@_compat.deprecated_class(deadline='v0.16', fix='Use cirq_google.GridDevice instead.')
class SerializableDevice(cirq.Device):
"""Device object generated from a device specification proto.

Expand Down Expand Up @@ -122,6 +124,11 @@ def metadata(self) -> cirq.GridDeviceMetadata:
return self._metadata

@classmethod
@_compat.deprecated(
deadline='v0.16',
fix='cirq_google.SerializableDevice is replaced cirq_google.GridDevice.'
' Use cirq_google.GridDevice.from_proto() instead.',
)
def from_proto(
cls,
proto: v2.device_pb2.DeviceSpecification,
Expand Down
Loading