Skip to content

Remove qid_pairs deprecation. #5290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cirq-core/cirq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
NoiseProperties,
OpIdentifier,
SuperconductingQubitsNoiseProperties,
SymmetricalQidPair,
UNCONSTRAINED_DEVICE,
NamedTopology,
draw_gridlike,
Expand Down
14 changes: 0 additions & 14 deletions cirq-core/cirq/contrib/graph_device/graph_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,6 @@ def qubit_set(self) -> FrozenSet['cirq.Qid']:
def edges(self):
return tuple(sorted(self.device_graph.edges))

@_compat.deprecated(
deadline='v0.15',
fix='qubit coupling data can now be found in device.metadata.nx_graph if provided.',
)
def qid_pairs(self) -> FrozenSet['cirq.SymmetricalQidPair']:
with _compat.block_overlapping_deprecation('device\\.metadata'):
return frozenset(
[
devices.SymmetricalQidPair(*edge) # type: ignore
for edge in self.device_graph.edges
if len(edge) == 2 and all(isinstance(q, ops.Qid) for q in edge)
]
)

@property
def labelled_edges(self):
return self.device_graph.labelled_edges
Expand Down
8 changes: 0 additions & 8 deletions cirq-core/cirq/contrib/graph_device/graph_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,3 @@ def test_qubit_set_deprecated():
device = ccgd.UndirectedGraphDevice(device_graph=device_graph)
with cirq.testing.assert_deprecated('qubit_set', deadline='v0.15'):
assert device.qubit_set() == {a, b, c, d}


def test_qid_pairs_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)
with cirq.testing.assert_deprecated('device.metadata', deadline='v0.15', count=1):
assert len(device.qid_pairs()) == 2
2 changes: 1 addition & 1 deletion cirq-core/cirq/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Device classes, qubits, and topologies, as well as noise models."""

from cirq.devices.device import Device, DeviceMetadata, SymmetricalQidPair
from cirq.devices.device import Device, DeviceMetadata

from cirq.devices.grid_device_metadata import GridDeviceMetadata

Expand Down
79 changes: 1 addition & 78 deletions cirq-core/cirq/devices/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
# limitations under the License.

import abc
from typing import TYPE_CHECKING, Optional, AbstractSet, cast, FrozenSet, Iterator, Iterable
from typing import TYPE_CHECKING, Optional, AbstractSet, FrozenSet, Iterable
import networkx as nx
from cirq import _compat, value
from cirq.devices.grid_qubit import _BaseGridQid
from cirq.devices.line_qubit import _BaseLineQid

if TYPE_CHECKING:
import cirq
Expand Down Expand Up @@ -51,47 +49,6 @@ def qubit_set(self) -> Optional[AbstractSet['cirq.Qid']]:
# Default to the qubits being unknown.
return None

@_compat.deprecated(
deadline='v0.15', fix='qubit coupling data can now be found in device.metadata if provided.'
)
def qid_pairs(self) -> Optional[FrozenSet['cirq.SymmetricalQidPair']]:
"""Returns a set of qubit edges on the device, if possible.

This property can be overridden in child classes for special handling.
The default handling is: GridQids and LineQids will have neighbors as
edges, and others will be fully connected.

Returns:
If the device has a finite set of qubits, then a set of all edges
on the device is returned.

