Skip to content

Commit

Permalink
Flush v0.14.0 deprecation backlog. (#4601)
Browse files Browse the repository at this point in the history
Removed `cirq.<vendor>` to `cirq_<vendor>` deprecations (This required some repr_inward changes as well as some renaming in `cirq_pasqal`). 
Removed `ParallelGateOperation`.
Removed `cirq.Two/ThreeQubitGate`. We still have `cirq.testing.Two/ThreeQubitGate`.
Removed `SupportsOnEachGate`.
Removed `allow_decompose` parameter from `measurement_key_names` and `is_measurement`.
Removed `kraus_to_channel_matrix`, `operation_to_channel_matrix`.
Removed `asynchronous_pending` and `cirq-core/cirq/testing/asynchronous.py`.
Removed `gate_set_name` in favor of `name` from `serializable_gate_set.py`

@mpharrigan can you double check my changes on the json items.

BREAKING CHANGE= some features of ParallelGateOperation aren't fully convertible. i.e. `cirq.num_qubits(old_op.gate) != cirq.num_qubits(new_op.gate)` and `isinstance(old_op, GateOperation) != isinstance(new_op, GateOperation)`
  • Loading branch information
MichaelBroughton authored Oct 29, 2021
1 parent c7d420b commit 21b9be3
Show file tree
Hide file tree
Showing 54 changed files with 102 additions and 1,369 deletions.
40 changes: 0 additions & 40 deletions cirq-core/cirq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from cirq import (
# Low level
_version,
_compat,
_doc,
type_workarounds,
)
Expand Down Expand Up @@ -249,7 +248,6 @@
ParallelGate,
ParallelGateFamily,
parallel_gate_op,
ParallelGateOperation,
Pauli,
PAULI_GATE_LIKE,
PAULI_STRING_LIKE,
Expand Down Expand Up @@ -301,12 +299,10 @@
SwapPowGate,
T,
TaggedOperation,
ThreeQubitGate,
ThreeQubitDiagonalGate,
TOFFOLI,
transform_op_tree,
TwoQubitDiagonalGate,
TwoQubitGate,
VirtualTag,
wait,
WaitGate,
Expand Down Expand Up @@ -369,11 +365,9 @@
entanglement_fidelity,
eye_tensor,
fidelity,
kraus_to_channel_matrix,
kraus_to_choi,
kraus_to_superoperator,
one_hot,
operation_to_channel_matrix,
operation_to_choi,
operation_to_superoperator,
QUANTUM_STATE_LIKE,
Expand Down Expand Up @@ -621,40 +615,6 @@
testing,
)

_compat.deprecated_submodule(
new_module_name='cirq_google',
old_parent=__name__,
old_child='google',
deadline="v0.14",
create_attribute=True,
)

_compat.deprecated_submodule(
new_module_name='cirq_aqt',
old_parent=__name__,
old_child='aqt',
deadline="v0.14",
create_attribute=True,
)


_compat.deprecated_submodule(
new_module_name='cirq_ionq',
old_parent=__name__,
old_child='ionq',
deadline="v0.14",
create_attribute=True,
)

_compat.deprecated_submodule(
new_module_name='cirq_pasqal',
old_parent=__name__,
old_child='pasqal',
deadline="v0.14",
create_attribute=True,
)


# Registers cirq-core's public classes for JSON serialization.
# pylint: disable=wrong-import-position
from cirq.protocols.json_serialization import _register_resolver
Expand Down
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 @@ -45,6 +45,9 @@ def two_qubit_matrix_gate(matrix):
matrix = np.array(matrix, dtype=np.complex128)
return cirq.MatrixGate(matrix, qid_shape=(2, 2))

def _parallel_gate_op(gate, qubits):
return cirq.parallel_gate_op(gate, *qubits)

import sympy

