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