If the device has no well defined finite set of qubits (e.g.
`cirq.UnconstrainedDevice` has this property), then `None` is
returned.
"""
with _compat.block_overlapping_deprecation('(device\\.metadata|qubit_set)'):
qs = self.qubit_set()
if qs is None:
return None
if all(isinstance(q, _BaseGridQid) for q in qs):
return frozenset(
[
SymmetricalQidPair(q, q2)
for q in [cast(_BaseGridQid, q) for q in qs]
for q2 in [q + (0, 1), q + (1, 0)]
if q2 in qs
]
)
if all(isinstance(q, _BaseLineQid) for q in qs):
return frozenset(
[
SymmetricalQidPair(q, q + 1)
for q in [cast(_BaseLineQid, q) for q in qs]
if q + 1 in qs
]
)
return frozenset([SymmetricalQidPair(q, q2) for q in qs for q2 in qs if q < q2])

@_compat.deprecated(deadline='v0.15', fix='Devices will no longer decompose operations.')
def decompose_operation(self, operation: 'cirq.Operation') -> 'cirq.OP_TREE':
"""Returns a device-valid decomposition for the given operation.
Expand Down Expand Up @@ -168,40 +125,6 @@ def can_add_operation_into_moment(
return not moment.operates_on(operation.qubits)


@_compat.deprecated_class(
deadline='v0.15',
fix='Qid coupling information can now be found in device.metadata if applicable.',
)
@value.value_equality
class SymmetricalQidPair:
def __init__(self, qid1: 'cirq.Qid', qid2: 'cirq.Qid'):
if qid1 == qid2:
raise ValueError('A QidPair cannot have identical qids.')
self.qids = frozenset([qid1, qid2])

def _value_equality_values_(self):
return self.qids

def __repr__(self):
return f'cirq.QidPair({repr(sorted(self.qids))[1:-1]})'

def _json_dict_(self):
return {'qids': sorted(self.qids)}

@classmethod
def _from_json_dict_(cls, qids, **kwargs):
return cls(qids[0], qids[1])

def __len__(self) -> int:
return 2

def __iter__(self) -> Iterator['cirq.Qid']:
yield from sorted(self.qids)

def __contains__(self, item: 'cirq.Qid') -> bool:
return item in self.qids


@value.value_equality
class DeviceMetadata:
"""Parent type for all device specific metadata classes."""
Expand Down
49 changes: 0 additions & 49 deletions cirq-core/cirq/devices/device_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# pylint: disable=wrong-or-nonexistent-copyright-notice
import pytest
import networkx as nx
import cirq

Expand Down Expand Up @@ -40,24 +39,6 @@ def _qubits(self):
assert PrivateQubitMethodDevice().qubit_set() == frozenset(cirq.LineQubit.range(6))


def test_qid_pairs():
class RawDevice(cirq.Device):
pass

with cirq.testing.assert_deprecated('device.metadata', deadline='v0.15', count=1):
assert RawDevice().qid_pairs() is None

class QubitFieldDevice(cirq.Device):
def __init__(self, qubits):
self.qubits = qubits

with cirq.testing.assert_deprecated('device.metadata', deadline='v0.15', count=3):

assert len(QubitFieldDevice(cirq.LineQubit.range(10)).qid_pairs()) == 9
assert len(QubitFieldDevice(cirq.GridQubit.rect(10, 10)).qid_pairs()) == 180
assert len(QubitFieldDevice([cirq.NamedQubit(str(s)) for s in range(10)]).qid_pairs()) == 45


def test_decompose_operation_deprecated():
q0 = cirq.GridQubit(0, 0)

Expand All @@ -68,36 +49,6 @@ class RawDevice(cirq.Device):
RawDevice().decompose_operation(cirq.H(q0))


def test_qid_pair_deprecated():
q0, q1, q2, q3 = cirq.LineQubit.range(4)
with cirq.testing.assert_deprecated('device.metadata', deadline='v0.15', count=3):
e1 = cirq.SymmetricalQidPair(q0, q1)
e2 = cirq.SymmetricalQidPair(q1, q0)
e3 = cirq.SymmetricalQidPair(q2, q3)
assert e1 == e2
assert e2 != e3
assert repr(e1) == "cirq.QidPair(cirq.LineQubit(0), cirq.LineQubit(1))"

assert len(e1) == 2
a, b = e1
assert (a, b) == (q0, q1)
a, b = e2
assert (a, b) == (q0, q1)

assert q0 in e1
assert q1 in e1
assert q2 not in e1

set1 = frozenset([e1, e2])
set2 = frozenset([e2, e3])
assert len(set1) == 1
assert len(set2) == 2

with cirq.testing.assert_deprecated('device.metadata', deadline='v0.15', count=1):
with pytest.raises(ValueError, match='A QidPair cannot have identical qids.'):
cirq.SymmetricalQidPair(q0, q0)


def test_device_metadata():
class RawDevice(cirq.Device):
pass
Expand Down
13 changes: 0 additions & 13 deletions cirq-core/cirq/ion/ion_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,6 @@ def metadata(self) -> devices.DeviceMetadata:
def qubit_set(self) -> FrozenSet['cirq.LineQubit']:
return self.qubits

@_compat.deprecated(
deadline='v0.15', fix='qubit coupling data can now be found in device.metadata if provided.'
)
def qid_pairs(self) -> FrozenSet['cirq.SymmetricalQidPair']:
"""Qubits have all-to-all connectivity, so returns all pairs.

Returns:
All qubit pairs on the device.
"""
with _compat.block_overlapping_deprecation('device\\.metadata'):
qs = self.qubits
return frozenset([devices.SymmetricalQidPair(q, q2) for q in qs for q2 in qs if q < q2])

@_compat.deprecated(
fix='Use cirq.ConvertToIonGates() instead to decompose operations.', deadline='v0.15'
)
Expand Down
5 changes: 0 additions & 5 deletions cirq-core/cirq/ion/ion_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,3 @@ def test_at():
def test_qubit_set_deprecated():
with cirq.testing.assert_deprecated('qubit_set', deadline='v0.15', count=2):
assert ion_device(3).qubit_set() == frozenset(cirq.LineQubit.range(3))


def test_qid_pairs_deprecated():
with cirq.testing.assert_deprecated('device.metadata', deadline='v0.15', count=2):
assert len(ion_device(10).qid_pairs()) == 45
5 changes: 4 additions & 1 deletion cirq-core/cirq/json_resolver_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def _datetime(timestamp: float) -> datetime.datetime:
# timezones, and hour fields will not be identical.
return datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc)

def _symmetricalqidpair(qids):
return frozenset(qids)

import sympy

