Skip to content

Commit

Permalink
Remove the deprecated mutators in cirq/ops (quantumlib#5201)
Browse files Browse the repository at this point in the history
Removes all the deprecated mutators.
  • Loading branch information
daxfohl authored and tonybruguier committed Apr 14, 2022
1 parent 65676a3 commit 95d5970
Show file tree
Hide file tree
Showing 27 changed files with 10 additions and 488 deletions.
25 changes: 0 additions & 25 deletions cirq-core/cirq/ops/controlled_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import numpy as np

from cirq import protocols, value, _import
from cirq._compat import deprecated
from cirq.ops import raw_types, controlled_operation as cop, matrix_gates
from cirq.type_workarounds import NotImplementedType

Expand Down Expand Up @@ -121,38 +120,14 @@ def __init__(
def control_qid_shape(self) -> Tuple[int, ...]:
return self._control_qid_shape

@control_qid_shape.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def control_qid_shape(self, control_qid_shape: Tuple[int, ...]):
self._control_qid_shape = control_qid_shape

@property
def control_values(self) -> Tuple[Tuple[int, ...], ...]:
return self._control_values

@control_values.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def control_values(self, control_values: Tuple[Tuple[int, ...], ...]):
self._control_values = control_values

@property
def sub_gate(self) -> 'cirq.Gate':
return self._sub_gate

@sub_gate.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def sub_gate(self, sub_gate: 'cirq.Gate'):
self._sub_gate = sub_gate

def num_controls(self) -> int:
return len(self.control_qid_shape)

Expand Down
13 changes: 0 additions & 13 deletions cirq-core/cirq/ops/controlled_gate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,16 +597,3 @@ def num_qubits(self) -> int:
(0.25, cirq.unitary(cirq.CZ)),
],
)


def test_setters_deprecated():
gate = cirq.ControlledGate(cirq.Z)
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
gate.sub_gate = cirq.X
assert gate.sub_gate == cirq.X
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
gate.control_qid_shape = (3, 3)
assert gate.control_qid_shape == (3, 3)
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
gate.control_values = ((3,), (3,))
assert gate.control_values == ((3,), (3,))
28 changes: 2 additions & 26 deletions cirq-core/cirq/ops/controlled_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import itertools
from typing import (
AbstractSet,
Any,
Expand All @@ -25,11 +27,9 @@
TYPE_CHECKING,
)

import itertools
import numpy as np

from cirq import protocols, qis, value
from cirq._compat import deprecated
from cirq.ops import raw_types, gate_operation, controlled_gate, matrix_gates
from cirq.type_workarounds import NotImplementedType

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

@controls.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def controls(self, controls: Tuple['cirq.Qid', ...]):
self._controls = controls

@property
def control_values(self) -> Tuple[Tuple[int, ...], ...]:
return self._control_values

@control_values.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def control_values(self, control_values: Tuple[Tuple[int, ...], ...]):
self._control_values = control_values

@property
def sub_operation(self) -> 'cirq.Operation':
return self._sub_operation

@sub_operation.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def sub_operation(self, sub_operation: 'cirq.Operation'):
self._sub_operation = sub_operation

@property
def gate(self) -> Optional['cirq.ControlledGate']:
if self.sub_operation.gate is None:
Expand Down
14 changes: 0 additions & 14 deletions cirq-core/cirq/ops/controlled_operation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,3 @@ def with_qubits(self, *new_qubits):
(0.25, cirq.unitary(cirq.CZ)),
],
)


def test_setters_deprecated():
q0, q1, q2 = cirq.LineQubit.range(3)
op = cirq.ControlledOperation([q1], cirq.Z(q0))
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
op.sub_operation = cirq.X(q0)
assert op.sub_operation == cirq.X(q0)
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
op.controls = (q2,)
assert op.controls == (q2,)
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
op.control_values = ((3,), (3,))
assert op.control_values == ((3,), (3,))
21 changes: 3 additions & 18 deletions cirq-core/cirq/ops/dense_pauli_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import abc
import numbers
from typing import (
AbstractSet,
Expand All @@ -29,13 +31,12 @@
TypeVar,
Union,
)
import abc

import numpy as np
import sympy

from cirq import protocols, linalg, value
from cirq._compat import deprecated, proper_repr
from cirq._compat import proper_repr
from cirq.ops import raw_types, identity, pauli_gates, global_phase_op, pauli_string
from cirq.type_workarounds import NotImplementedType

