Skip to content

Commit

Permalink
Temporary GridDevice.qubits property
Browse files Browse the repository at this point in the history
  • Loading branch information
verult committed Jun 23, 2022
1 parent 4f4310e commit 7e62a15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cirq-google/cirq_google/devices/grid_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions cirq-google/cirq_google/devices/grid_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7e62a15

Please sign in to comment.