Repository: PennyLaneAI/pennylane
Pull request #5984 (2024-07-10 22:06:13)

deprecate arguments of execute function
**Context:**

deprecate the following arguments from the`qml.execute` function as part of the 0.38 deprecations cycle.

- `expand_fn`: Specifying it allows the user to not do the preprocessing and validation the device said needed to be done. This is dangerous, and could lead to incorrect results or unmanaged errors.
- `max_expansion`: It allows users to not reach the required target gateset of the device, potentially leading to incorrect results or unmanaged errors.
- `override_shots`: Setting the shots on the tape(s) to be executed provides greater control and flexibility.
- `device_batch_transform`:  Setting `device_batch_transform=False` opens up the user to submitting something unvalidated and unsupported to the device.

**Description of the Change:**

Several argument in ``qml.execute`` have been deprecated. 

[sc-67226]
[sc-67230]
[sc-67225]
[sc-67224]

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/5984?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 99.65%. Comparing base [(`6d0a528`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/6d0a528f8797cc60422d48e00ad0168ca14c5c3f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) to head [(`e32d8f6`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/e32d8f68474d887ed8bfded01c0ffdc11a3a2f16?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).
> Report is 3 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #5984      +/-   ##
==========================================
- Coverage   99.67%   99.65%   -0.03%     
==========================================
  Files         426      425       -1     
  Lines       40924    40683     -241     
==========================================
- Hits        40791    40541     -250     
- Misses        133      142       +9     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/5984?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).

EmilianoG-byte: @trbromley do you think this is ready to be merged? :) 
EmilianoG-byte: > Thanks @EmilianoG-byte, this looks great! We just need a second code reviewer - @Alex-Preciado, any suggestions?

We have asked @PietropaoloFrisoni, thank you @trbromley!

Patch:
diff --git a/doc/development/deprecations.rst b/doc/development/deprecations.rst
index 43b1bd050..05e50b93b 100644
--- a/doc/development/deprecations.rst
+++ b/doc/development/deprecations.rst
@@ -9,6 +9,30 @@ deprecations are listed below.
 Pending deprecations
 --------------------
 
+* The ``expand_fn`` argument in ``qml.execute`` is deprecated. 
+  Instead, please create a ``qml.transforms.core.TransformProgram`` with the desired preprocessing and pass it to the ``transform_program`` argument of ``qml.execute``.
+
+  - Deprecated in v0.38
+  - Will be removed in v0.39
+
+* The ``max_expansion`` argument in ``qml.execute`` is deprecated. 
+  Instead, please use ``qml.devices.preprocess.decompose`` with the desired expansion level, add it to a ``TransformProgram``, and pass it to the ``transform_program`` argument of ``qml.execute``.
+
+  - Deprecated in v0.38
+  - Will be removed in v0.39
+
+* The ``override_shots`` argument in ``qml.execute`` is deprecated. 
+  Instead, please add the shots to the ``QuantumTape``'s to be executed.
+
+  - Deprecated in v0.38
+  - Will be removed in v0.39
+
+* The ``device_batch_transform`` argument in ``qml.execute`` is deprecated. 
+  Instead, please create a ``qml.transforms.core.TransformProgram`` with the desired preprocessing and pass it to the ``transform_program`` argument of ``qml.execute``.
+
+  - Deprecated in v0.38
+  - Will be removed in v0.39
+
 * The functions ``qml.qinfo.classical_fisher`` and ``qml.qinfo.quantum_fisher`` are deprecated since they are being migrated
   to the ``qml.gradients`` module. Therefore, ``qml.gradients.classical_fisher`` and ``qml.gradients.quantum_fisher`` should be used instead.
 
diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index 962557219..51fff9978 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -65,11 +65,11 @@
 * `queue_idx` attribute has been removed from the `Operator`, `CompositeOp`, and `SymboliOp` classes.
   [(#6005)](https://github.com/PennyLaneAI/pennylane/pull/6005)
 
-* ``qml.from_qasm`` no longer removes measurements from the QASM code. Use 
-  ``measurements=[]`` to remove measurements from the original circuit.
+* `qml.from_qasm` no longer removes measurements from the QASM code. Use 
+  `measurements=[]` to remove measurements from the original circuit.
   [(#5982)](https://github.com/PennyLaneAI/pennylane/pull/5982)
-  
-* ``qml.transforms.map_batch_transform`` has been removed, since transforms can be applied directly to a batch of tapes.
+
+* `qml.transforms.map_batch_transform` has been removed, since transforms can be applied directly to a batch of tapes.
   See :func:`~.pennylane.transform` for more information.
   [(#5981)](https://github.com/PennyLaneAI/pennylane/pull/5981)
 
@@ -78,6 +78,22 @@
 
 <h3>Deprecations 👋</h3>
 
+* The `expand_fn` argument in `qml.execute` has been deprecated. 
+  Instead, please create a `qml.transforms.core.TransformProgram` with the desired preprocessing and pass it to the `transform_program` argument of `qml.execute`.
+  [(#5984)](https://github.com/PennyLaneAI/pennylane/pull/5984)
+
+* The `max_expansion` argument in `qml.execute` has been deprecated. 
+  Instead, please use `qml.devices.preprocess.decompose` with the desired expansion level, add it to a `TransformProgram` and pass it to the `transform_program` argument of `qml.execute`.
+  [(#5984)](https://github.com/PennyLaneAI/pennylane/pull/5984)
+
+* The `override_shots` argument in `qml.execute` is deprecated. 
+  Instead, please add the shots to the `QuantumTape`'s to be executed.
+  [(#5984)](https://github.com/PennyLaneAI/pennylane/pull/5984)
+
+* The `device_batch_transform` argument in `qml.execute` is deprecated. 
+  Instead, please create a `qml.transforms.core.TransformProgram` with the desired preprocessing and pass it to the `transform_program` argument of `qml.execute`.
+  [(#5984)](https://github.com/PennyLaneAI/pennylane/pull/5984)
+
 * `pennylane.qinfo.classical_fisher` and `pennylane.qinfo.quantum_fisher` have been deprecated.
   Instead, use `pennylane.gradients.classical_fisher` and `pennylane.gradients.quantum_fisher`.
   [(#5985)](https://github.com/PennyLaneAI/pennylane/pull/5985)
@@ -117,6 +133,7 @@ Pietropaolo Frisoni,
 Emiliano Godinez,
 Christina Lee,
 Austin Huang,
+Christina Lee,
 William Maxwell,
 Vincent Michaud-Rioux,
 Mudit Pandey,
diff --git a/pennylane/resource/specs.py b/pennylane/resource/specs.py
index 371af2fff..3285283ec 100644
--- a/pennylane/resource/specs.py
+++ b/pennylane/resource/specs.py
@@ -25,7 +25,8 @@ def _get_absolute_import_path(fn):
 def _determine_spec_level(kwargs, qnode):
     if "max_expansion" in kwargs:
         warnings.warn(
-            "'max_expansion' has no effect on the output of 'specs()' and should not be used."
+            "'max_expansion' has no effect on the output of 'specs()' and should not be used.",
+            qml.PennyLaneDeprecationWarning,
         )
 
     sentinel = object()
diff --git a/pennylane/workflow/execution.py b/pennylane/workflow/execution.py
index b020cb7c7..45f856d80 100644
--- a/pennylane/workflow/execution.py
+++ b/pennylane/workflow/execution.py
@@ -30,6 +30,7 @@ from typing import Callable, MutableMapping, Optional, Sequence, Tuple, Union
 from cachetools import Cache, LRUCache
 
 import pennylane as qml
+from pennylane.data.base.attribute import UNSET
 from pennylane.tape import QuantumTape
 from pennylane.transforms import transform
 from pennylane.typing import ResultBatch
@@ -408,6 +409,63 @@ def _get_interface_name(tapes, interface):
     return interface
 
 
+def _deprecated_arguments_warnings(
+    tapes, override_shots, expand_fn, max_expansion, device_batch_transform
+):
+    """Helper function to raise exceptions and pass codefactor checks regarding the length of the function"""
+
+    if device_batch_transform is not None:
+        warnings.warn(
+            "The device_batch_transform argument is deprecated and will be removed in version 0.39. "
+            "Instead, please create a TransformProgram with the desired preprocessing and pass "
+            "it to the transform_program argument of qml.execute.",
+            qml.PennyLaneDeprecationWarning,
+        )
+    else:
+        device_batch_transform = True
+
+    if override_shots is not UNSET:
+        warnings.warn(
+            "The override_shots argument is deprecated and will be removed in version 0.39. "
+            "Instead, please add the shots to the QuantumTape's to be executed.",
+            qml.PennyLaneDeprecationWarning,
+        )
+        if override_shots is not False:
+            tapes = tuple(
+                qml.tape.QuantumScript(
+                    t.operations,
+                    t.measurements,
+                    trainable_params=t.trainable_params,
+                    shots=override_shots,
+                )
+                for t in tapes
+            )
+    else:
+        override_shots = False
+
+    if expand_fn is not UNSET:
+        warnings.warn(
+            "The expand_fn argument is deprecated and will be removed in version 0.39. "
+            "Instead, please create a TransformProgram with the desired preprocessing and pass "
+            "it to the transform_program argument of qml.execute.",
+            qml.PennyLaneDeprecationWarning,
+        )
+    else:
+        expand_fn = "device"
+
+    if max_expansion is not None:
+        warnings.warn(
+            "The max_expansion argument is deprecated and will be removed in version 0.39. "
+            "Instead, please use qml.devices.preprocess.decompose with the desired expansion level, "
+            "add it to a TransformProgram and pass it to the transform_program argument of qml.execute.",
+            qml.PennyLaneDeprecationWarning,
+        )
+    else:
+        max_expansion = 10
+
+    return tapes, override_shots, expand_fn, max_expansion, device_batch_transform
+
+
 def execute(
     tapes: Sequence[QuantumTape],
     device: device_type,
@@ -421,10 +479,10 @@ def execute(
     cache: Union[None, bool, dict, Cache] = True,
     cachesize=10000,
     max_diff=1,
-    override_shots: int = False,
-    expand_fn="device",  # type: ignore
-    max_expansion=10,
-    device_batch_transform=True,
+    override_shots: int = UNSET,
+    expand_fn=UNSET,  # type: ignore
+    max_expansion=None,
+    device_batch_transform=None,
     device_vjp=False,
     mcm_config=None,
 ) -> ResultBatch:
@@ -480,6 +538,53 @@ def execute(
         list[tensor_like[float]]: A nested list of tape results. Each element in
         the returned list corresponds in order to the provided tapes.
 
+    .. warning::
+
+        The following arguments are deprecated and will be removed in version 0.39:
+        ``expand_fn``, ``max_expansion``, and ``device_batch_transform``.
+        Instead, please create a :class:`~.TransformProgram` with the desired preprocessing and
+        pass it to the ``transform_program`` argument. For instance, we can create a program that uses
+        the ``qml.devices.preprocess.decompose`` transform with the desired expansion level and pass it
+        to the ``qml.execute`` function:
+
+        .. code-block:: python
+
+            from pennylane.devices.preprocess import decompose
+            from pennylane.transforms.core import TransformProgram
+
+            def stopping_condition(obj):
+                return obj.name in {"CNOT", "RX", "RZ"}
+
+            tape = qml.tape.QuantumScript([qml.IsingXX(1.2, wires=(0,1))], [qml.expval(qml.Z(0))])
+
+            program = TransformProgram()
+            program.add_transform(
+                decompose,
+                stopping_condition=stopping_condition,
+                max_expansion=10,
+            )
+
+            dev = qml.device("default.qubit", wires=2)
+
+        >>> qml.execute([tape], dev, transform_program=program)
+        (0.36235775447667357,)
+
+    .. warning::
+
+        The ``override_shots`` argument is deprecated and will be removed in version 0.39.
+        Instead, please add the shots to the ``QuantumTape``'s to be executed. For instance:
+
+        .. code-block:: python
+
+            dev = qml.device("default.qubit", wires=1)
+            operations = [qml.PauliX(0)]
+            measurements = [qml.expval(qml.PauliZ(0))]
+            qs = qml.tape.QuantumTape(operations, measurements, shots=100)
+
+        >>> qml.execute([qs], dev)
+        (-1.0,)
+
+
     **Example**
 
     Consider the following cost function:
@@ -562,6 +667,12 @@ def execute(
             "::L".join(str(i) for i in inspect.getouterframes(inspect.currentframe(), 2)[1][1:3]),
         )
 
+    tapes, override_shots, expand_fn, max_expansion, device_batch_transform = (
+        _deprecated_arguments_warnings(
+            tapes, override_shots, expand_fn, max_expansion, device_batch_transform
+        )
+    )
+
     ### Specifying and preprocessing variables ####
 
     interface = _get_interface_name(tapes, interface)
diff --git a/pennylane/workflow/qnode.py b/pennylane/workflow/qnode.py
index fe807e403..728996315 100644
--- a/pennylane/workflow/qnode.py
+++ b/pennylane/workflow/qnode.py
@@ -1099,19 +1099,26 @@ class QNode:
         full_transform_program.set_classical_component(self, args, kwargs)
         _prune_dynamic_transform(full_transform_program, inner_transform_program)
 
-        # pylint: disable=unexpected-keyword-arg
-        res = qml.execute(
-            (self._tape,),
-            device=self.device,
-            gradient_fn=self.gradient_fn,
-            interface=self.interface,
-            transform_program=full_transform_program,
-            inner_transform=inner_transform_program,
-            config=config,
-            gradient_kwargs=self.gradient_kwargs,
-            override_shots=override_shots,
-            **self.execute_kwargs,
-        )
+        with warnings.catch_warnings():
+            # TODO: remove this once the cycle for the arguements have finished, i.e. 0.39.
+            warnings.filterwarnings(
+                action="ignore",
+                message=r".*argument is deprecated and will be removed in version 0.39.*",
+                category=qml.PennyLaneDeprecationWarning,
+            )
+            # pylint: disable=unexpected-keyword-arg
+            res = qml.execute(
+                (self._tape,),
+                device=self.device,
+                gradient_fn=self.gradient_fn,
+                interface=self.interface,
+                transform_program=full_transform_program,
+                inner_transform=inner_transform_program,
+                config=config,
+                gradient_kwargs=self.gradient_kwargs,
+                override_shots=override_shots,
+                **self.execute_kwargs,
+            )
         res = res[0]
 
         # convert result to the interface in case the qfunc has no parameters


Test patch:
diff --git a/tests/devices/test_preprocess.py b/tests/devices/test_preprocess.py
index cdfeec6c2..7cdbddb56 100644
--- a/tests/devices/test_preprocess.py
+++ b/tests/devices/test_preprocess.py
@@ -199,7 +199,7 @@ class TestDecomposeValidation:
     """Unit tests for helper functions in qml.devices.qubit.preprocess"""
 
     def test_error_if_invalid_op(self):
-        """Test that expand_fn throws an error when an operation is does not define a matrix or decomposition."""
+        """Test that expand_fn throws an error when an operation does not define a matrix or decomposition."""
 
         tape = QuantumScript(ops=[NoMatNoDecompOp(0)], measurements=[qml.expval(qml.Hadamard(0))])
         with pytest.raises(DeviceError, match="not supported with abc"):
diff --git a/tests/interfaces/default_qubit_2_integration/test_execute_default_qubit_2.py b/tests/interfaces/default_qubit_2_integration/test_execute_default_qubit_2.py
index 7891f43ea..87201a276 100644
--- a/tests/interfaces/default_qubit_2_integration/test_execute_default_qubit_2.py
+++ b/tests/interfaces/default_qubit_2_integration/test_execute_default_qubit_2.py
@@ -64,9 +64,13 @@ class TestBatchTransformHelper:
 
         with pytest.warns(UserWarning, match="device batch transforms cannot be turned off"):
             program, _ = dev.preprocess()
-            qml.execute(
-                (qs, qs), device=dev, device_batch_transform=False, transform_program=program
-            )
+            with pytest.warns(
+                qml.PennyLaneDeprecationWarning,
+                match="The device_batch_transform argument is deprecated",
+            ):
+                qml.execute(
+                    (qs, qs), device=dev, device_batch_transform=False, transform_program=program
+                )
 
     def test_split_and_expand_performed(self):
         """Test that preprocess returns the correct tapes when splitting and expanding
@@ -137,7 +141,13 @@ def test_warning_if_not_device_batch_transform():
 
     with pytest.warns(UserWarning, match="device batch transforms cannot be turned off"):
         program, _ = dev.preprocess()
-        results = qml.execute([qs], dev, device_batch_transform=False, transform_program=program)
+        with pytest.warns(
+            qml.PennyLaneDeprecationWarning,
+            match="The device_batch_transform argument is deprecated",
+        ):
+            results = qml.execute(
+                [qs], dev, device_batch_transform=False, transform_program=program
+            )
 
     assert len(results) == 1
     assert qml.math.allclose(results[0], -1)
@@ -166,3 +176,54 @@ def test_caching(gradient_fn):
     assert tracker.totals["batches"] == 1
     assert tracker.totals["executions"] == 1
     assert cache[qs.hash] == -1.0
+
+
+class TestExecuteDeprecations:
+    """Class to test deprecation warnings in qml.execute. Warnings should be raised even if the default value is used."""
+
+    @pytest.mark.parametrize("expand_fn", (None, lambda qs: qs, "device"))
+    def test_expand_fn_is_deprecated(self, expand_fn):
+        """Test that expand_fn argument of qml.execute is deprecated."""
+        dev = DefaultQubit()
+        qs = qml.tape.QuantumScript([qml.PauliX(0)], [qml.expval(qml.PauliZ(0))])
+
+        with pytest.warns(
+            qml.PennyLaneDeprecationWarning, match="The expand_fn argument is deprecated"
+        ):
+            # None is a value used for expand_fn in the QNode
+            qml.execute([qs], dev, expand_fn=expand_fn)
+
+    def test_max_expansion_is_deprecated(self):
+        """Test that max_expansion argument of qml.execute is deprecated."""
+        dev = DefaultQubit()
+        qs = qml.tape.QuantumScript([qml.PauliX(0)], [qml.expval(qml.PauliZ(0))])
+
+        with pytest.warns(
+            qml.PennyLaneDeprecationWarning, match="The max_expansion argument is deprecated"
+        ):
+            qml.execute([qs], dev, max_expansion=10)
+
+    @pytest.mark.parametrize("override_shots", (False, 10))
+    def test_override_shots_is_deprecated(self, override_shots):
+        """Test that override_shots argument of qml.execute is deprecated."""
+        dev = DefaultQubit()
+        qs = qml.tape.QuantumScript([qml.PauliX(0)], [qml.expval(qml.PauliZ(0))])
+
+        with pytest.warns(
+            qml.PennyLaneDeprecationWarning, match="The override_shots argument is deprecated"
+        ):
+            qml.execute([qs], dev, override_shots=override_shots)
+
+    @pytest.mark.parametrize("device_batch_transform", (False, True))
+    def test_device_batch_transform_is_deprecated(self, device_batch_transform):
+        """Test that device_batch_transform argument of qml.execute is deprecated."""
+        # Need to use legacy device, otherwise another warning would be raised due to new Device interface
+        dev = qml.device("default.qubit.legacy", wires=1)
+
+        qs = qml.tape.QuantumScript([qml.PauliX(0)], [qml.expval(qml.PauliZ(0))])
+
+        with pytest.warns(
+            qml.PennyLaneDeprecationWarning,
+            match="The device_batch_transform argument is deprecated",
+        ):
+            qml.execute([qs], dev, device_batch_transform=device_batch_transform)
diff --git a/tests/interfaces/test_autograd.py b/tests/interfaces/test_autograd.py
index d8180ff7b..311c2f32b 100644
--- a/tests/interfaces/test_autograd.py
+++ b/tests/interfaces/test_autograd.py
@@ -201,14 +201,26 @@ class TestBatchTransformExecution:
 
         if not qml.operation.active_new_opmath():
             with pytest.raises(AssertionError, match="Hamiltonian must be used with shots=None"):
-                _ = qml.execute([tape], dev, None, device_batch_transform=False)
+                with pytest.warns(
+                    qml.PennyLaneDeprecationWarning,
+                    match="The device_batch_transform argument is deprecated",
+                ):
+                    _ = qml.execute([tape], dev, None, device_batch_transform=False)
         else:
-            res = qml.execute([tape], dev, None, device_batch_transform=False)
+            with pytest.warns(
+                qml.PennyLaneDeprecationWarning,
+                match="The device_batch_transform argument is deprecated",
+            ):
+                res = qml.execute([tape], dev, None, device_batch_transform=False)
             assert np.allclose(res[0], np.cos(y), atol=0.1)
 
         spy.assert_not_called()
 
-        res = qml.execute([tape], dev, None, device_batch_transform=True)
+        with pytest.warns(
+            qml.PennyLaneDeprecationWarning,
+            match="The device_batch_transform argument is deprecated",
+        ):
+            res = qml.execute([tape], dev, None, device_batch_transform=True)
         spy.assert_called()
 
         assert qml.math.shape(res[0]) == ()
@@ -220,7 +232,10 @@ class TestBatchTransformExecution:
         dev = qml.device("default.qubit.legacy", wires=1)
         H = 2.0 * qml.PauliZ(0)
         qscript = qml.tape.QuantumScript(measurements=[qml.expval(H)])
-        res = qml.execute([qscript], dev, interface=None, override_shots=10)
+        with pytest.warns(
+            qml.PennyLaneDeprecationWarning, match="The override_shots argument is deprecated"
+        ):
+            res = qml.execute([qscript], dev, interface=None, override_shots=10)
         assert res == (2.0,)
 
 
@@ -1115,7 +1130,10 @@ class TestOverridingShots:
         spy.assert_not_called()
 
         # execute with shots=100
-        res = qml.execute([tape], dev, gradient_fn=param_shift, override_shots=100)
+        with pytest.warns(
+            qml.PennyLaneDeprecationWarning, match="The override_shots argument is deprecated"
+        ):
+            res = qml.execute([tape], dev, gradient_fn=param_shift, override_shots=100)
         spy.assert_called_once()
         assert spy.spy_return.shape == (100,)
 
@@ -1142,11 +1160,17 @@ class TestOverridingShots:
         mock_property = qml.Device.shots.setter(spy)
         mocker.patch.object(qml.Device, "shots", mock_property)
 
-        qml.execute([tape], dev, gradient_fn=param_shift, override_shots=123)
+        with pytest.warns(
+            qml.PennyLaneDeprecationWarning, match="The override_shots argument is deprecated"
+        ):
+            qml.execute([tape], dev, gradient_fn=param_shift, override_shots=123)
         # overriden shots is the same, no change
         spy.assert_not_called()
 
-        qml.execute([tape], dev, gradient_fn=param_shift, override_shots=100)
+        with pytest.warns(
+            qml.PennyLaneDeprecationWarning, match="The override_shots argument is deprecated"
+        ):
+            qml.execute([tape], dev, gradient_fn=param_shift, override_shots=100)
         # overriden shots is not the same, shots were changed
         spy.assert_called()
 
@@ -1172,7 +1196,10 @@ class TestOverridingShots:
             qml.expval(qml.PauliY(1))
 
         tape = qml.tape.QuantumScript.from_queue(q)
-        res = qml.execute([tape], dev, gradient_fn=param_shift, override_shots=100)[0]
+        with pytest.warns(
+            qml.PennyLaneDeprecationWarning, match="The override_shots argument is deprecated"
+        ):
+            res = qml.execute([tape], dev, gradient_fn=param_shift, override_shots=100)[0]
 
         assert isinstance(res, np.ndarray)
         assert res.shape == ()
@@ -1200,7 +1227,11 @@ class TestOverridingShots:
                 qml.expval(qml.PauliY(1))
 
             tape = qml.tape.QuantumScript.from_queue(q)
-            return qml.execute([tape], dev, gradient_fn=param_shift, override_shots=shots)[0]
+            with pytest.warns(
+                qml.PennyLaneDeprecationWarning, match="The override_shots argument is deprecated"
+            ):
+                result = qml.execute([tape], dev, gradient_fn=param_shift, override_shots=shots)
+            return result[0]
 
         res = qml.jacobian(cost_fn)(a, b, shots=[10000, 10000, 10000])
         assert dev.shots is None
diff --git a/tests/resource/test_specs.py b/tests/resource/test_specs.py
index 2dd69be8d..2e1bda862 100644
--- a/tests/resource/test_specs.py
+++ b/tests/resource/test_specs.py
@@ -48,7 +48,7 @@ class TestSpecsTransform:
         def circ():
             return qml.expval(qml.PauliZ(0))
 
-        with pytest.warns(UserWarning, match="'max_expansion' has no effect"):
+        with pytest.warns(qml.PennyLaneDeprecationWarning, match="'max_expansion' has no effect"):
             qml.specs(circ, max_expansion=10)()
 
     def test_only_one_of_level_or_expansion_strategy_passed(self):
@@ -251,7 +251,7 @@ class TestSpecsTransform:
 
     @pytest.mark.xfail(reason="DefaultQubit2 does not support custom expansion depths")
     def test_max_expansion(self):
-        """Test that a user can calculation specifications for a different max
+        """Test that a user can calculate specifications for a different max
         expansion parameter."""
 
         circuit, params = self.make_qnode_and_params("device")