Skip to content

Commit ac9e8bc

Browse files
MichaelBroughtonrht
authored andcommitted
Remove v0.13 deprecations. (quantumlib#4567)
Flush v0.13 deprecation backlog.
1 parent 653f846 commit ac9e8bc

27 files changed

+19
-662
lines changed

cirq-core/cirq/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@
505505
ApplyMixtureArgs,
506506
ApplyUnitaryArgs,
507507
approx_eq,
508-
channel,
509508
circuit_diagram_info,
510509
CircuitDiagramInfo,
511510
CircuitDiagramInfoArgs,
@@ -516,7 +515,6 @@
516515
DEFAULT_RESOLVERS,
517516
definitely_commutes,
518517
equal_up_to_global_phase,
519-
has_channel,
520518
has_kraus,
521519
has_mixture,
522520
has_stabilizer_effect,
@@ -558,7 +556,6 @@
558556
SupportsApplyMixture,
559557
SupportsApproximateEquality,
560558
SupportsConsistentApplyUnitary,
561-
SupportsChannel,
562559
SupportsCircuitDiagramInfo,
563560
SupportsCommutes,
564561
SupportsDecompose,

cirq-core/cirq/contrib/quimb/mps_simulator.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919

2020
import dataclasses
2121
import math
22-
from typing import Any, Dict, List, Optional, Sequence, Set, TYPE_CHECKING, Iterable, Union
22+
from typing import Any, Dict, List, Optional, Sequence, Set, TYPE_CHECKING, Union
2323

2424
import numpy as np
2525
import quimb.tensor as qtn
2626

2727
from cirq import devices, study, ops, protocols, value
28-
from cirq._compat import deprecated_parameter
2928
from cirq.sim import simulator, simulator_base
3029
from cirq.sim.act_on_args import ActOnArgs
3130

@@ -214,20 +213,13 @@ class MPSState(ActOnArgs):
214213

215214
# TODO(#3388) Add documentation for Raises.
216215
# pylint: disable=missing-raises-doc
217-
@deprecated_parameter(
218-
deadline='v0.13',
219-
fix='No longer needed. `protocols.act_on` infers axes.',
220-
parameter_desc='axes',
221-
match=lambda args, kwargs: 'axes' in kwargs or len(args) > 6,
222-
)
223216
def __init__(
224217
self,
225218
qubits: Sequence['cirq.Qid'],
226219
prng: np.random.RandomState,
227220
simulation_options: MPSOptions = MPSOptions(),
228221
grouping: Optional[Dict['cirq.Qid', int]] = None,
229222
initial_state: int = 0,
230-
axes: Iterable[int] = None,
231223
log_of_measurement_results: Dict[str, Any] = None,
232224
):
233225
"""Creates and MPSState
@@ -240,12 +232,10 @@ def __init__(
240232
simulation_options: Numerical options for the simulation.
241233
grouping: How to group qubits together, if None all are individual.
242234
initial_state: An integer representing the initial state.
243-
axes: The indices of axes corresponding to the qubits that the
244-
operation is supposed to act upon.
245235
log_of_measurement_results: A mutable object that measurements are
246236
being recorded into.
247237
"""
248-
super().__init__(prng, qubits, axes, log_of_measurement_results)
238+
super().__init__(prng, qubits, log_of_measurement_results)
249239
qubit_map = self.qubit_map
250240
self.grouping = qubit_map if grouping is None else grouping
251241
if self.grouping.keys() != self.qubit_map.keys():

cirq-core/cirq/ops/gate_operation.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,6 @@ def _mixture_(self) -> Sequence[Tuple[float, Any]]:
199199
return getter()
200200
return NotImplemented
201201

202-
def _has_channel_(self) -> bool:
203-
getter = getattr(self.gate, '_has_channel_', None)
204-
if getter is not None:
205-
return getter()
206-
return NotImplemented
207-
208-
def _channel_(self) -> Union[Tuple[np.ndarray], NotImplementedType]:
209-
getter = getattr(self.gate, '_channel_', None)
210-
if getter is not None:
211-
return getter()
212-
return NotImplemented
213-
214202
def _has_kraus_(self) -> bool:
215203
getter = getattr(self.gate, '_has_kraus_', None)
216204
if getter is not None:

cirq-core/cirq/ops/gate_operation_test.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import Tuple
15-
1614
import numpy as np
1715
import pytest
1816
import sympy
@@ -436,27 +434,3 @@ def _is_parameterized_(self):
436434
assert not cirq.is_parameterized(No1().on(q))
437435
assert not cirq.is_parameterized(No2().on(q))
438436
assert cirq.is_parameterized(Yes().on(q))
439-
440-
441-
def test_channel_propagates_to_gate():
442-
class TestGate(cirq.SingleQubitGate):
443-
def _channel_(self) -> np.ndarray:
444-
return (np.eye(2),)
445-
446-
def _has_channel_(self) -> bool:
447-
return True
448-
449-
def assert_kraus_eq(ks1: Tuple[np.ndarray, ...], ks2: Tuple[np.ndarray, ...]) -> None:
450-
assert len(ks1) == len(ks2)
451-
for k1, k2 in zip(ks1, ks2):
452-
assert np.all(k1 == k2)
453-
454-
identity_kraus = (np.eye(2),)
455-
q = cirq.LineQubit(0)
456-
gate = TestGate()
457-
gate_op = TestGate().on(q)
458-
with cirq.testing.assert_deprecated(deadline='v0.13', count=None):
459-
assert cirq.has_channel(gate)
460-
assert cirq.has_channel(gate_op)
461-
assert_kraus_eq(cirq.channel(gate), identity_kraus)
462-
assert_kraus_eq(cirq.channel(gate_op), identity_kraus)

cirq-core/cirq/ops/kraus_channel.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ def __init__(
5151
self._key = key
5252

5353
@staticmethod
54-
def from_channel(
55-
channel: 'protocols.SupportsChannel', key: Union[str, value.MeasurementKey, None] = None
56-
):
54+
def from_channel(channel: 'KrausChannel', key: Union[str, value.MeasurementKey, None] = None):
5755
"""Creates a copy of a channel with the given measurement key."""
5856
return KrausChannel(kraus_ops=list(protocols.kraus(channel)), key=key)
5957

cirq-core/cirq/protocols/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@
4040
SupportsApproximateEquality,
4141
)
4242
from cirq.protocols.kraus_protocol import (
43-
channel,
4443
kraus,
45-
has_channel,
4644
has_kraus,
47-
SupportsChannel,
4845
SupportsKraus,
4946
)
5047
from cirq.protocols.commutes_protocol import (

cirq-core/cirq/protocols/act_on_protocol.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,8 @@ def act_on(
132132
if is_op and qubits is not None:
133133
raise ValueError('Calls to act_on should not supply qubits if the action is an Operation.')
134134

135-
# todo: change to an exception after `args.axes` is deprecated.
136135
if not is_op and qubits is None:
137-
from cirq.sim import ActOnArgs
138-
139-
if isinstance(args, ActOnArgs):
140-
qubits = [args.qubits[i] for i in args.axes]
136+
raise ValueError('Calls to act_on should supply qubits if the action is not an Operation.')
141137

142138
action_act_on = getattr(action, '_act_on_', None)
143139
if action_act_on is not None:

cirq-core/cirq/protocols/act_on_protocol_test.py

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,6 @@ def _act_on_(self, args):
8383
cirq.act_on(Op(), args)
8484

8585

86-
def test_act_on_args_axes_deprecation():
87-
class Args(DummyActOnArgs):
88-
def _act_on_fallback_(
89-
self,
90-
action: Union['cirq.Operation', 'cirq.Gate'],
91-
qubits: Sequence['cirq.Qid'] = None,
92-
allow_decompose: bool = True,
93-
) -> bool:
94-
self.measurements.append(qubits)
95-
return True
96-
97-
args = Args()
98-
args._qubits = tuple(cirq.LineQubit.range(3))
99-
with cirq.testing.assert_deprecated(
100-
"ActOnArgs.axes", "Use `protocols.act_on` instead.", deadline="v0.13"
101-
):
102-
args.axes = (1,)
103-
with cirq.testing.assert_deprecated(
104-
"ActOnArgs.axes", "Use `protocols.act_on` instead.", deadline="v0.13"
105-
):
106-
cirq.act_on(object(), args) # type: ignore
107-
assert args.measurements == [[cirq.LineQubit(1)]]
108-
109-
11086
def test_qubits_not_allowed_for_operations():
11187
class Op(cirq.Operation):
11288
@property
@@ -121,3 +97,9 @@ def with_qubits(self: TSelf, *new_qubits: 'cirq.Qid') -> TSelf:
12197
ValueError, match='Calls to act_on should not supply qubits if the action is an Operation'
12298
):
12399
cirq.act_on(Op(), args, qubits=[])
100+
101+
102+
def test_qubits_should_be_defined_for_operations():
103+
args = DummyActOnArgs()
104+
with pytest.raises(ValueError, match='Calls to act_on should'):
105+
cirq.act_on(cirq.KrausChannel([np.array([[1, 0], [0, 0]])]), args, qubits=None)

cirq-core/cirq/protocols/json_test_data/spec.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
'SupportsApplyChannel',
138138
'SupportsApplyMixture',
139139
'SupportsApproximateEquality',
140-
'SupportsChannel',
141140
'SupportsCircuitDiagramInfo',
142141
'SupportsCommutes',
143142
'SupportsConsistentApplyUnitary',

cirq-core/cirq/protocols/kraus_protocol.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
import numpy as np
2121
from typing_extensions import Protocol
2222

23-
from cirq._compat import (
24-
deprecated,
25-
deprecated_class,
26-
)
2723
from cirq._doc import doc_private
2824
from cirq.protocols.decompose_protocol import (
2925
_try_decompose_into_operations_and_qubits,
@@ -45,11 +41,6 @@
4541
TDefault = TypeVar('TDefault')
4642

4743

48-
@deprecated_class(deadline='v0.13', fix='use cirq.SupportsKraus instead')
49-
class SupportsChannel(Protocol):
50-
pass
51-
52-
5344
class SupportsKraus(Protocol):
5445
"""An object that may be describable as a quantum channel."""
5546

@@ -105,13 +96,6 @@ def _has_kraus_(self) -> bool:
10596
"""
10697

10798

108-
@deprecated(deadline='v0.13', fix='use cirq.kraus instead')
109-
def channel(
110-
val: Any, default: Any = RaiseTypeErrorIfNotProvided
111-
) -> Union[Tuple[np.ndarray, ...], TDefault]:
112-
return kraus(val, default=default)
113-
114-
11599
def kraus(
116100
val: Any, default: Any = RaiseTypeErrorIfNotProvided
117101
) -> Union[Tuple[np.ndarray, ...], TDefault]:
@@ -192,11 +176,6 @@ def kraus(
192176
)
193177

194178

195-
@deprecated(deadline='v0.13', fix='use cirq.has_kraus instead')
196-
def has_channel(val: Any, *, allow_decompose: bool = True) -> bool:
197-
return has_kraus(val, allow_decompose=allow_decompose)
198-
199-
200179
def has_kraus(val: Any, *, allow_decompose: bool = True) -> bool:
201180
"""Returns whether the value has a Kraus representation.
202181
@@ -220,13 +199,6 @@ def has_kraus(val: Any, *, allow_decompose: bool = True) -> bool:
220199
has a non-default value. Returns False if none of these functions
221200
exists.
222201
"""
223-
channel_getter = getattr(val, '_has_channel_', None)
224-
if channel_getter is not None:
225-
warnings.warn(
226-
'_has_channel_ is deprecated and will be removed in cirq 0.13, rename to _has_kraus_',
227-
DeprecationWarning,
228-
)
229-
230202
kraus_getter = getattr(val, '_has_kraus_', None)
231203
result = NotImplemented if kraus_getter is None else kraus_getter()
232204
if result is not NotImplemented:
@@ -236,10 +208,6 @@ def has_kraus(val: Any, *, allow_decompose: bool = True) -> bool:
236208
if result is not NotImplemented and result:
237209
return result
238210

239-
result = NotImplemented if channel_getter is None else channel_getter()
240-
if result is not NotImplemented:
241-
return result
242-
243211
if allow_decompose:
244212
operations, _, _ = _try_decompose_into_operations_and_qubits(val)
245213
if operations is not None:

cirq-core/cirq/protocols/kraus_protocol_test.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,6 @@ def assert_not_implemented(val):
5252
assert not cirq.has_kraus(val)
5353

5454

55-
def test_supports_channel_class_is_deprecated():
56-
with cirq.testing.assert_deprecated(deadline='v0.13'):
57-
58-
class SomeChannel(cirq.SupportsChannel):
59-
pass
60-
61-
_ = SomeChannel()
62-
63-
64-
def test_channel_protocol_is_deprecated():
65-
with cirq.testing.assert_deprecated(deadline='v0.13'):
66-
assert np.allclose(cirq.channel(cirq.X), cirq.kraus(cirq.X))
67-
68-
69-
def test_has_channel_protocol_is_deprecated():
70-
with cirq.testing.assert_deprecated(deadline='v0.13'):
71-
assert cirq.has_channel(cirq.depolarize(0.1)) == cirq.has_kraus(cirq.depolarize(0.1))
72-
73-
7455
def test_kraus_returns_not_implemented():
7556
class ReturnsNotImplemented:
7657
def _kraus_(self):
@@ -79,23 +60,6 @@ def _kraus_(self):
7960
assert_not_implemented(ReturnsNotImplemented())
8061

8162

82-
def test_channel_generates_deprecation_warning():
83-
class UsesDeprecatedChannelMethod:
84-
def _has_channel_(self):
85-
return True
86-
87-
def _channel_(self):
88-
return (np.eye(2),)
89-
90-
val = UsesDeprecatedChannelMethod()
91-
with pytest.warns(DeprecationWarning, match='_has_kraus_'):
92-
assert cirq.has_kraus(val)
93-
with pytest.warns(DeprecationWarning, match='_kraus_'):
94-
ks = cirq.kraus(val)
95-
assert len(ks) == 1
96-
assert np.all(ks[0] == np.eye(2))
97-
98-
9963
def test_mixture_returns_not_implemented():
10064
class ReturnsNotImplemented:
10165
def _mixture_(self):

0 commit comments

Comments
 (0)