return {
Expand Down Expand Up @@ -176,7 +179,6 @@ def _datetime(timestamp: float) -> datetime.datetime:
'StabilizerStateChForm': cirq.StabilizerStateChForm,
'StatePreparationChannel': cirq.StatePreparationChannel,
'SwapPowGate': cirq.SwapPowGate,
'SymmetricalQidPair': cirq.SymmetricalQidPair,
'SympyCondition': cirq.SympyCondition,
'TaggedOperation': cirq.TaggedOperation,
'TiltedSquareLattice': cirq.TiltedSquareLattice,
Expand Down Expand Up @@ -204,6 +206,7 @@ def _datetime(timestamp: float) -> datetime.datetime:
'IdentityOperation': _identity_operation_from_dict,
'ParallelGateOperation': _parallel_gate_op, # Removed in v0.14
'SingleQubitMatrixGate': single_qubit_matrix_gate,
'SymmetricalQidPair': _symmetricalqidpair, # Removed in v0.15
'TwoQubitMatrixGate': two_qubit_matrix_gate,
# not a cirq class, but treated as one:
'pandas.DataFrame': pd.DataFrame,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
frozenset([cirq.LineQubit(0), cirq.LineQubit(1)])
2 changes: 1 addition & 1 deletion cirq-core/cirq/protocols/json_test_data/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
'Unique',
'DEFAULT_RESOLVERS',
],
deprecated={'GlobalPhaseOperation': 'v0.16', 'SymmetricalQidPair': 'v0.15'},
deprecated={'GlobalPhaseOperation': 'v0.16'},
tested_elsewhere=[
# SerializableByKey does not follow common serialization rules.
# It is tested separately in test_context_serialization.
Expand Down
22 changes: 0 additions & 22 deletions cirq-google/cirq_google/devices/serializable_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,28 +250,6 @@ def __str__(self) -> str:

return super().__str__()

@_compat.deprecated(
deadline='v0.15', fix='qubit coupling data can now be found in device.metadata if provided.'
)
def qid_pairs(self) -> FrozenSet['cirq.SymmetricalQidPair']:
"""Returns a list of qubit edges on the device, defined by the gate
definitions.

Returns:
The list of qubit edges on the device.
"""
with _compat.block_overlapping_deprecation('device\\.metadata'):
return frozenset(
[
cirq.SymmetricalQidPair(pair[0], pair[1])
for gate_defs in self.gate_definitions.values()
for gate_def in gate_defs
if gate_def.number_of_qubits == 2
for pair in gate_def.target_set
if len(pair) == 2 and pair[0] < pair[1]
]
)

def _repr_pretty_(self, p: Any, cycle: bool) -> None:
"""Creates ASCII diagram for Jupyter, IPython, etc."""
# There should never be a cycle, but just in case use the default repr.
Expand Down
5 changes: 0 additions & 5 deletions cirq-google/cirq_google/devices/serializable_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,3 @@ def test_sycamore23_str():
(9, 4)"""
)


def test_sycamore23_qid_pairs_deprecated():
with cirq.testing.assert_deprecated('device.metadata', deadline='v0.15', count=1):
assert len(cg.Sycamore23.qid_pairs()) == 32
20 changes: 0 additions & 20 deletions cirq-pasqal/cirq_pasqal/pasqal_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,26 +356,6 @@ def _value_equality_values_(self) -> Any:
def _json_dict_(self) -> Dict[str, Any]:
return cirq.protocols.obj_to_dict_helper(self, ['control_radius', 'qubits'])

@_compat.deprecated(
deadline='v0.15', fix='qubit coupling data can now be found in device.metadata if provided.'
)
def qid_pairs(self) -> FrozenSet['cirq.SymmetricalQidPair']:
"""Returns a list of qubit edges on the device.

Returns:
All qubit pairs that are less or equal to the control radius apart.
"""
with _compat.block_overlapping_deprecation('device\\.metadata'):
qs = self.qubits
return frozenset(
[
cirq.SymmetricalQidPair(q, q2)
for q in qs
for q2 in qs
if q < q2 and self.distance(q, q2) <= self.control_radius
]
)


class PasqalConverter(cirq.neutral_atoms.ConvertToNeutralAtomGates):
"""A gate converter for compatibility with Pasqal processors.
Expand Down
19 changes: 0 additions & 19 deletions cirq-pasqal/cirq_pasqal/pasqal_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,22 +258,3 @@ def test_to_json():
vdev = PasqalVirtualDevice(control_radius=2, qubits=[TwoDQubit(0, 0)])
d = vdev._json_dict_()
assert d == {"control_radius": 2, "qubits": [cirq_pasqal.TwoDQubit(0, 0)]}


def test_qid_pairs_deprecated():
dev = PasqalVirtualDevice(
1,
qubits=[
ThreeDQubit(0, 0, 0),
ThreeDQubit(1, 0, 0),
ThreeDQubit(0, 1, 0),
ThreeDQubit(1, 1, 0),
ThreeDQubit(1, 1, 1),
],
)
with cirq.testing.assert_deprecated('device.metadata', deadline='v0.15', count=3):
assert len(dev.qid_pairs()) == 5
dev1 = PasqalVirtualDevice(
5, qubits=[TwoDQubit(0, 0), TwoDQubit(3, 2), TwoDQubit(3, 4), TwoDQubit(3, 6)]
)
assert len(dev1.qid_pairs()) == 5