Skip to content

Commit 94e4ee6

Browse files
authored
Remove the deprecated mutators in cirq/ops (#5201)
Removes all the deprecated mutators.
1 parent db78359 commit 94e4ee6

27 files changed

+10
-488
lines changed

cirq-core/cirq/ops/controlled_gate.py

-25
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import numpy as np
3030

3131
from cirq import protocols, value, _import
32-
from cirq._compat import deprecated
3332
from cirq.ops import raw_types, controlled_operation as cop, matrix_gates
3433
from cirq.type_workarounds import NotImplementedType
3534

@@ -121,38 +120,14 @@ def __init__(
121120
def control_qid_shape(self) -> Tuple[int, ...]:
122121
return self._control_qid_shape
123122

124-
@control_qid_shape.setter # type: ignore
125-
@deprecated(
126-
deadline="v0.15",
127-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
128-
)
129-
def control_qid_shape(self, control_qid_shape: Tuple[int, ...]):
130-
self._control_qid_shape = control_qid_shape
131-
132123
@property
133124
def control_values(self) -> Tuple[Tuple[int, ...], ...]:
134125
return self._control_values
135126

136-
@control_values.setter # type: ignore
137-
@deprecated(
138-
deadline="v0.15",
139-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
140-
)
141-
def control_values(self, control_values: Tuple[Tuple[int, ...], ...]):
142-
self._control_values = control_values
143-
144127
@property
145128
def sub_gate(self) -> 'cirq.Gate':
146129
return self._sub_gate
147130

148-
@sub_gate.setter # type: ignore
149-
@deprecated(
150-
deadline="v0.15",
151-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
152-
)
153-
def sub_gate(self, sub_gate: 'cirq.Gate'):
154-
self._sub_gate = sub_gate
155-
156131
def num_controls(self) -> int:
157132
return len(self.control_qid_shape)
158133

cirq-core/cirq/ops/controlled_gate_test.py

-13
Original file line numberDiff line numberDiff line change
@@ -597,16 +597,3 @@ def num_qubits(self) -> int:
597597
(0.25, cirq.unitary(cirq.CZ)),
598598
],
599599
)
600-
601-
602-
def test_setters_deprecated():
603-
gate = cirq.ControlledGate(cirq.Z)
604-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
605-
gate.sub_gate = cirq.X
606-
assert gate.sub_gate == cirq.X
607-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
608-
gate.control_qid_shape = (3, 3)
609-
assert gate.control_qid_shape == (3, 3)
610-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
611-
gate.control_values = ((3,), (3,))
612-
assert gate.control_values == ((3,), (3,))

cirq-core/cirq/ops/controlled_operation.py

+2-26
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
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+
15+
import itertools
1416
from typing import (
1517
AbstractSet,
1618
Any,
@@ -25,11 +27,9 @@
2527
TYPE_CHECKING,
2628
)
2729

28-
import itertools
2930
import numpy as np
3031

3132
from cirq import protocols, qis, value
32-
from cirq._compat import deprecated
3333
from cirq.ops import raw_types, gate_operation, controlled_gate, matrix_gates
3434
from cirq.type_workarounds import NotImplementedType
3535

@@ -77,38 +77,14 @@ def __init__(
7777
def controls(self) -> Tuple['cirq.Qid', ...]:
7878
return self._controls
7979

80-
@controls.setter # type: ignore
81-
@deprecated(
82-
deadline="v0.15",
83-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
84-
)
85-
def controls(self, controls: Tuple['cirq.Qid', ...]):
86-
self._controls = controls
87-
8880
@property
8981
def control_values(self) -> Tuple[Tuple[int, ...], ...]:
9082
return self._control_values
9183

92-
@control_values.setter # type: ignore
93-
@deprecated(
94-
deadline="v0.15",
95-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
96-
)
97-
def control_values(self, control_values: Tuple[Tuple[int, ...], ...]):
98-
self._control_values = control_values
99-
10084
@property
10185
def sub_operation(self) -> 'cirq.Operation':
10286
return self._sub_operation
10387

104-
@sub_operation.setter # type: ignore
105-
@deprecated(
106-
deadline="v0.15",
107-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
108-
)
109-
def sub_operation(self, sub_operation: 'cirq.Operation'):
110-
self._sub_operation = sub_operation
111-
11288
@property
11389
def gate(self) -> Optional['cirq.ControlledGate']:
11490
if self.sub_operation.gate is None:

cirq-core/cirq/ops/controlled_operation_test.py

-14
Original file line numberDiff line numberDiff line change
@@ -455,17 +455,3 @@ def with_qubits(self, *new_qubits):
455455
(0.25, cirq.unitary(cirq.CZ)),
456456
],
457457
)
458-
459-
460-
def test_setters_deprecated():
461-
q0, q1, q2 = cirq.LineQubit.range(3)
462-
op = cirq.ControlledOperation([q1], cirq.Z(q0))
463-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
464-
op.sub_operation = cirq.X(q0)
465-
assert op.sub_operation == cirq.X(q0)
466-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
467-
op.controls = (q2,)
468-
assert op.controls == (q2,)
469-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
470-
op.control_values = ((3,), (3,))
471-
assert op.control_values == ((3,), (3,))

