Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
71 changes: 38 additions & 33 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,50 @@ Pending deprecations
- Deprecated in v0.43
- Will be removed in v0.44

* The boolean functions provided by ``pennylane.operation`` are deprecated. See below for alternate code to
use instead.
* Accessing ``lie_closure``, ``structure_constants`` and ``center`` via ``qml.pauli`` is deprecated. Top level import and usage is advised.

- Deprecated in v0.40
- Will be removed in v0.41

Completed removal of legacy operator arithmetic
-----------------------------------------------

In PennyLane v0.40, the legacy operator arithmetic system has been removed, and is fully replaced by the new
operator arithmetic functionality that was introduced in v0.36. Check out the :ref:`Updated operators <new_opmath>` page
for details on how to port your legacy code to the new system. The following functionality has been removed:

* In PennyLane v0.40, legacy operator arithmetic has been removed. This includes :func:`~pennylane.operation.enable_new_opmath`,
:func:`~pennylane.operation.disable_new_opmath`, :class:`~pennylane.ops.Hamiltonian`, and :class:`~pennylane.operation.Tensor`. Note
that ``qml.Hamiltonian`` will continue to dispatch to :class:`~pennylane.ops.LinearCombination`.

- Deprecated in v0.39
- Removed in v0.40

* :meth:`~pennylane.pauli.PauliSentence.hamiltonian` and :meth:`~pennylane.pauli.PauliWord.hamiltonian` has been removed. Instead, please use
:meth:`~pennylane.pauli.PauliSentence.operation` and :meth:`~pennylane.pauli.PauliWord.operation` respectively.

- Deprecated in v0.39
- Removed in v0.40

* :func:`pennylane.pauli.simplify` has been removed. Instead, please use :func:`pennylane.simplify` or :meth:`~pennylane.operation.Operator.simplify`.

- Deprecated in v0.39
- Removed in v0.40

Completed deprecation cycles
----------------------------

* The boolean functions provided by ``pennylane.operation`` are deprecated. See below for an example of alternative code to use.
These include ``not_tape``, ``has_gen``, ``has_grad_method``, ``has_multipar``, ``has_nopar``, ``has_unitary_gen``,
``is_measurement``, ``defines_diagonalizing_gates``, and ``gen_is_multi_term_hamiltonian``.

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

.. code-block:: python

from pennylane.operation import TermsUndefinedError, Operator

def not_tape(obj):
return not isinstance(obj, qml.tape.QuantumScript)

Expand Down Expand Up @@ -78,39 +112,11 @@ Pending deprecations
return False
try:
generator = obj.generator()
_, ops = generator.terms()
_, ops = generator.terms()
return len(ops) > 1
except TermsUndefinedError:
return False

Completed removal of legacy operator arithmetic
-----------------------------------------------

In PennyLane v0.40, the legacy operator arithmetic system has been removed, and is fully replaced by the new
operator arithmetic functionality that was introduced in v0.36. Check out the :ref:`Updated operators <new_opmath>` page
for details on how to port your legacy code to the new system. The following functionality has been removed:

* In PennyLane v0.40, legacy operator arithmetic has been removed. This includes :func:`~pennylane.operation.enable_new_opmath`,
:func:`~pennylane.operation.disable_new_opmath`, :class:`~pennylane.ops.Hamiltonian`, and :class:`~pennylane.operation.Tensor`. Note
that ``qml.Hamiltonian`` will continue to dispatch to :class:`~pennylane.ops.LinearCombination`.

- Deprecated in v0.39
- Removed in v0.40

* :meth:`~pennylane.pauli.PauliSentence.hamiltonian` and :meth:`~pennylane.pauli.PauliWord.hamiltonian` has been removed. Instead, please use
:meth:`~pennylane.pauli.PauliSentence.operation` and :meth:`~pennylane.pauli.PauliWord.operation` respectively.

- Deprecated in v0.39
- Removed in v0.40

* :func:`pennylane.pauli.simplify` has been removed. Instead, please use :func:`pennylane.simplify` or :meth:`~pennylane.operation.Operator.simplify`.