Expand Down Expand Up @@ -107,26 +108,10 @@ def __init__(
def pauli_mask(self) -> np.ndarray:
return self._pauli_mask

@pauli_mask.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def pauli_mask(self, pauli_mask: np.ndarray):
self._pauli_mask = pauli_mask

@property
def coefficient(self) -> complex:
return self._coefficient

@coefficient.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def coefficient(self, coefficient: complex):
self._coefficient = coefficient

def _json_dict_(self) -> Dict[str, Any]:
return protocols.obj_to_dict_helper(self, ['pauli_mask', 'coefficient'])

Expand Down
11 changes: 0 additions & 11 deletions cirq-core/cirq/ops/dense_pauli_string_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,14 +660,3 @@ def test_symbolic():
assert p == cirq.MutableDensePauliString('XYZ', coefficient=t * r)
p /= r
assert p == cirq.MutableDensePauliString('XYZ', coefficient=t)


def test_setters_deprecated():
gate = cirq.DensePauliString('X')
mask = np.array([0, 3, 1, 2], dtype=np.uint8)
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
gate.pauli_mask = mask
assert gate.pauli_mask is mask
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
gate.coefficient = -1
assert gate.coefficient == -1
9 changes: 0 additions & 9 deletions cirq-core/cirq/ops/fourier_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

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


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

@exponent.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def exponent(self, exponent: Union[float, sympy.Basic]):
self._exponent = exponent

def _json_dict_(self) -> Dict[str, Any]:
return {
'num_qubits': self._num_qubits,
Expand Down
8 changes: 0 additions & 8 deletions cirq-core/cirq/ops/fourier_transform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,3 @@ def test_circuit_diagram():
3: ───#4────#4───────
""",
)


def test_setters_deprecated():
gate = cirq.PhaseGradientGate(num_qubits=1, exponent=0.1)
assert gate.exponent == 0.1
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
gate.exponent = 0.2
assert gate.exponent == 0.2
58 changes: 1 addition & 57 deletions cirq-core/cirq/ops/fsim_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import cirq
from cirq import protocols, value
from cirq._compat import deprecated, proper_repr
from cirq._compat import proper_repr
from cirq.ops import gate_features, raw_types


Expand Down Expand Up @@ -97,26 +97,10 @@ def __init__(self, theta: 'cirq.TParamVal', phi: 'cirq.TParamVal') -> None:
def theta(self) -> 'cirq.TParamVal':
return self._theta

@theta.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def theta(self, theta: 'cirq.TParamVal'):
self._theta = theta

@property
def phi(self) -> 'cirq.TParamVal':
return self._phi

@phi.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def phi(self, phi: 'cirq.TParamVal'):
self._phi = phi

def _num_qubits_(self) -> int:
return 2

Expand Down Expand Up @@ -303,62 +287,22 @@ def __init__(
def theta(self) -> 'cirq.TParamVal':
return self._theta

@theta.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def theta(self, theta: 'cirq.TParamVal'):
self._theta = theta

@property
def zeta(self) -> 'cirq.TParamVal':
return self._zeta

@zeta.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def zeta(self, zeta: 'cirq.TParamVal'):
self._zeta = zeta

@property
def chi(self) -> 'cirq.TParamVal':
return self._chi

@chi.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def chi(self, chi: 'cirq.TParamVal'):
self._chi = chi

@property
def gamma(self) -> 'cirq.TParamVal':
return self._gamma

@gamma.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def gamma(self, gamma: 'cirq.TParamVal'):
self._gamma = gamma

@property
def phi(self) -> 'cirq.TParamVal':
return self._phi

@phi.setter # type: ignore
@deprecated(
deadline="v0.15",
fix="The mutators of this class are deprecated, instantiate a new object instead.",
)
def phi(self, phi: 'cirq.TParamVal'):
self._phi = phi

@staticmethod
def from_fsim_rz(
theta: 'cirq.TParamVal',
Expand Down
36 changes: 0 additions & 36 deletions cirq-core/cirq/ops/fsim_gate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,39 +804,3 @@ def test_phased_fsim_json_dict():
'gamma': 0.78,
'phi': 0.9,
}


def test_setters_deprecated():
gate = cirq.FSimGate(0.1, 0.1)
assert gate.theta == 0.1
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
gate.theta = 0.2
assert gate.theta == 0.2
assert gate.phi == 0.1
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
gate.phi = 0.2
assert gate.phi == 0.2


def test_phased_setters_deprecated():
gate = cirq.PhasedFSimGate(0.1, 0.1, 0.1, 0.1, 0.1)
assert gate.theta == 0.1
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
gate.theta = 0.2
assert gate.theta == 0.2
assert gate.zeta == 0.1
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
gate.zeta = 0.2
assert gate.zeta == 0.2
assert gate.chi == 0.1
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
gate.chi = 0.2
assert gate.chi == 0.2
assert gate.gamma == 0.1
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
gate.gamma = 0.2
assert gate.gamma == 0.2
assert gate.phi == 0.1
with cirq.testing.assert_deprecated('mutators', deadline='v0.15'):
gate.phi = 0.2
assert gate.phi == 0.2
Loading

0 comments on commit 95d5970

Please sign in to comment.