Skip to content

Commit

Permalink
Deprecate qubit_set in cirq-core/devices (#4965)
Browse files Browse the repository at this point in the history
This deprecates qubit_set on `UnconstrainedDevice`, `Device` and `HyperGraphDevice` in contrib. Note that device already has metadata. UnconstrainedDevice probably shouldn't have a metadata and to add Metadata for HyperGraphDevice, might take a non-trivial amount of work. Maybe we open an issue for this ?

xref: #4744 .
  • Loading branch information
MichaelBroughton authored Feb 16, 2022
1 parent 43955b3 commit 0225963
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions cirq-core/cirq/contrib/graph_device/graph_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def __init__(
def qubits(self) -> Tuple['cirq.Qid', ...]:
return cast(Tuple['cirq.Qid', ...], tuple(sorted(self.device_graph.vertices)))

@_compat.deprecated(fix='Please use UndirectedGraphDevice.qubits', deadline='v0.15')
def qubit_set(self) -> FrozenSet['cirq.Qid']:
return frozenset(self.qubits)

Expand Down
5 changes: 3 additions & 2 deletions cirq-core/cirq/contrib/graph_device/graph_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@ def test_graph_device_copy_and_add():
assert device_copy == device_sum


def test_qubit_set():
def test_qubit_set_deprecated():
a, b, c, d = cirq.LineQubit.range(4)
device_graph = ccgd.UndirectedHypergraph(labelled_edges={(a, b): None, (c, d): None})
device = ccgd.UndirectedGraphDevice(device_graph=device_graph)
assert device.qubit_set() == {a, b, c, d}
with cirq.testing.assert_deprecated('qubit_set', deadline='v0.15'):
assert device.qubit_set() == {a, b, c, d}


def test_qid_pairs_deprecated():
Expand Down
3 changes: 2 additions & 1 deletion cirq-core/cirq/devices/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
class Device(metaclass=abc.ABCMeta):
"""Hardware constraints for validating circuits."""

@_compat.deprecated(fix='Use metadata.qubit_set if applicable.', deadline='v0.15')
def qubit_set(self) -> Optional[AbstractSet['cirq.Qid']]:
"""Returns a set or frozenset of qubits on the device, if possible.
Expand Down Expand Up @@ -77,7 +78,7 @@ def qid_pairs(self) -> Optional[FrozenSet['cirq.SymmetricalQidPair']]:
`cirq.UnconstrainedDevice` has this property), then `None` is
returned.
"""
with _compat.block_overlapping_deprecation('device\\.metadata'):
with _compat.block_overlapping_deprecation('(device\\.metadata|qubit_set)'):
qs = self.qubit_set()
if qs is None:
return None
Expand Down
17 changes: 11 additions & 6 deletions cirq-core/cirq/devices/device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,40 @@
import cirq


def test_qubit_set():
def test_qubit_set_deprecated():
class RawDevice(cirq.Device):
pass

assert RawDevice().qubit_set() is None
with cirq.testing.assert_deprecated('qubit_set', deadline='v0.15'):
assert RawDevice().qubit_set() is None

class QubitFieldDevice(cirq.Device):
def __init__(self):
self.qubits = cirq.LineQubit.range(3)

assert QubitFieldDevice().qubit_set() == frozenset(cirq.LineQubit.range(3))
with cirq.testing.assert_deprecated('qubit_set', deadline='v0.15'):
assert QubitFieldDevice().qubit_set() == frozenset(cirq.LineQubit.range(3))

class PrivateQubitFieldDevice(cirq.Device):
def __init__(self):
self._qubits = cirq.LineQubit.range(4)

assert PrivateQubitFieldDevice().qubit_set() == frozenset(cirq.LineQubit.range(4))
with cirq.testing.assert_deprecated('qubit_set', deadline='v0.15'):
assert PrivateQubitFieldDevice().qubit_set() == frozenset(cirq.LineQubit.range(4))

class QubitMethodDevice(cirq.Device):
def qubits(self):
return cirq.LineQubit.range(5)

assert QubitMethodDevice().qubit_set() == frozenset(cirq.LineQubit.range(5))
with cirq.testing.assert_deprecated('qubit_set', deadline='v0.15'):
assert QubitMethodDevice().qubit_set() == frozenset(cirq.LineQubit.range(5))

class PrivateQubitMethodDevice(cirq.Device):
def _qubits(self):
return cirq.LineQubit.range(6)

assert PrivateQubitMethodDevice().qubit_set() == frozenset(cirq.LineQubit.range(6))
with cirq.testing.assert_deprecated('qubit_set', deadline='v0.15'):
assert PrivateQubitMethodDevice().qubit_set() == frozenset(cirq.LineQubit.range(6))


def test_qid_pairs():
Expand Down
3 changes: 2 additions & 1 deletion cirq-core/cirq/devices/unconstrained_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from typing import Any, Dict, TYPE_CHECKING

from cirq import value, protocols
from cirq import _compat, value, protocols
from cirq._doc import document
from cirq.devices import device

Expand All @@ -26,6 +26,7 @@
class _UnconstrainedDevice(device.Device):
"""A device that allows everything, infinitely fast."""

@_compat.deprecated(fix='qubit_set on UnconstrainedDevice is always None.', deadline='v0.15')
def qubit_set(self) -> None:
return None

Expand Down
5 changes: 3 additions & 2 deletions cirq-core/cirq/devices/unconstrained_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ def test_infinitely_fast():
)


def test_qubit_set():
assert cirq.UNCONSTRAINED_DEVICE.qubit_set() is None
def test_qubit_set_deprecated():
with cirq.testing.assert_deprecated('None', deadline='v0.15'):
assert cirq.UNCONSTRAINED_DEVICE.qubit_set() is None

0 comments on commit 0225963

Please sign in to comment.