From cc5246fab68f716e667e24f1d5ef725f4f35e282 Mon Sep 17 00:00:00 2001 From: Cheng Xing Date: Wed, 15 Jun 2022 00:57:05 +0000 Subject: [PATCH] Add deprecation context in tests that use SerializableDevice --- .../cirq_google/devices/grid_device_test.py | 54 ++++++++++--------- .../cirq_google/devices/known_devices_test.py | 18 +++++-- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/cirq-google/cirq_google/devices/grid_device_test.py b/cirq-google/cirq_google/devices/grid_device_test.py index bc0678447c2..7f9822a3b3d 100644 --- a/cirq-google/cirq_google/devices/grid_device_test.py +++ b/cirq-google/cirq_google/devices/grid_device_test.py @@ -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(): diff --git a/cirq-google/cirq_google/devices/known_devices_test.py b/cirq-google/cirq_google/devices/known_devices_test.py index 37aee656cb9..7f13f6caa97 100644 --- a/cirq-google/cirq_google/devices/known_devices_test.py +++ b/cirq-google/cirq_google/devices/known_devices_test.py @@ -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], @@ -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], @@ -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=[