Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create a PL-specific deprecation warning #4814

Merged
merged 4 commits into from
Nov 10, 2023
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
3 changes: 3 additions & 0 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
Deprecations
============

All PennyLane deprecations will raise a ``qml.PennyLaneDeprecationWarning``. Pending and completed
deprecations are listed below.

Pending deprecations
--------------------

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

<h3>Deprecations 👋</h3>

* All deprecations now raise a `qml.PennyLaneDeprecationWarning` instead of a `UserWarning`.
[(#4814)](https://github.com/PennyLaneAI/pennylane/pull/4814)

* `QuantumScript.is_sampled` and `QuantumScript.all_sampled` are deprecated.
Users should now validate these properties manually.
[(#4773)](https://github.com/PennyLaneAI/pennylane/pull/4773)
Expand Down
4 changes: 4 additions & 0 deletions pennylane/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ class QuantumFunctionError(Exception):
"""Exception raised when an illegal operation is defined in a quantum function."""


class PennyLaneDeprecationWarning(UserWarning):
"""Warning raised when a PennyLane feature is being deprecated."""


def _get_device_entrypoints():
"""Returns a dictionary mapping the device short name to the
loadable entrypoint"""
Expand Down
4 changes: 2 additions & 2 deletions pennylane/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,7 @@ def return_type(self):
warnings.warn(
"`Observable.return_type` is deprecated. Instead, you should "
"inspect the type of the surrounding measurement process.",
UserWarning,
qml.PennyLaneDeprecationWarning,
)
return self._return_type

Expand All @@ -1893,7 +1893,7 @@ def return_type(self, value):
warnings.warn(
"`Observable.return_type` is deprecated. Instead, you should "
"create a measurement process containing this Observable.",
UserWarning,
qml.PennyLaneDeprecationWarning,
)
self._return_type = value

Expand Down
2 changes: 1 addition & 1 deletion pennylane/ops/functions/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _generator_backcompatibility(op):
"The Operator.generator property is deprecated. Please update the operator so that "
"\n\t1. Operator.generator() is a method, and"
"\n\t2. Operator.generator() returns an Operator instance representing the operator.",
UserWarning,
qml.PennyLaneDeprecationWarning,
)
gen = op.generator

Expand Down
2 changes: 1 addition & 1 deletion pennylane/ops/op_math/controlled.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def __init__(self, base, control_wires, control_values=None, work_wires=None, id
if isinstance(control_values, str):
warnings.warn(
"Specifying control values as a string is deprecated. Please use Sequence[Bool]",
UserWarning,
qml.PennyLaneDeprecationWarning,
)
# All values not 0 are cast as true. Assumes a string of 1s and 0s.
control_values = [(x != "0") for x in control_values]
Expand Down
4 changes: 2 additions & 2 deletions pennylane/tape/qscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def is_sampled(self) -> bool:
">>> from pennylane.measurements import *\n"
">>> sample_types = (SampleMP, CountsMP, ClassicalShadowMP, ShadowExpvalMP)\n"
">>> is_sampled = any(isinstance(m, sample_types) for m in tape.measurements)\n",
UserWarning,
qml.PennyLaneDeprecationWarning,
)
sample_type = (SampleMP, CountsMP, ClassicalShadowMP, ShadowExpvalMP)
return any(isinstance(m, sample_type) for m in self.measurements)
Expand All @@ -419,7 +419,7 @@ def all_sampled(self) -> bool:
">>> from pennylane.measurements import *\n"
">>> sample_types = (SampleMP, CountsMP, ClassicalShadowMP, ShadowExpvalMP)\n"
">>> all_sampled = all(isinstance(m, sample_types) for m in tape.measurements)\n",
UserWarning,
qml.PennyLaneDeprecationWarning,
)
sample_type = (SampleMP, CountsMP, ClassicalShadowMP, ShadowExpvalMP)
return all(isinstance(m, sample_type) for m in self.measurements)
Expand Down
6 changes: 3 additions & 3 deletions pennylane/transforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@
Old transforms framework
------------------------

These utility functions were previously used to create transforms in PennyLane and will be
deprecated soon. It is now recommended to use :class:`qml.transform <pennylane.transform>`
for creation of custom transforms.
These utility functions were previously used to create transforms in PennyLane and are now
deprecated. It is now recommended to use :class:`qml.transform <pennylane.transform>`
for the creation of custom transforms.

.. autosummary::
:toctree: api
Expand Down
2 changes: 1 addition & 1 deletion pennylane/transforms/batch_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def __init__(self, transform_fn, expand_fn=None, differentiable=True):
"Use of `batch_transform` to create a custom transform is deprecated. Instead "
"switch to using the new qml.transform function. Follow the instructions here for "
"further details: https://docs.pennylane.ai/en/stable/code/qml_transforms.html#custom-transforms.",
UserWarning,
qml.PennyLaneDeprecationWarning,
)
self.transform_fn = transform_fn
self.expand_fn = expand_fn
Expand Down
2 changes: 1 addition & 1 deletion pennylane/transforms/core/transform_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def processing_fn(results):
"or call the transform directly using qnode = transform_fn(qnode, "
"**transform_kwargs). Visit the deprecations page for more details: "
"https://docs.pennylane.ai/en/stable/development/deprecations.html",
UserWarning,
qml.PennyLaneDeprecationWarning,
)

if obj is not None:
Expand Down
2 changes: 1 addition & 1 deletion pennylane/transforms/op_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def __init__(self, fn):
"Use of `op_transform` to create a custom transform is deprecated. Instead "
"switch to using the new qml.transform function. Follow the instructions here for "
"further details: https://docs.pennylane.ai/en/stable/code/qml_transforms.html#custom-transforms.",
UserWarning,
qml.PennyLaneDeprecationWarning,
)
self._fn = fn
self._sig = inspect.signature(fn).parameters
Expand Down
6 changes: 3 additions & 3 deletions pennylane/transforms/qfunc_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def __init__(self, transform_fn):
"Use of `single_tape_transform` to create a custom transform is deprecated. Instead "
"switch to using the new qml.transform function. Follow the instructions here for "
"further details: https://docs.pennylane.ai/en/stable/code/qml_transforms.html#custom-transforms.",
UserWarning,
qml.PennyLaneDeprecationWarning,
)
self.transform_fn = transform_fn
functools.update_wrapper(self, transform_fn)
Expand Down Expand Up @@ -405,11 +405,11 @@ def new_qfunc(*args, **kwargs):
"Use of `qfunc_transform` to create a custom transform is deprecated. Instead "
"switch to using the new qml.transform function. Follow the instructions here for "
"further details: https://docs.pennylane.ai/en/stable/code/qml_transforms.html#custom-transforms.",
UserWarning,
qml.PennyLaneDeprecationWarning,
)
if not isinstance(tape_transform, single_tape_transform):
with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning)
warnings.simplefilter("ignore", qml.PennyLaneDeprecationWarning)
tape_transform = single_tape_transform(tape_transform)

sig = inspect.signature(tape_transform)
Expand Down
2 changes: 1 addition & 1 deletion pennylane/vqe/vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def __init__(
"ExpvalCost is deprecated, use qml.expval() instead. "
"For optimizing Hamiltonian measurements with measuring commuting "
"terms in parallel, use the grouping_type keyword in qml.Hamiltonian.",
UserWarning,
qml.PennyLaneDeprecationWarning,
)

if kwargs.get("measure", "expval") != "expval":
Expand Down
Loading