return {
Expand Down Expand Up @@ -112,7 +115,7 @@ def two_qubit_matrix_gate(matrix):
'_PauliY': cirq.ops.pauli_gates._PauliY,
'_PauliZ': cirq.ops.pauli_gates._PauliZ,
'ParamResolver': cirq.ParamResolver,
'ParallelGateOperation': cirq.ParallelGateOperation,
'ParallelGateOperation': _parallel_gate_op, # Removed in v0.14
'ParallelGate': cirq.ParallelGate,
'PauliMeasurementGate': cirq.PauliMeasurementGate,
'PauliString': cirq.PauliString,
Expand Down
6 changes: 3 additions & 3 deletions cirq-core/cirq/neutral_atoms/neutral_atom_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def duration_of(self, operation: ops.Operation):
gate
"""
self.validate_operation(operation)
if isinstance(operation, (ops.GateOperation, ops.ParallelGateOperation)):
if isinstance(operation, ops.GateOperation):
if isinstance(operation.gate, ops.MeasurementGate):
return self._measurement_duration
return self._gate_duration
Expand Down Expand Up @@ -167,7 +167,7 @@ def validate_operation(self, operation: ops.Operation):
Raises:
ValueError: If the operation is not valid
"""
if not isinstance(operation, (ops.GateOperation, ops.ParallelGateOperation)):
if not isinstance(operation, ops.GateOperation):
raise ValueError(f'Unsupported operation: {operation!r}')

# All qubits the operation acts on must be on the device
Expand Down Expand Up @@ -219,7 +219,7 @@ def validate_moment(self, moment: ops.Moment):

categorized_ops: DefaultDict = collections.defaultdict(list)
for op in moment.operations:
assert isinstance(op, (ops.GateOperation, ops.ParallelGateOperation))
assert isinstance(op, ops.GateOperation)
for k, v in CATEGORIES.items():
assert isinstance(v, tuple)
gate = _subgate_if_parallel_gate(op.gate)
Expand Down
6 changes: 0 additions & 6 deletions cirq-core/cirq/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@
from cirq.ops.gate_features import (
InterchangeableQubitsGate,
SingleQubitGate,
ThreeQubitGate,
TwoQubitGate,
)

from cirq.ops.gate_operation import (
Expand Down Expand Up @@ -154,10 +152,6 @@

from cirq.ops.parallel_gate import ParallelGate, parallel_gate_op

from cirq.ops.parallel_gate_operation import (
ParallelGateOperation,
)

from cirq.ops.projector import (
ProjectorString,
)
Expand Down
53 changes: 0 additions & 53 deletions cirq-core/cirq/ops/gate_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
"""

import abc
import warnings

from cirq import value, ops
from cirq._compat import deprecated_class
from cirq.ops import raw_types


Expand All @@ -33,58 +30,8 @@ def qubit_index_to_equivalence_group_key(self, index: int) -> int:
return 0


class _SupportsOnEachGateMeta(value.ABCMetaImplementAnyOneOf):
def __instancecheck__(cls, instance):
return isinstance(instance, (SingleQubitGate, ops.DepolarizingChannel)) or issubclass(
type(instance), SupportsOnEachGate
)


@deprecated_class(
deadline='v0.14',
fix='Remove `SupportsOnEachGate` from the list of parent classes. '
'`on_each` is now directly supported in the `Gate` base class.',
)
class SupportsOnEachGate(raw_types.Gate, metaclass=_SupportsOnEachGateMeta):
pass


class SingleQubitGate(raw_types.Gate, metaclass=abc.ABCMeta):
"""A gate that must be applied to exactly one qubit."""

def _num_qubits_(self) -> int:
return 1


class _TwoQubitGateMeta(value.ABCMetaImplementAnyOneOf):
def __instancecheck__(cls, instance):
warnings.warn(
'isinstance(gate, TwoQubitGate) is deprecated. Use cirq.num_qubits(gate) == 2 instead',
DeprecationWarning,
)
return isinstance(instance, raw_types.Gate) and instance._num_qubits_() == 2


@deprecated_class(deadline='v0.14', fix='Define _num_qubits_ manually.')
class TwoQubitGate(raw_types.Gate, metaclass=_TwoQubitGateMeta):
"""A gate that must be applied to exactly two qubits."""

def _num_qubits_(self) -> int:
return 2


class _ThreeQubitGateMeta(value.ABCMetaImplementAnyOneOf):
def __instancecheck__(cls, instance):
warnings.warn(
'isinstance(gate, TwoQubitGate) is deprecated. Use cirq.num_qubits(gate) == 3 instead',
DeprecationWarning,
)
return isinstance(instance, raw_types.Gate) and instance._num_qubits_() == 3


@deprecated_class(deadline='v0.14', fix='Define _num_qubits_ manually.')
class ThreeQubitGate(raw_types.Gate, metaclass=_ThreeQubitGateMeta):
"""A gate that must be applied to exactly three qubits."""

def _num_qubits_(self) -> int:
return 3
Loading

0 comments on commit 21b9be3

Please sign in to comment.