- Deprecated in v0.39
- Removed in v0.40

Completed deprecation cycles
----------------------------

* Accessing ``lie_closure``, ``structure_constants`` and ``center`` via ``qml.pauli`` is deprecated. Top level import and usage is advised. They now live in
the ``liealg`` module.

Expand All @@ -130,7 +136,6 @@ Completed deprecation cycles
.. code-block:: python

class MyObs(Operator):

is_hermitian = True

def queue(self, context=qml.QueuingManager):
Expand Down
7 changes: 7 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@

<h3>Breaking changes 💔</h3>

* The boolean functions provided in `qml.operation` are deprecated. See the
:doc:`deprecations page </development/deprecations>` for equivalent code to use instead. These
include `not_tape`, `has_gen`, `has_grad_method`, `has_multipar`, `has_nopar`, `has_unitary_gen`,
`is_measurement`, `defines_diagonalizing_gates`, and `gen_is_multi_term_hamiltonian`.
[(#7924)](https://github.com/PennyLaneAI/pennylane/pull/7924)

* Removed access for `lie_closure`, `structure_constants` and `center` via `qml.pauli`.
Top level import and usage is advised. The functions now live in the `liealg` module.

Expand All @@ -141,6 +147,7 @@
PennyLane now depends on the more general `Operator` interface instead. The
`Operator.is_hermitian` property can instead be used to check whether or not it is highly likely
that the operator instance is Hermitian.
[(#7927)](https://github.com/PennyLaneAI/pennylane/pull/7927)

* `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.
Expand Down
181 changes: 0 additions & 181 deletions pennylane/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,12 @@
:class:`~.BooleanFn`'s are functions of a single object that return ``True`` or ``False``.
The ``operation`` module provides the following:

.. warning::

All of the boolean functions in this module are currently deprecated. See the individual functions
for alternative code.

.. currentmodule:: pennylane.operation

.. autosummary::
:toctree: api

~defines_diagonalizing_gates
~gen_is_multi_term_hamiltonian
~has_gen
~has_grad_method
~has_multipar
~has_nopar
~has_unitary_gen
~is_measurement
~is_trainable
~not_tape

Other
~~~~~
Expand Down Expand Up @@ -228,7 +214,6 @@

import pennylane as qml
from pennylane import capture
from pennylane.exceptions import PennyLaneDeprecationWarning
from pennylane.math import expand_matrix, is_abstract
from pennylane.queuing import QueuingManager
from pennylane.typing import TensorLike
Expand Down Expand Up @@ -2386,119 +2371,6 @@ def operation_derivative(operation: Operation) -> TensorLike:
return 1j * generator @ operation.matrix()


@qml.BooleanFn
def not_tape(obj):
"""Returns ``True`` if the object is not a quantum tape.

.. warning::

**Deprecated**. Use ``not isinstance(obj, qml.tape.QuantumScript)`` instead.
"""
warnings.warn(
"not_tape is deprecated. Use ``not isinstance(obj, qml.tape.QuantumScript)`` instead.",
PennyLaneDeprecationWarning,
)
return not isinstance(obj, qml.tape.QuantumScript)


@qml.BooleanFn
def has_gen(obj):
"""Returns ``True`` if an operator has a generator defined.

.. warning::

**Deprecated**. Use ``obj.has_generator`` instead.
"""
warnings.warn(
"has_gen is deprecated. Use Operator.has_generator instead.", PennyLaneDeprecationWarning
)
if isinstance(obj, Operator):
return obj.has_generator
try:
obj.generator()
except (AttributeError, OperatorPropertyUndefined, GeneratorUndefinedError):
return False
return True


@qml.BooleanFn
def has_grad_method(obj):
"""Returns ``True`` if an operator has a grad_method defined.

.. warning::

**Deprecated**: Use ``obj.grad_method is not None`` instead.
"""
warnings.warn(
"has_grad_method is deprecated. Use obj.grad_method is not None instead. ",
PennyLaneDeprecationWarning,
)
return obj.grad_method is not None


@qml.BooleanFn
def has_multipar(obj):
"""Returns ``True`` if an operator has more than one parameter
according to ``num_params``.

.. warning::

**Deprecated**: Use ``obj.num_params > 1`` instead.
"""
warnings.warn(
"has_multipar is deprecated. Use obj.num_params > 1 instead.", PennyLaneDeprecationWarning
)
return obj.num_params > 1


@qml.BooleanFn
def has_nopar(obj):
"""Returns ``True`` if an operator has no parameters
according to ``num_params``.

.. warning::

**Deprecated**: Use ``obj.num_params == 0`` instead.
"""
warnings.warn(
"has_nopar is deprecated. Use obj.num_params == 0 instead.", PennyLaneDeprecationWarning
)
return obj.num_params == 0


@qml.BooleanFn
def has_unitary_gen(obj):
"""Returns ``True`` if an operator has a unitary_generator
according to the ``has_unitary_generator`` flag.

.. warning::

**Deprecated**: Use ``obj in qml.ops.qubit.attributes.has_unitary_gen`` insteaed.

"""
warnings.warn(
"has_unitary_gen is deprecated. Use `obj in qml.ops.qubit.attributes.has_unitary_generator` instead.",
PennyLaneDeprecationWarning,
)
# Linting check disabled as static analysis can misidentify qml.ops as the set instance qml.ops.qubit.ops
return obj in qml.ops.qubit.attributes.has_unitary_generator


@qml.BooleanFn
def is_measurement(obj):
"""Returns ``True`` if an operator is a ``MeasurementProcess`` instance.

.. warning::

**Deprecated**: Use ``isinstance(obj, qml.measurements.MeasurementProcess)`` instead.
"""
warnings.warn(
"is_measurement is deprecated. Use isinstance(obj, qml.measurements.MeasurementProcess) instead.",
PennyLaneDeprecationWarning,
)
return isinstance(obj, qml.measurements.MeasurementProcess)


@qml.BooleanFn
def is_trainable(obj):
"""Returns ``True`` if any of the parameters of an operator is trainable
Expand All @@ -2507,22 +2379,6 @@ def is_trainable(obj):
return any(qml.math.requires_grad(p) for p in obj.parameters)


@qml.BooleanFn
def defines_diagonalizing_gates(obj):
"""Returns ``True`` if an operator defines the diagonalizing gates.

.. warning::

**Deprecated:** Use ``obj.has_diagonalizing_gates`` instead.

"""
warnings.warn(
"defines_diagonalizing_gates is deprecated. Use obj.has_diagonalizing_gates instead.",
PennyLaneDeprecationWarning,
)
return obj.has_diagonalizing_gates


_gen_is_multi_term_hamiltonian_code = """
if not isinstance(obj, Operator) or not obj.has_generator:
return False
Expand All @@ -2535,43 +2391,6 @@ def defines_diagonalizing_gates(obj):
"""


@qml.BooleanFn
def gen_is_multi_term_hamiltonian(obj):
"""Returns ``True`` if an operator has a generator defined and it is a Hamiltonian
with more than one term.

.. warning::

**Deprecated**: Use the following code instead:

.. code-block:: python

def gen_is_multi_term_hamiltonian(obj):
if not isinstance(obj, Operator) or not obj.has_generator:
return False
try:
generator = obj.generator()
_, ops = generator.terms()
return len(ops) > 1
except TermsUndefinedError:
return False


"""
warnings.warn(
f"gen_is_multiterm_hamiltonian is deprecated. Use {_gen_is_multi_term_hamiltonian_code}",
PennyLaneDeprecationWarning,
)
if not isinstance(obj, Operator) or not obj.has_generator:
return False
try:
generator = obj.generator()
_, ops = generator.terms() # len(coeffs) can be weird sometimes
return len(ops) > 1
except TermsUndefinedError:
return False


def __getattr__(name):
"""To facilitate StatePrep rename"""
if name == "StatePrep":
Expand Down
Loading