cirq-core/cirq/ops/dense_pauli_string.py

+3-18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
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+
15+
import abc
1416
import numbers
1517
from typing import (
1618
AbstractSet,
@@ -29,13 +31,12 @@
2931
TypeVar,
3032
Union,
3133
)
32-
import abc
3334

3435
import numpy as np
3536
import sympy
3637

3738
from cirq import protocols, linalg, value
38-
from cirq._compat import deprecated, proper_repr
39+
from cirq._compat import proper_repr
3940
from cirq.ops import raw_types, identity, pauli_gates, global_phase_op, pauli_string
4041
from cirq.type_workarounds import NotImplementedType
4142

@@ -107,26 +108,10 @@ def __init__(
107108
def pauli_mask(self) -> np.ndarray:
108109
return self._pauli_mask
109110

110-
@pauli_mask.setter # type: ignore
111-
@deprecated(
112-
deadline="v0.15",
113-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
114-
)
115-
def pauli_mask(self, pauli_mask: np.ndarray):
116-
self._pauli_mask = pauli_mask
117-
118111
@property
119112
def coefficient(self) -> complex:
120113
return self._coefficient
121114

122-
@coefficient.setter # type: ignore
123-
@deprecated(
124-
deadline="v0.15",
125-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
126-
)
127-
def coefficient(self, coefficient: complex):
128-
self._coefficient = coefficient
129-
130115
def _json_dict_(self) -> Dict[str, Any]:
131116
return protocols.obj_to_dict_helper(self, ['pauli_mask', 'coefficient'])
132117

cirq-core/cirq/ops/dense_pauli_string_test.py

-11
Original file line numberDiff line numberDiff line change
@@ -660,14 +660,3 @@ def test_symbolic():
660660
assert p == cirq.MutableDensePauliString('XYZ', coefficient=t * r)
661661
p /= r
662662
assert p == cirq.MutableDensePauliString('XYZ', coefficient=t)
663-
664-
665-
def test_setters_deprecated():
666-
gate = cirq.DensePauliString('X')
667-
mask = np.array([0, 3, 1, 2], dtype=np.uint8)
668-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
669-
gate.pauli_mask = mask
670-
assert gate.pauli_mask is mask
671-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
672-
gate.coefficient = -1
673-
assert gate.coefficient == -1

cirq-core/cirq/ops/fourier_transform.py

-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import cirq
2121
from cirq import value, _compat
22-
from cirq._compat import deprecated
2322
from cirq.ops import raw_types
2423

2524

@@ -100,14 +99,6 @@ def __init__(self, *, num_qubits: int, exponent: Union[float, sympy.Basic]):
10099
def exponent(self) -> Union[float, sympy.Basic]:
101100
return self._exponent
102101

103-
@exponent.setter # type: ignore
104-
@deprecated(
105-
deadline="v0.15",
106-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
107-
)
108-
def exponent(self, exponent: Union[float, sympy.Basic]):
109-
self._exponent = exponent
110-
111102
def _json_dict_(self) -> Dict[str, Any]:
112103
return {
113104
'num_qubits': self._num_qubits,

cirq-core/cirq/ops/fourier_transform_test.py

-8
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,3 @@ def test_circuit_diagram():
170170
3: ───#4────#4───────
171171
""",
172172
)
173-
174-
175-
def test_setters_deprecated():
176-
gate = cirq.PhaseGradientGate(num_qubits=1, exponent=0.1)
177-
assert gate.exponent == 0.1
178-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
179-
gate.exponent = 0.2
180-
assert gate.exponent == 0.2

cirq-core/cirq/ops/fsim_gate.py

+1-57
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
import cirq
3232
from cirq import protocols, value
33-
from cirq._compat import deprecated, proper_repr
33+
from cirq._compat import proper_repr
3434
from cirq.ops import gate_features, raw_types
3535

3636

@@ -97,26 +97,10 @@ def __init__(self, theta: 'cirq.TParamVal', phi: 'cirq.TParamVal') -> None:
9797
def theta(self) -> 'cirq.TParamVal':
9898
return self._theta
9999

100-
@theta.setter # type: ignore
101-
@deprecated(
102-
deadline="v0.15",
103-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
104-
)
105-
def theta(self, theta: 'cirq.TParamVal'):
106-
self._theta = theta
107-
108100
@property
109101
def phi(self) -> 'cirq.TParamVal':
110102
return self._phi
111103

112-
@phi.setter # type: ignore
113-
@deprecated(
114-
deadline="v0.15",
115-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
116-
)
117-
def phi(self, phi: 'cirq.TParamVal'):
118-
self._phi = phi
119-
120104
def _num_qubits_(self) -> int:
121105
return 2
122106

@@ -303,62 +287,22 @@ def __init__(
303287
def theta(self) -> 'cirq.TParamVal':
304288
return self._theta
305289

306-
@theta.setter # type: ignore
307-
@deprecated(
308-
deadline="v0.15",
309-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
310-
)
311-
def theta(self, theta: 'cirq.TParamVal'):
312-
self._theta = theta
313-
314290
@property
315291
def zeta(self) -> 'cirq.TParamVal':
316292
return self._zeta
317293

318-
@zeta.setter # type: ignore
319-
@deprecated(
320-
deadline="v0.15",
321-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
322-
)
323-
def zeta(self, zeta: 'cirq.TParamVal'):
324-
self._zeta = zeta
325-
326294
@property
327295
def chi(self) -> 'cirq.TParamVal':
328296
return self._chi
329297

330-
@chi.setter # type: ignore
331-
@deprecated(
332-
deadline="v0.15",
333-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
334-
)
335-
def chi(self, chi: 'cirq.TParamVal'):
336-
self._chi = chi
337-
338298
@property
339299
def gamma(self) -> 'cirq.TParamVal':
340300
return self._gamma
341301

342-
@gamma.setter # type: ignore
343-
@deprecated(
344-
deadline="v0.15",
345-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
346-
)
347-
def gamma(self, gamma: 'cirq.TParamVal'):
348-
self._gamma = gamma
349-
350302
@property
351303
def phi(self) -> 'cirq.TParamVal':
352304
return self._phi
353305

354-
@phi.setter # type: ignore
355-
@deprecated(
356-
deadline="v0.15",
357-
fix="The mutators of this class are deprecated, instantiate a new object instead.",
358-
)
359-
def phi(self, phi: 'cirq.TParamVal'):
360-
self._phi = phi
361-
362306
@staticmethod
363307
def from_fsim_rz(
364308
theta: 'cirq.TParamVal',

cirq-core/cirq/ops/fsim_gate_test.py

-36
Original file line numberDiff line numberDiff line change
@@ -804,39 +804,3 @@ def test_phased_fsim_json_dict():
804804
'gamma': 0.78,
805805
'phi': 0.9,
806806
}
807-
808-
809-
def test_setters_deprecated():
810-
gate = cirq.FSimGate(0.1, 0.1)
811-
assert gate.theta == 0.1
812-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
813-
gate.theta = 0.2
814-
assert gate.theta == 0.2
815-
assert gate.phi == 0.1
816-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
817-
gate.phi = 0.2
818-
assert gate.phi == 0.2
819-
820-
821-
def test_phased_setters_deprecated():
822-
gate = cirq.PhasedFSimGate(0.1, 0.1, 0.1, 0.1, 0.1)
823-
assert gate.theta == 0.1
824-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
825-
gate.theta = 0.2
826-
assert gate.theta == 0.2
827-
assert gate.zeta == 0.1
828-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
829-
gate.zeta = 0.2
830-
assert gate.zeta == 0.2
831-
assert gate.chi == 0.1
832-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
833-
gate.chi = 0.2
834-
assert gate.chi == 0.2
835-
assert gate.gamma == 0.1
836-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
837-
gate.gamma = 0.2
838-
assert gate.gamma == 0.2
839-
assert gate.phi == 0.1
840-
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
841-
gate.phi = 0.2
842-
assert gate.phi == 0.2

0 commit comments

Comments
 (0)