From e630258c0a9014d4c331f886df821bb4a2294021 Mon Sep 17 00:00:00 2001 From: Edward Jiang Date: Thu, 10 Aug 2023 14:25:50 -0400 Subject: [PATCH 01/13] Allow new decorator syntax --- .../transforms/core/transform_dispatcher.py | 23 ++++++++++- .../test_transform_dispatcher.py | 39 +++++++++++++------ 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/pennylane/transforms/core/transform_dispatcher.py b/pennylane/transforms/core/transform_dispatcher.py index 867c728d6c7..ec02a063a50 100644 --- a/pennylane/transforms/core/transform_dispatcher.py +++ b/pennylane/transforms/core/transform_dispatcher.py @@ -15,6 +15,8 @@ This module contains the transform function, the transform dispatcher and the transform container. """ import copy +import warnings + import pennylane as qml @@ -68,10 +70,27 @@ def __call__(self, *targs, **tkwargs): if callable(obj): return self._qfunc_transform(obj, targs, tkwargs) - raise TransformError( - "The object on which the transform is applied is not valid. It can only be a tape, a QNode or a qfunc." + # Input is not a QNode nor a quantum tape nor a device. + # Assume Python decorator syntax: + # + # result = some_transform(*transform_args)(qnode)(*qnode_args) + + warnings.warn( + "The decorator syntax transform_fn(*transform_args)(qnode) has been " + "deprecated and will be removed in a future version. Please use either " + "transform_fn(qnode, *transform_args) or " + "functools.partial(transform_fn, *transform_args)(qnode) instead.", + UserWarning, ) + if obj is not None: + targs = (obj, *targs) + + def wrapper(obj): + return self(obj, *targs, **tkwargs) + + return wrapper + @property def transform(self): """Return the quantum transform.""" diff --git a/tests/transforms/test_experimental/test_transform_dispatcher.py b/tests/transforms/test_experimental/test_transform_dispatcher.py index 80de79dab37..9984d3e341a 100644 --- a/tests/transforms/test_experimental/test_transform_dispatcher.py +++ b/tests/transforms/test_experimental/test_transform_dispatcher.py @@ -174,7 +174,7 @@ def qnode_circuit(a): assert not dispatched_transform.is_informative @pytest.mark.parametrize("valid_transform", valid_transforms) - def test_integration_dispatcher_with_valid_transform_decorator(self, valid_transform): + def test_integration_dispatcher_with_valid_transform_decorator_partial(self, valid_transform): """Test that no error is raised with the transform function and that the transform dispatcher returns the right object.""" @@ -197,6 +197,32 @@ def qnode_circuit(a): qnode_circuit.transform_program.pop_front(), qml.transforms.core.TransformContainer ) + @pytest.mark.parametrize("valid_transform", valid_transforms) + def test_integration_dispatcher_with_valid_transform_decorator(self, valid_transform): + """Test that a warning is raised with the transform function and that the transform dispatcher returns + the right object.""" + + dispatched_transform = transform(valid_transform) + targs = [0] + + with pytest.warns(UserWarning, match="The decorator syntax"): + + @dispatched_transform(targs) + @qml.qnode(device=dev) + def qnode_circuit(a): + """QNode circuit.""" + qml.Hadamard(wires=0) + qml.CNOT(wires=[0, 1]) + qml.PauliX(wires=0) + qml.RZ(a, wires=1) + return qml.expval(qml.PauliZ(wires=0)) + + assert isinstance(qnode_circuit, qml.QNode) + assert isinstance(qnode_circuit.transform_program, qml.transforms.core.TransformProgram) + assert isinstance( + qnode_circuit.transform_program.pop_front(), qml.transforms.core.TransformContainer + ) + def test_queuing_qfunc_transform(self): """Test that queuing works with the transformed quantum function.""" @@ -339,17 +365,6 @@ def test_cotransform_not_implemented(self): ): transform(first_valid_transform, classical_cotransform=non_callable) - def test_apply_dispatched_transform_non_valid_obj(self): - """Test that applying a dispatched function on a non-valid object raises an error.""" - dispatched_transform = transform(first_valid_transform) - obj = qml.RX(0.1, wires=0) - with pytest.raises( - TransformError, - match="The object on which the transform is applied is not valid. It can only be a tape, a QNode or a " - "qfunc.", - ): - dispatched_transform(obj) - def test_qfunc_transform_multiple_tapes(self): """Test that quantum function is not compatible with multiple tapes.""" dispatched_transform = transform(second_valid_transform) From e1eb8fef85f6047469cb5ce790e29d1767a1e228 Mon Sep 17 00:00:00 2001 From: Edward Jiang Date: Thu, 10 Aug 2023 14:34:13 -0400 Subject: [PATCH 02/13] Add message for batch_transform too --- pennylane/transforms/batch_transform.py | 8 ++++++++ tests/transforms/test_batch_transform.py | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/pennylane/transforms/batch_transform.py b/pennylane/transforms/batch_transform.py index 53b9836d77a..ff153016c45 100644 --- a/pennylane/transforms/batch_transform.py +++ b/pennylane/transforms/batch_transform.py @@ -384,6 +384,14 @@ def _construct(args, kwargs): # ... # result = circuit(*qnode_args) + warnings.warn( + "The decorator syntax transform_fn(*transform_args)(qnode) has been " + "deprecated and will be removed in a future version. Please use either " + "transform_fn(qnode, *transform_args) or " + "functools.partial(transform_fn, *transform_args)(qnode) instead.", + UserWarning, + ) + # Prepend the input to the transform args, # and create a wrapper function. if qnode is not None: diff --git a/tests/transforms/test_batch_transform.py b/tests/transforms/test_batch_transform.py index b01e457a5b9..67d919df706 100644 --- a/tests/transforms/test_batch_transform.py +++ b/tests/transforms/test_batch_transform.py @@ -320,7 +320,8 @@ def test_parametrized_transform_tape_decorator(self): qml.expval(qml.PauliX(0)) tape = qml.tape.QuantumScript.from_queue(q) - tapes, _ = self.my_transform(a, b)(tape) # pylint: disable=no-value-for-parameter + with pytest.warns(UserWarning, match="The decorator syntax"): + tapes, _ = self.my_transform(a, b)(tape) # pylint: disable=no-value-for-parameter assert len(tapes[0].operations) == 2 assert tapes[0].operations[0].name == "Hadamard" @@ -372,7 +373,8 @@ def test_parametrized_transform_device_decorator(self, mocker): x = 0.543 dev = qml.device("default.qubit", wires=1) - dev = self.my_transform(a, b)(dev) # pylint: disable=no-value-for-parameter + with pytest.warns(UserWarning, match="The decorator syntax"): + dev = self.my_transform(a, b)(dev) # pylint: disable=no-value-for-parameter @qml.qnode(dev, interface="autograd") def circuit(x): @@ -441,12 +443,14 @@ def test_parametrized_transform_qnode_decorator(self, mocker): dev = qml.device("default.qubit", wires=2) - @self.my_transform(a, b) # pylint: disable=no-value-for-parameter - @qml.qnode(dev) - def circuit(x): - qml.Hadamard(wires=0) - qml.RX(x, wires=0) - return qml.expval(qml.PauliX(0)) + with pytest.warns(UserWarning, match="The decorator syntax"): + + @self.my_transform(a, b) # pylint: disable=no-value-for-parameter + @qml.qnode(dev) + def circuit(x): + qml.Hadamard(wires=0) + qml.RX(x, wires=0) + return qml.expval(qml.PauliX(0)) spy = mocker.spy(self.my_transform, "construct") res = circuit(x) From c5f5a41a2e1301299209d97403712d71688c4e7e Mon Sep 17 00:00:00 2001 From: Edward Jiang Date: Thu, 10 Aug 2023 14:42:52 -0400 Subject: [PATCH 03/13] Add to changelog and deprecations --- doc/development/deprecations.rst | 21 +++++++++++++++++++++ doc/releases/changelog-dev.md | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/doc/development/deprecations.rst b/doc/development/deprecations.rst index 7d2c59061cd..41142475b74 100644 --- a/doc/development/deprecations.rst +++ b/doc/development/deprecations.rst @@ -132,6 +132,27 @@ Pending deprecations - Deprecated in v0.32 - Will be removed in v0.33 +* The following decorator syntax for batch transforms has been deprecated: + + .. code-block:: python + + @transform_fn(*transform_args) + @qml.qnode(dev) + def circuit(): + ... + + Please call the batch transform directly using ``circuit = transform_fn(circuit, *transform_args)``, + or use ``functools.partial``: + + .. code-block:: python + + @functools.partial(transform_fn, *transform_args) + @qml.qnode(dev) + def circuit(): + ... + + - Deprecated in v0.32 + - Will be removed in v0.34 Completed deprecation cycles ---------------------------- diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index e908c8c0dc5..65b5b237036 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -245,6 +245,24 @@ array([False, False]) changes to operator equality and hashing. [(#4144)](https://github.com/PennyLaneAI/pennylane/pull/4144) +* The following decorator syntax for batch transforms has been deprecated and will raise a warning: + ```python + @transform_fn(*transform_args) + @qml.qnode(dev) + def circuit(): + ... + ``` + Please call the batch transform directly using `circuit = transform_fn(circuit, *transform_args)`, + or use `functools.partial`: + + ```python + @functools.partial(transform_fn, *transform_args) + @qml.qnode(dev) + def circuit(): + ... + ``` + []() +

Documentation 📝

* The `qml.pulse.transmon_interaction` and `qml.pulse.transmon_drive` documentation has been updated. From a9302dc51d9cf68050e776ae51285641d62bee11 Mon Sep 17 00:00:00 2001 From: Edward Jiang Date: Thu, 10 Aug 2023 15:18:30 -0400 Subject: [PATCH 04/13] Remove batch --- doc/development/deprecations.rst | 4 ++-- doc/releases/changelog-dev.md | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/doc/development/deprecations.rst b/doc/development/deprecations.rst index 41142475b74..df8df4eccfd 100644 --- a/doc/development/deprecations.rst +++ b/doc/development/deprecations.rst @@ -132,7 +132,7 @@ Pending deprecations - Deprecated in v0.32 - Will be removed in v0.33 -* The following decorator syntax for batch transforms has been deprecated: +* The following decorator syntax for transforms has been deprecated: .. code-block:: python @@ -141,7 +141,7 @@ Pending deprecations def circuit(): ... - Please call the batch transform directly using ``circuit = transform_fn(circuit, *transform_args)``, + Please call the transform directly using ``circuit = transform_fn(circuit, *transform_args)``, or use ``functools.partial``: .. code-block:: python diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index 65b5b237036..810a203250c 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -245,16 +245,15 @@ array([False, False]) changes to operator equality and hashing. [(#4144)](https://github.com/PennyLaneAI/pennylane/pull/4144) -* The following decorator syntax for batch transforms has been deprecated and will raise a warning: +* The following decorator syntax for transforms has been deprecated and will raise a warning: ```python @transform_fn(*transform_args) @qml.qnode(dev) def circuit(): ... ``` - Please call the batch transform directly using `circuit = transform_fn(circuit, *transform_args)`, + Please call the transform directly using `circuit = transform_fn(circuit, *transform_args)`, or use `functools.partial`: - ```python @functools.partial(transform_fn, *transform_args) @qml.qnode(dev) From 35de15bbbb0616e70697312d0827d35ef4727132 Mon Sep 17 00:00:00 2001 From: Edward Jiang <34989448+eddddddy@users.noreply.github.com> Date: Fri, 11 Aug 2023 11:09:14 -0400 Subject: [PATCH 05/13] Update doc/releases/changelog-dev.md Co-authored-by: Christina Lee --- doc/releases/changelog-dev.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index afbc33c160d..be21988cd87 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -264,7 +264,7 @@ array([False, False]) def circuit(): ... ``` - []() + [(#4457)](https://github.com/PennyLaneAI/pennylane/pull/4457/)

Documentation 📝

From 99458c1cc40516909004ca99a862d2492f5eed64 Mon Sep 17 00:00:00 2001 From: Edward Jiang Date: Fri, 11 Aug 2023 12:57:19 -0400 Subject: [PATCH 06/13] doc changes --- doc/development/deprecations.rst | 8 +++++--- doc/releases/changelog-dev.md | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/doc/development/deprecations.rst b/doc/development/deprecations.rst index df8df4eccfd..ebbe582ff93 100644 --- a/doc/development/deprecations.rst +++ b/doc/development/deprecations.rst @@ -141,12 +141,14 @@ Pending deprecations def circuit(): ... - Please call the transform directly using ``circuit = transform_fn(circuit, *transform_args)``, - or use ``functools.partial``: + If you are using a transform that has supporting ``transform_args``, please call the + transform directly using ``circuit = transform_fn(circuit, *transform_args)``. + Alternatively, use ``functools.partial``, in which case all arguments must be converted + to keyword arguments: .. code-block:: python - @functools.partial(transform_fn, *transform_args) + @functools.partial(transform_fn, **transform_kwargs) @qml.qnode(dev) def circuit(): ... diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index be21988cd87..d2f357094fd 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -256,10 +256,12 @@ array([False, False]) def circuit(): ... ``` - Please call the transform directly using `circuit = transform_fn(circuit, *transform_args)`, - or use `functools.partial`: + If you are using a transform that has supporting `transform_args`, please call the + transform directly using `circuit = transform_fn(circuit, *transform_args)`. + Alternatively, use `functools.partial`, in which case all arguments must be converted + to keyword arguments: ```python - @functools.partial(transform_fn, *transform_args) + @functools.partial(transform_fn, **transform_kwargs) @qml.qnode(dev) def circuit(): ... From c00474f77332664d1f5ed66f6b625bda1f5dc02c Mon Sep 17 00:00:00 2001 From: Edward Jiang Date: Fri, 11 Aug 2023 13:04:07 -0400 Subject: [PATCH 07/13] docstring for wrapper --- pennylane/transforms/core/transform_dispatcher.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pennylane/transforms/core/transform_dispatcher.py b/pennylane/transforms/core/transform_dispatcher.py index ec02a063a50..c62e4db1253 100644 --- a/pennylane/transforms/core/transform_dispatcher.py +++ b/pennylane/transforms/core/transform_dispatcher.py @@ -87,6 +87,7 @@ def __call__(self, *targs, **tkwargs): targs = (obj, *targs) def wrapper(obj): + f"""Partial of transform {self} with bound arguments and keyword arguments.""" return self(obj, *targs, **tkwargs) return wrapper From 3b3c46149755c79b6f8fafa2af5bdf9ea09ce67c Mon Sep 17 00:00:00 2001 From: Edward Jiang Date: Fri, 11 Aug 2023 13:15:17 -0400 Subject: [PATCH 08/13] fix docstring --- pennylane/transforms/core/transform_dispatcher.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pennylane/transforms/core/transform_dispatcher.py b/pennylane/transforms/core/transform_dispatcher.py index c62e4db1253..aea9aa8610e 100644 --- a/pennylane/transforms/core/transform_dispatcher.py +++ b/pennylane/transforms/core/transform_dispatcher.py @@ -87,9 +87,10 @@ def __call__(self, *targs, **tkwargs): targs = (obj, *targs) def wrapper(obj): - f"""Partial of transform {self} with bound arguments and keyword arguments.""" return self(obj, *targs, **tkwargs) + wrapper.__doc__ = f"Partial of transform {self} with bound arguments and keyword arguments." + return wrapper @property From b250857376ac598d016a639e0acaa6357f9ec6de Mon Sep 17 00:00:00 2001 From: Edward Jiang Date: Fri, 11 Aug 2023 15:17:22 -0400 Subject: [PATCH 09/13] make doc say transform --- pennylane/transforms/core/transform_dispatcher.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pennylane/transforms/core/transform_dispatcher.py b/pennylane/transforms/core/transform_dispatcher.py index aea9aa8610e..dfe6f863bb0 100644 --- a/pennylane/transforms/core/transform_dispatcher.py +++ b/pennylane/transforms/core/transform_dispatcher.py @@ -89,7 +89,9 @@ def __call__(self, *targs, **tkwargs): def wrapper(obj): return self(obj, *targs, **tkwargs) - wrapper.__doc__ = f"Partial of transform {self} with bound arguments and keyword arguments." + wrapper.__doc__ = ( + f"Partial of transform {self._transform} with bound arguments and keyword arguments." + ) return wrapper From ab6b2fb6f4ade1a55a4d4975eedd1d4b8e97db22 Mon Sep 17 00:00:00 2001 From: Edward Jiang Date: Fri, 11 Aug 2023 15:24:00 -0400 Subject: [PATCH 10/13] use kwargs everywhere instead of args --- doc/development/deprecations.rst | 9 ++++----- doc/releases/changelog-dev.md | 9 ++++----- pennylane/transforms/batch_transform.py | 6 +++--- pennylane/transforms/core/transform_dispatcher.py | 6 +++--- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/doc/development/deprecations.rst b/doc/development/deprecations.rst index ebbe582ff93..1e52d6d018a 100644 --- a/doc/development/deprecations.rst +++ b/doc/development/deprecations.rst @@ -136,15 +136,14 @@ Pending deprecations .. code-block:: python - @transform_fn(*transform_args) + @transform_fn(**transform_kwargs) @qml.qnode(dev) def circuit(): ... - If you are using a transform that has supporting ``transform_args``, please call the - transform directly using ``circuit = transform_fn(circuit, *transform_args)``. - Alternatively, use ``functools.partial``, in which case all arguments must be converted - to keyword arguments: + If you are using a transform that has supporting ``transform_kwargs``, please call the + transform directly using ``circuit = transform_fn(circuit, **transform_kwargs)``, + or use ``functools.partial``: .. code-block:: python diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index d2f357094fd..a6c9bd1dad0 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -251,15 +251,14 @@ array([False, False]) * The following decorator syntax for transforms has been deprecated and will raise a warning: ```python - @transform_fn(*transform_args) + @transform_fn(**transform_kwargs) @qml.qnode(dev) def circuit(): ... ``` - If you are using a transform that has supporting `transform_args`, please call the - transform directly using `circuit = transform_fn(circuit, *transform_args)`. - Alternatively, use `functools.partial`, in which case all arguments must be converted - to keyword arguments: + If you are using a transform that has supporting `transform_kwargs`, please call the + transform directly using `circuit = transform_fn(circuit, **transform_kwargs)`, + or use `functools.partial`: ```python @functools.partial(transform_fn, **transform_kwargs) @qml.qnode(dev) diff --git a/pennylane/transforms/batch_transform.py b/pennylane/transforms/batch_transform.py index ff153016c45..239dd852c29 100644 --- a/pennylane/transforms/batch_transform.py +++ b/pennylane/transforms/batch_transform.py @@ -385,10 +385,10 @@ def _construct(args, kwargs): # result = circuit(*qnode_args) warnings.warn( - "The decorator syntax transform_fn(*transform_args)(qnode) has been " + "The decorator syntax transform_fn(**transform_kwargs)(qnode) has been " "deprecated and will be removed in a future version. Please use either " - "transform_fn(qnode, *transform_args) or " - "functools.partial(transform_fn, *transform_args)(qnode) instead.", + "transform_fn(qnode, **transform_kwargs) or " + "functools.partial(transform_fn, **transform_kwargs)(qnode) instead.", UserWarning, ) diff --git a/pennylane/transforms/core/transform_dispatcher.py b/pennylane/transforms/core/transform_dispatcher.py index dfe6f863bb0..d194d2f5b39 100644 --- a/pennylane/transforms/core/transform_dispatcher.py +++ b/pennylane/transforms/core/transform_dispatcher.py @@ -76,10 +76,10 @@ def __call__(self, *targs, **tkwargs): # result = some_transform(*transform_args)(qnode)(*qnode_args) warnings.warn( - "The decorator syntax transform_fn(*transform_args)(qnode) has been " + "The decorator syntax transform_fn(**transform_kwargs)(qnode) has been " "deprecated and will be removed in a future version. Please use either " - "transform_fn(qnode, *transform_args) or " - "functools.partial(transform_fn, *transform_args)(qnode) instead.", + "transform_fn(qnode, **transform_kwargs) or " + "functools.partial(transform_fn, **transform_kwargs)(qnode) instead.", UserWarning, ) From b13ee598c7a0c8797ca5574901a4f3ef8eaa8b07 Mon Sep 17 00:00:00 2001 From: Edward Jiang Date: Mon, 14 Aug 2023 10:17:22 -0400 Subject: [PATCH 11/13] Change warning message --- pennylane/transforms/batch_transform.py | 8 ++++---- pennylane/transforms/core/transform_dispatcher.py | 8 ++++---- tests/transforms/test_batch_transform.py | 6 +++--- .../test_experimental/test_transform_dispatcher.py | 3 ++- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pennylane/transforms/batch_transform.py b/pennylane/transforms/batch_transform.py index 239dd852c29..def8b9c5a2d 100644 --- a/pennylane/transforms/batch_transform.py +++ b/pennylane/transforms/batch_transform.py @@ -385,10 +385,10 @@ def _construct(args, kwargs): # result = circuit(*qnode_args) warnings.warn( - "The decorator syntax transform_fn(**transform_kwargs)(qnode) has been " - "deprecated and will be removed in a future version. Please use either " - "transform_fn(qnode, **transform_kwargs) or " - "functools.partial(transform_fn, **transform_kwargs)(qnode) instead.", + "Decorating a QNode with @transform_fn(**transform_kwargs) has been " + "deprecated and will be removed in a future version. Please decorate " + "with @functools.partial(transform_fn, **transform_kwargs) instead, " + "or call the transform directly using qnode = transform_fn(qnode, **transform_kwargs)", UserWarning, ) diff --git a/pennylane/transforms/core/transform_dispatcher.py b/pennylane/transforms/core/transform_dispatcher.py index d194d2f5b39..073eafe4fd9 100644 --- a/pennylane/transforms/core/transform_dispatcher.py +++ b/pennylane/transforms/core/transform_dispatcher.py @@ -76,10 +76,10 @@ def __call__(self, *targs, **tkwargs): # result = some_transform(*transform_args)(qnode)(*qnode_args) warnings.warn( - "The decorator syntax transform_fn(**transform_kwargs)(qnode) has been " - "deprecated and will be removed in a future version. Please use either " - "transform_fn(qnode, **transform_kwargs) or " - "functools.partial(transform_fn, **transform_kwargs)(qnode) instead.", + "Decorating a QNode with @transform_fn(**transform_kwargs) has been " + "deprecated and will be removed in a future version. Please decorate " + "with @functools.partial(transform_fn, **transform_kwargs) instead, " + "or call the transform directly using qnode = transform_fn(qnode, **transform_kwargs)", UserWarning, ) diff --git a/tests/transforms/test_batch_transform.py b/tests/transforms/test_batch_transform.py index 67d919df706..caf1a637ff9 100644 --- a/tests/transforms/test_batch_transform.py +++ b/tests/transforms/test_batch_transform.py @@ -320,7 +320,7 @@ def test_parametrized_transform_tape_decorator(self): qml.expval(qml.PauliX(0)) tape = qml.tape.QuantumScript.from_queue(q) - with pytest.warns(UserWarning, match="The decorator syntax"): + with pytest.warns(UserWarning, match="Decorating a QNode with"): tapes, _ = self.my_transform(a, b)(tape) # pylint: disable=no-value-for-parameter assert len(tapes[0].operations) == 2 @@ -373,7 +373,7 @@ def test_parametrized_transform_device_decorator(self, mocker): x = 0.543 dev = qml.device("default.qubit", wires=1) - with pytest.warns(UserWarning, match="The decorator syntax"): + with pytest.warns(UserWarning, match="Decorating a QNode with"): dev = self.my_transform(a, b)(dev) # pylint: disable=no-value-for-parameter @qml.qnode(dev, interface="autograd") @@ -443,7 +443,7 @@ def test_parametrized_transform_qnode_decorator(self, mocker): dev = qml.device("default.qubit", wires=2) - with pytest.warns(UserWarning, match="The decorator syntax"): + with pytest.warns(UserWarning, match="Decorating a QNode with"): @self.my_transform(a, b) # pylint: disable=no-value-for-parameter @qml.qnode(dev) diff --git a/tests/transforms/test_experimental/test_transform_dispatcher.py b/tests/transforms/test_experimental/test_transform_dispatcher.py index 9984d3e341a..43fe08e0f3f 100644 --- a/tests/transforms/test_experimental/test_transform_dispatcher.py +++ b/tests/transforms/test_experimental/test_transform_dispatcher.py @@ -205,7 +205,8 @@ def test_integration_dispatcher_with_valid_transform_decorator(self, valid_trans dispatched_transform = transform(valid_transform) targs = [0] - with pytest.warns(UserWarning, match="The decorator syntax"): + msg = r"Decorating a QNode with @transform_fn\(\*\*transform_kwargs\) has been deprecated" + with pytest.warns(UserWarning, match=msg): @dispatched_transform(targs) @qml.qnode(device=dev) From e45cdca80266fa3ca348b86d98eb69027720972c Mon Sep 17 00:00:00 2001 From: Edward Jiang Date: Mon, 14 Aug 2023 11:19:08 -0400 Subject: [PATCH 12/13] Revert warning for batch transforms --- pennylane/transforms/batch_transform.py | 8 -------- tests/transforms/test_batch_transform.py | 20 ++++++++------------ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/pennylane/transforms/batch_transform.py b/pennylane/transforms/batch_transform.py index def8b9c5a2d..53b9836d77a 100644 --- a/pennylane/transforms/batch_transform.py +++ b/pennylane/transforms/batch_transform.py @@ -384,14 +384,6 @@ def _construct(args, kwargs): # ... # result = circuit(*qnode_args) - warnings.warn( - "Decorating a QNode with @transform_fn(**transform_kwargs) has been " - "deprecated and will be removed in a future version. Please decorate " - "with @functools.partial(transform_fn, **transform_kwargs) instead, " - "or call the transform directly using qnode = transform_fn(qnode, **transform_kwargs)", - UserWarning, - ) - # Prepend the input to the transform args, # and create a wrapper function. if qnode is not None: diff --git a/tests/transforms/test_batch_transform.py b/tests/transforms/test_batch_transform.py index caf1a637ff9..b01e457a5b9 100644 --- a/tests/transforms/test_batch_transform.py +++ b/tests/transforms/test_batch_transform.py @@ -320,8 +320,7 @@ def test_parametrized_transform_tape_decorator(self): qml.expval(qml.PauliX(0)) tape = qml.tape.QuantumScript.from_queue(q) - with pytest.warns(UserWarning, match="Decorating a QNode with"): - tapes, _ = self.my_transform(a, b)(tape) # pylint: disable=no-value-for-parameter + tapes, _ = self.my_transform(a, b)(tape) # pylint: disable=no-value-for-parameter assert len(tapes[0].operations) == 2 assert tapes[0].operations[0].name == "Hadamard" @@ -373,8 +372,7 @@ def test_parametrized_transform_device_decorator(self, mocker): x = 0.543 dev = qml.device("default.qubit", wires=1) - with pytest.warns(UserWarning, match="Decorating a QNode with"): - dev = self.my_transform(a, b)(dev) # pylint: disable=no-value-for-parameter + dev = self.my_transform(a, b)(dev) # pylint: disable=no-value-for-parameter @qml.qnode(dev, interface="autograd") def circuit(x): @@ -443,14 +441,12 @@ def test_parametrized_transform_qnode_decorator(self, mocker): dev = qml.device("default.qubit", wires=2) - with pytest.warns(UserWarning, match="Decorating a QNode with"): - - @self.my_transform(a, b) # pylint: disable=no-value-for-parameter - @qml.qnode(dev) - def circuit(x): - qml.Hadamard(wires=0) - qml.RX(x, wires=0) - return qml.expval(qml.PauliX(0)) + @self.my_transform(a, b) # pylint: disable=no-value-for-parameter + @qml.qnode(dev) + def circuit(x): + qml.Hadamard(wires=0) + qml.RX(x, wires=0) + return qml.expval(qml.PauliX(0)) spy = mocker.spy(self.my_transform, "construct") res = circuit(x) From 992137d1405b330828c086fa0bdb5087c2f80a8b Mon Sep 17 00:00:00 2001 From: Edward Jiang <34989448+eddddddy@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:05:39 -0400 Subject: [PATCH 13/13] Update doc/development/deprecations.rst Co-authored-by: Romain Moyard --- doc/development/deprecations.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/development/deprecations.rst b/doc/development/deprecations.rst index 1e52d6d018a..81b80388f2b 100644 --- a/doc/development/deprecations.rst +++ b/doc/development/deprecations.rst @@ -152,7 +152,7 @@ Pending deprecations def circuit(): ... - - Deprecated in v0.32 + - Deprecated in v0.33 - Will be removed in v0.34 Completed deprecation cycles