|
232 | 232 |
|
233 | 233 | import pennylane as qml
|
234 | 234 | from pennylane.capture import ABCCaptureMeta, create_operator_primitive
|
| 235 | +from pennylane.exceptions import PennyLaneDeprecationWarning |
235 | 236 | from pennylane.math import expand_matrix
|
236 | 237 | from pennylane.queuing import QueuingManager
|
237 | 238 | from pennylane.typing import TensorLike
|
@@ -299,27 +300,38 @@ class ParameterFrequenciesUndefinedError(OperatorPropertyUndefined):
|
299 | 300 | # =============================================================================
|
300 | 301 |
|
301 | 302 |
|
302 |
| -class WiresEnum(IntEnum): |
| 303 | +class _WiresEnum(IntEnum): |
303 | 304 | """Integer enumeration class
|
304 | 305 | to represent the number of wires
|
305 | 306 | an operation acts on.
|
306 | 307 |
|
| 308 | + .. warning:: |
| 309 | +
|
| 310 | + This class is deprecated ``Operator.num_wires=None`` should now be used to indicate |
| 311 | + that an operator can exist on any number of wires. |
| 312 | +
|
307 | 313 | """
|
308 | 314 |
|
309 | 315 | AnyWires = -1
|
310 | 316 | """A enumeration that represents that an operator can act on any number of wires.
|
311 | 317 |
|
| 318 | + .. warning:: |
| 319 | +
|
| 320 | + ``AnyWires`` is deprecated ``Operator.num_wires=None`` should now be used to indicate |
| 321 | + that an operator can exist on any number of wires. |
| 322 | +
|
312 | 323 | """
|
313 | 324 |
|
314 | 325 | AllWires = -2
|
315 | 326 | """A enumeration that represents that an operator acts on all wires in the system.
|
316 | 327 |
|
| 328 | + .. warning:: |
317 | 329 |
|
318 |
| - """ |
| 330 | + ``AllWires`` is deprecated ``Operator.num_wires=None`` should now be used to indicate |
| 331 | + that an operator can exist on any number of wires. |
319 | 332 |
|
| 333 | + """ |
320 | 334 |
|
321 |
| -AnyWires = WiresEnum.AnyWires |
322 |
| -AllWires = WiresEnum.AllWires |
323 | 335 |
|
324 | 336 | # =============================================================================
|
325 | 337 | # Class property
|
@@ -971,7 +983,7 @@ def terms(self) -> tuple[list[TensorLike], list["Operation"]]: # pylint: disabl
|
971 | 983 | """
|
972 | 984 | raise TermsUndefinedError
|
973 | 985 |
|
974 |
| - num_wires: Optional[Union[int, WiresEnum]] = None |
| 986 | + num_wires: Optional[Union[int, _WiresEnum]] = None |
975 | 987 | """Number of wires the operator acts on."""
|
976 | 988 |
|
977 | 989 | @property
|
@@ -1135,7 +1147,7 @@ def __init__(
|
1135 | 1147 | self._wires: Wires = Wires(wires)
|
1136 | 1148 |
|
1137 | 1149 | # check that the number of wires given corresponds to required number
|
1138 |
| - if (self.num_wires is not None and not isinstance(self.num_wires, WiresEnum)) and len( |
| 1150 | + if (self.num_wires is not None and not isinstance(self.num_wires, _WiresEnum)) and len( |
1139 | 1151 | self._wires
|
1140 | 1152 | ) != self.num_wires:
|
1141 | 1153 | raise ValueError(
|
@@ -2475,6 +2487,27 @@ def gen_is_multi_term_hamiltonian(obj):
|
2475 | 2487 |
|
2476 | 2488 | def __getattr__(name):
|
2477 | 2489 | """To facilitate StatePrep rename"""
|
| 2490 | + if name == "AnyWires": |
| 2491 | + warnings.warn( |
| 2492 | + "AnyWires is deprecated and will be removed in v0.43. " |
| 2493 | + " If your operation accepts any number of wires, set num_wires=None instead.", |
| 2494 | + PennyLaneDeprecationWarning, |
| 2495 | + ) |
| 2496 | + return _WiresEnum.AllWires |
| 2497 | + if name == "AllWires": |
| 2498 | + warnings.warn( |
| 2499 | + "AllWires is deprecated and will be removed in v0.43. " |
| 2500 | + " If your operation accepts any number of wires, set num_wires=None instead.", |
| 2501 | + PennyLaneDeprecationWarning, |
| 2502 | + ) |
| 2503 | + return _WiresEnum.AllWires |
| 2504 | + if name == "WiresEnum": |
| 2505 | + warnings.warn( |
| 2506 | + "WiresEnum is deprecated and will be removed in v0.43. " |
| 2507 | + " If your operation accepts any number of wires, set num_wires=None instead.", |
| 2508 | + PennyLaneDeprecationWarning, |
| 2509 | + ) |
| 2510 | + return _WiresEnum |
2478 | 2511 | if name == "StatePrep":
|
2479 | 2512 | return StatePrepBase
|
2480 | 2513 | raise AttributeError(f"module 'pennylane.operation' has no attribute '{name}'")
|
0 commit comments