Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ Pending deprecations
- Deprecated in v0.42
- Will be removed in v0.43

* ``qml.operation.WiresEnum``, ``qml.operation.AllWires``, and ``qml.operation.AnyWires`` are deprecated. If an operation can act
on any number of wires ``Operator.num_wires = None`` should be used instead. This is the default, and does not need
to be overridden unless the operator developer wants to validate that the correct number of wires is passed.

- Deprecated in v0.42
- Will be removed in v0.43

* The boolean functions provided by ``pennylane.operation`` are deprecated. See below for alternate code to
use instead.
These include ``not_tape``, ``has_gen``, ``has_grad_method``, ``has_multipar``, ``has_nopar``, ``has_unitary_gen``,
Expand Down Expand Up @@ -137,6 +130,13 @@ for details on how to port your legacy code to the new system. The following fun
Completed deprecation cycles
----------------------------

* ``qml.operation.WiresEnum``, ``qml.operation.AllWires``, and ``qml.operation.AnyWires`` are deprecated. If an operation can act
on any number of wires ``Operator.num_wires = None`` should be used instead. This is the default, and does not need
to be overridden unless the operator developer wants to validate that the correct number of wires is passed.

- Deprecated in v0.42
- Removed in v0.43

* Top-level access to ``DeviceError``, ``PennyLaneDeprecationWarning``, ``QuantumFunctionError`` and ``ExperimentalWarning``
is now removed in v0.43. Please import these objects from the new ``pennylane.exceptions`` module.

Expand Down
4 changes: 4 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@

<h3>Breaking changes 💔</h3>

* `qml.operation.WiresEnum`, `qml.operation.AllWires`, and `qml.operation.AnyWires` have been removed. Setting `Operator.num_wires = None` (the default)
should instead indicate that the `Operator` does not need wire validation.
[(#7911)](https://github.com/PennyLaneAI/pennylane/pull/7911)

* Top-level access to ``DeviceError``, ``PennyLaneDeprecationWarning``, ``QuantumFunctionError`` and ``ExperimentalWarning`` has been removed. Please import these objects from the new ``pennylane.exceptions`` module.
[(#7874)](https://github.com/PennyLaneAI/pennylane/pull/7874)

Expand Down
66 changes: 2 additions & 64 deletions pennylane/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@
import copy
import warnings
from collections.abc import Hashable, Iterable
from enum import IntEnum
from functools import lru_cache
from typing import Any, Callable, Literal, Optional, Type, Union

Expand Down Expand Up @@ -300,44 +299,6 @@ class ParameterFrequenciesUndefinedError(OperatorPropertyUndefined):
does not have parameter_frequencies"""


# =============================================================================
# Wire types
# =============================================================================


class _WiresEnum(IntEnum):
"""Integer enumeration class
to represent the number of wires
an operation acts on.

.. warning::

This class is deprecated ``Operator.num_wires=None`` should now be used to indicate
that an operator can exist on any number of wires.

"""

AnyWires = -1
"""A enumeration that represents that an operator can act on any number of wires.

.. warning::

``AnyWires`` is deprecated ``Operator.num_wires=None`` should now be used to indicate
that an operator can exist on any number of wires.

"""

AllWires = -2
"""A enumeration that represents that an operator acts on all wires in the system.

.. warning::

``AllWires`` is deprecated ``Operator.num_wires=None`` should now be used to indicate
that an operator can exist on any number of wires.

"""


# =============================================================================
# Class property
# =============================================================================
Expand Down Expand Up @@ -1087,7 +1048,7 @@ def terms(self) -> tuple[list[TensorLike], list["Operation"]]: # pylint: disabl
"""
raise TermsUndefinedError

num_wires: Optional[Union[int, _WiresEnum]] = None
num_wires: None | int = None
"""Number of wires the operator acts on."""

@property
Expand Down Expand Up @@ -1250,9 +1211,7 @@ def __init__(
self._wires: Wires = Wires(wires)

# check that the number of wires given corresponds to required number
if (self.num_wires is not None and not isinstance(self.num_wires, _WiresEnum)) and len(
self._wires
) != self.num_wires:
if (self.num_wires is not None) and len(self._wires) != self.num_wires:
raise ValueError(
f"{self.name}: wrong number of wires. "
f"{len(self._wires)} wires given, {self.num_wires} expected."
Expand Down Expand Up @@ -2627,27 +2586,6 @@ def __getattr__(name):
PennyLaneDeprecationWarning,
)
return Observable
if name == "AnyWires":
warnings.warn(
"AnyWires is deprecated and will be removed in v0.43. "
" If your operation accepts any number of wires, set num_wires=None instead.",
PennyLaneDeprecationWarning,
)
return _WiresEnum.AllWires
if name == "AllWires":
warnings.warn(
"AllWires is deprecated and will be removed in v0.43. "
" If your operation accepts any number of wires, set num_wires=None instead.",
PennyLaneDeprecationWarning,
)
return _WiresEnum.AllWires
if name == "WiresEnum":
warnings.warn(
"WiresEnum is deprecated and will be removed in v0.43. "
" If your operation accepts any number of wires, set num_wires=None instead.",
PennyLaneDeprecationWarning,
)
return _WiresEnum
if name == "StatePrep":
return StatePrepBase
raise AttributeError(f"module 'pennylane.operation' has no attribute '{name}'")
14 changes: 0 additions & 14 deletions tests/test_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import pennylane as qml
from pennylane import numpy as pnp
from pennylane.exceptions import PennyLaneDeprecationWarning
from pennylane.operation import (
_UNSET_BATCH_SIZE,
Operation,
Expand All @@ -42,19 +41,6 @@
I_broadcasted = I[pnp.newaxis]


def test_wires_enum_deprecation():
"""Test that WiresEnum, AllWires, and AnyWires are deprecated."""

with pytest.warns(PennyLaneDeprecationWarning, match="is deprecated"):
_ = qml.operation.WiresEnum

with pytest.warns(PennyLaneDeprecationWarning, match="is deprecated"):
_ = qml.operation.AllWires

with pytest.warns(PennyLaneDeprecationWarning, match="is deprecated"):
_ = qml.operation.AnyWires


class TestOperatorConstruction:
"""Test custom operators' construction."""

Expand Down
Loading