Repository: PennyLaneAI/pennylane
Pull request #7000 (2025-02-24 18:21:41)

[v0.41 Dep & Rmv] Documentation Audit
**Context:**

This release had some rather large scope deprecations and removals. This PR aims to address any potential fuzz that was accidentally missed in the source code.

**Description of the Change:**

This PR includes minor adjustments to the deprecation message for,
- `gradient_kwargs` to the `QNode`
- Controlled qubit unitary arguments

**Benefits:** Cleaner code.

**Possible Drawbacks:** None identified.

[sc-82824]


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/7000?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.59%. Comparing base [(`d57655c`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/d57655c0dc0b6a12db70f9dc18134d075b8de783?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) to head [(`b078def`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/b078def2565bb2826c0cbe176ce36cf164c72d6c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).

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


```diff
@@           Coverage Diff           @@
##           master    #7000   +/-   ##
=======================================
  Coverage   99.59%   99.59%           
=======================================
  Files         483      483           
  Lines       46069    46069           
=======================================
  Hits        45884    45884           
  Misses        185      185           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/7000?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).

JerryChen97: I made some changes to several local symbols such that src code there less confusing.

Patch:
diff --git a/doc/development/guide/architecture.rst b/doc/development/guide/architecture.rst
index 0f1f3e5fb..d42ec1bb4 100644
--- a/doc/development/guide/architecture.rst
+++ b/doc/development/guide/architecture.rst
@@ -114,12 +114,6 @@ which are themselves operators.
 >>> m.obs
 PauliZ(wires=['a'])
 
-Furthermore, it specifies a "return type" which defines the kind of measurement performed,
-such as expectation, variance, probability, state, or sample.
-
->>> m.return_type
-ObservableReturnTypes.Expectation
-
 For more information, check out the documentation on :doc:`measurements </introduction/measurements>`
 
 QuantumTape
diff --git a/pennylane/ops/op_math/controlled_ops.py b/pennylane/ops/op_math/controlled_ops.py
index e8490d9c3..66a84e6b2 100644
--- a/pennylane/ops/op_math/controlled_ops.py
+++ b/pennylane/ops/op_math/controlled_ops.py
@@ -180,7 +180,7 @@ class ControlledQubitUnitary(ControlledOp):
         if hasattr(base, "wires"):
             warnings.warn(
                 "QubitUnitary input to ControlledQubitUnitary is deprecated and will be removed in v0.42. "
-                "Instead, please use a full matrix as input.",
+                "Instead, please use a full matrix as input, or try qml.ctrl for controlled QubitUnitary.",
                 qml.PennyLaneDeprecationWarning,
             )
             base = base.matrix()
diff --git a/pennylane/workflow/qnode.py b/pennylane/workflow/qnode.py
index 11ef70c57..76275ae19 100644
--- a/pennylane/workflow/qnode.py
+++ b/pennylane/workflow/qnode.py
@@ -578,7 +578,8 @@ class QNode:
         if kwargs:
             if any(k in qml.gradients.SUPPORTED_GRADIENT_KWARGS for k in list(kwargs.keys())):
                 warnings.warn(
-                    f"Specifying gradient keyword arguments {list(kwargs.keys())} is deprecated and will be removed in v0.42. Instead, please specify all arguments in the gradient_kwargs argument.",
+                    f"Specifying gradient keyword arguments {list(kwargs.keys())} as additional kwargs has been deprecated and will be removed in v0.42. \
+                    Instead, please specify these arguments through the `gradient_kwargs` dictionary argument.",
                     qml.PennyLaneDeprecationWarning,
                 )
             gradient_kwargs |= kwargs


Test patch:
diff --git a/tests/capture/test_base_interpreter.py b/tests/capture/test_base_interpreter.py
index 30a7679e1..d20486b8b 100644
--- a/tests/capture/test_base_interpreter.py
+++ b/tests/capture/test_base_interpreter.py
@@ -143,7 +143,6 @@ def test_default_operator_handling():
 @pytest.mark.parametrize(
     "op_class, args, kwargs",
     [
-        # (qml.ControlledQubitUnitary, (jnp.eye(2), [0, 1]), {}),
         (qml.CH, ([0, 1],), {}),
         (qml.CY, ([0, 1],), {}),
         (qml.CZ, ([0, 1],), {}),
diff --git a/tests/ops/op_math/test_controlled_ops.py b/tests/ops/op_math/test_controlled_ops.py
index a41a9670d..44628308d 100644
--- a/tests/ops/op_math/test_controlled_ops.py
+++ b/tests/ops/op_math/test_controlled_ops.py
@@ -163,14 +163,16 @@ class TestControlledQubitUnitary:
         """Test that both combinations of control and target wires lead to the same operator"""
         base_op = [[0, 1], [1, 0]]
 
-        control_wires_1, wires_1 = [0, 1], [2]
-        op_1 = qml.ControlledQubitUnitary(base_op, wires=control_wires_1 + wires_1)
+        control_wires_1, target_wires_1 = [0, 1], [2]
+        op_1 = qml.ControlledQubitUnitary(base_op, wires=control_wires_1 + target_wires_1)
 
         assert op_1.base.wires == Wires(2)
         assert op_1.control_wires == Wires([0, 1])
 
-        control_wires_2, wires_2 = [0, 1, 2], ()
-        op_2 = qml.ControlledQubitUnitary(base_op, wires=Wires(control_wires_2) + Wires(wires_2))
+        control_wires_2, target_wires_2 = [0, 1, 2], ()
+        op_2 = qml.ControlledQubitUnitary(
+            base_op, wires=Wires(control_wires_2) + Wires(target_wires_2)
+        )
 
         assert op_2.base.wires == Wires(2)
         assert op_2.control_wires == Wires([0, 1])
diff --git a/tests/test_qnode.py b/tests/test_qnode.py
index e3c2e8f18..ce0470daf 100644
--- a/tests/test_qnode.py
+++ b/tests/test_qnode.py
@@ -43,7 +43,7 @@ def test_additional_kwargs_is_deprecated():
 
     with pytest.warns(
         qml.PennyLaneDeprecationWarning,
-        match=r"Specifying gradient keyword arguments \[\'atol\'\] is deprecated",
+        match=r"Specifying gradient keyword arguments \[\'atol\'\] as additional kwargs has been deprecated",
     ):
         QNode(dummyfunc, dev, atol=1)
 
diff --git a/tests/transforms/test_qmc_transform.py b/tests/transforms/test_qmc_transform.py
index 8c399fb9b..3558c631c 100644
--- a/tests/transforms/test_qmc_transform.py
+++ b/tests/transforms/test_qmc_transform.py
@@ -96,12 +96,12 @@ def test_apply_controlled_z(n_wires):
     unitary and comparing against the one provided in _make_Z."""
     n_all_wires = n_wires + 1
 
-    wires = Wires(range(n_wires))
+    target_wires = Wires(range(n_wires))
     control_wire = n_wires
     work_wires = None
 
     circ = lambda: _apply_controlled_z(
-        wires=wires, control_wire=control_wire, work_wires=work_wires
+        wires=target_wires, control_wire=control_wire, work_wires=work_wires
     )
     u = get_unitary(circ, n_all_wires)
 
@@ -109,7 +109,7 @@ def test_apply_controlled_z(n_wires):
     # because two Zs are used.
     z_ideal = -_make_Z(2**n_wires)
 
-    circ = lambda: qml.ControlledQubitUnitary(z_ideal, wires=control_wire + wires)
+    circ = lambda: qml.ControlledQubitUnitary(z_ideal, wires=control_wire + target_wires)
     u_ideal = get_unitary(circ, n_all_wires)
 
     assert np.allclose(u, u_ideal)
@@ -121,7 +121,7 @@ def test_apply_controlled_v(n_wires):
     unitary and comparing against the one provided in _make_V."""
     n_all_wires = n_wires + 1
 
-    wires = Wires(range(n_wires))
+    target_wires = Wires(range(n_wires))
     control_wire = Wires(n_wires)
 
     circ = lambda: _apply_controlled_v(target_wire=Wires([n_wires - 1]), control_wire=control_wire)
@@ -131,7 +131,7 @@ def test_apply_controlled_v(n_wires):
     # because two Vs are used.
     v_ideal = -_make_V(2**n_wires)
 
-    circ = lambda: qml.ControlledQubitUnitary(v_ideal, wires=control_wire + wires)
+    circ = lambda: qml.ControlledQubitUnitary(v_ideal, wires=control_wire + target_wires)
     u_ideal = get_unitary(circ, n_all_wires)
 
     assert np.allclose(u, u_ideal)