From 9164316374379588d5e8b812d3f522384a42797e Mon Sep 17 00:00:00 2001 From: Cheng Xing Date: Thu, 23 Jun 2022 22:51:48 +0000 Subject: [PATCH 1/3] 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 5f34882f6fa..87fbcbef3ca 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 547e9d03ce5..9e3dd9d7ede 100644 --- a/cirq-google/cirq_google/devices/grid_device_test.py +++ b/cirq-google/cirq_google/devices/grid_device_test.py @@ -510,3 +510,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 From 249d02f588395a7822c39201e299d7dfe87a0212 Mon Sep 17 00:00:00 2001 From: Cheng Xing Date: Thu, 23 Jun 2022 23:35:02 +0000 Subject: [PATCH 2/3] Sort the qubit list; verify against the expected qubit list instead in unit test --- cirq-google/cirq_google/devices/grid_device.py | 2 +- cirq-google/cirq_google/devices/grid_device_test.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cirq-google/cirq_google/devices/grid_device.py b/cirq-google/cirq_google/devices/grid_device.py index 87fbcbef3ca..316a6ae8109 100644 --- a/cirq-google/cirq_google/devices/grid_device.py +++ b/cirq-google/cirq_google/devices/grid_device.py @@ -312,7 +312,7 @@ def metadata(self) -> cirq.GridDeviceMetadata: deadline='v0.16', fix='Change `device.qubits` to `device.metadata.qubit_set`.' ) def qubits(self) -> List[cirq.Qid]: - return list(self._metadata.qubit_set) + return sorted(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 9e3dd9d7ede..ee995553cfe 100644 --- a/cirq-google/cirq_google/devices/grid_device_test.py +++ b/cirq-google/cirq_google/devices/grid_device_test.py @@ -513,8 +513,8 @@ def test_to_proto_empty(): def test_grid_device_qubits(): - _, spec = _create_device_spec_with_horizontal_couplings() + device_info, 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 + assert device.qubits == device_info.grid_qubits From 14ab21aa805d6be391789e75714171386a45537c Mon Sep 17 00:00:00 2001 From: Cheng Xing Date: Fri, 24 Jun 2022 00:09:51 +0000 Subject: [PATCH 3/3] Ignoring mypy error around property not being supported (https://github.com/python/mypy/issues/1362#issuecomment-208605185) --- cirq-google/cirq_google/devices/grid_device.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cirq-google/cirq_google/devices/grid_device.py b/cirq-google/cirq_google/devices/grid_device.py index 316a6ae8109..e920f6f981e 100644 --- a/cirq-google/cirq_google/devices/grid_device.py +++ b/cirq-google/cirq_google/devices/grid_device.py @@ -307,7 +307,7 @@ def metadata(self) -> cirq.GridDeviceMetadata: # 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 + @property # type: ignore @cirq._compat.deprecated( deadline='v0.16', fix='Change `device.qubits` to `device.metadata.qubit_set`.' )