From 7e62a15dc2565ae05d1fa13b70179b9eb871bf67 Mon Sep 17 00:00:00 2001 From: Cheng Xing Date: Thu, 23 Jun 2022 22:50:36 +0000 Subject: [PATCH] Temporary GridDevice.qubits property --- cirq-google/cirq_google/devices/grid_device.py | 9 +++++++++ cirq-google/cirq_google/devices/grid_device_test.py | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/cirq-google/cirq_google/devices/grid_device.py b/cirq-google/cirq_google/devices/grid_device.py index 5f34882f6fa5..87fbcbef3cae 100644 --- a/cirq-google/cirq_google/devices/grid_device.py +++ b/cirq-google/cirq_google/devices/grid_device.py @@ -305,6 +305,15 @@ def metadata(self) -> cirq.GridDeviceMetadata: """Get metadata information for the device.""" return self._metadata + # Some user code using SerializableDevices gets the qubit list via `device.qubits`. + # This is a stopgap solution to prevent user breakage with the change to GridDevice. + @property + @cirq._compat.deprecated( + deadline='v0.16', fix='Change `device.qubits` to `device.metadata.qubit_set`.' + ) + def qubits(self) -> List[cirq.Qid]: + return list(self._metadata.qubit_set) + def validate_operation(self, operation: cirq.Operation) -> None: """Raises an exception if an operation is not valid. diff --git a/cirq-google/cirq_google/devices/grid_device_test.py b/cirq-google/cirq_google/devices/grid_device_test.py index c2f645d72706..8d55635e45ac 100644 --- a/cirq-google/cirq_google/devices/grid_device_test.py +++ b/cirq-google/cirq_google/devices/grid_device_test.py @@ -517,3 +517,11 @@ def test_to_proto_empty(): assert len(device.metadata.qubit_pairs) == 0 assert device.metadata.gateset == cirq.Gateset() assert device.metadata.gate_durations is None + + +def test_grid_device_qubits(): + _, spec = _create_device_spec_with_horizontal_couplings() + device = cirq_google.GridDevice.from_proto(spec) + + with cirq.testing.assert_deprecated('device.qubits', deadline='v0.16'): + assert frozenset(device.qubits) == device.metadata.qubit_set