Repository: PennyLaneAI/pennylane
Pull request #5533 (2024-04-17 09:14:58)

Update names of `qml.capture` switches
**Context:**
#5509 added a `qml.capture` module. It contains switches that enable and disable the capturing mechanism, and a status reporting function about whether the mechanism is currently enabled.

**Description of the Change:**
This PR changes the name of these switches/status functions
- `qml.capture.enable_plxpr` --> `qml.capture.enable`
- `qml.capture.disable_plxpr` --> `qml.capture.disable`
- `qml.capture.plxpr_enabled` --> `qml.capture.enabled`

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**


[sc-61510]

github-actions[bot]: Hello. You may have forgotten to update the changelog!
Please edit [`doc/releases/changelog-dev.md`](/PennyLaneAI/pennylane/blob/master/doc/releases/changelog-dev.md) with:
* A one-to-two sentence description of the change. You may include a small working example for new features.
* A link back to this PR.
* Your name (or GitHub username) in the contributors section.
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/5533?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.66%. Comparing base [(`0747c0a`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/0747c0ab22a277b1a3356656af33c9b6c2ce2609?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) to head [(`523202f`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/5533?dropdown=coverage&src=pr&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    #5533      +/-   ##
==========================================
- Coverage   99.67%   99.66%   -0.01%     
==========================================
  Files         404      406       +2     
  Lines       37852    37590     -262     
==========================================
- Hits        37728    37465     -263     
- Misses        124      125       +1     
```



</details>

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

dime10: If the third version is a query, would it make sense to name it `is_enabled`? (not sure if this follows existing pennylane conventions or not)
albi3ro: > If the third version is a query, would it make sense to name it `is_enabled`? (not sure if this follows existing pennylane conventions or not)

We don't really have conventions for this kinda of thing, so what ever we think works well enough.

Patch:
diff --git a/pennylane/capture/__init__.py b/pennylane/capture/__init__.py
index 24feeaebf..c5f917982 100644
--- a/pennylane/capture/__init__.py
+++ b/pennylane/capture/__init__.py
@@ -23,22 +23,22 @@ quantum-classical programs.
 
 
 To activate and deactivate the new PennyLane program capturing mechanism, use
-the switches ``qml.capture.enable_plxpr`` and ``qml.capture.disable_plxpr``.
+the switches ``qml.capture.enable`` and ``qml.capture.disable``.
 Whether or not the capturing mechanism is currently being used can be
-queried with ``qml.capture.plxpr_enabled``.
+queried with ``qml.capture.enabled``.
 By default, the mechanism is disabled:
 
 .. code-block:: pycon
 
     >>> import pennylane as qml
-    >>> qml.capture.plxpr_enabled()
+    >>> qml.capture.enabled()
     False
-    >>> qml.capture.enable_plxpr()
-    >>> qml.capture.plxpr_enabled()
+    >>> qml.capture.enable()
+    >>> qml.capture.enabled()
     True
-    >>> qml.capture.disable_plxpr()
-    >>> qml.capture.plxpr_enabled()
+    >>> qml.capture.disable()
+    >>> qml.capture.enabled()
     False
 
 """
-from .switches import enable_plxpr, disable_plxpr, plxpr_enabled
+from .switches import enable, disable, enabled
diff --git a/pennylane/capture/switches.py b/pennylane/capture/switches.py
index 90cd5be00..cbb25855c 100644
--- a/pennylane/capture/switches.py
+++ b/pennylane/capture/switches.py
@@ -34,31 +34,31 @@ def _make_switches() -> [Callable[[], None], Callable[[], None], Callable[[], bo
         can be used to make switches for any context.
     """
 
-    _PLXPR_ENABLED = False
+    _FEATURE_ENABLED = False
     # since this changes what happens with tracing, we need to turn the behaviour
     # off by default to preserve our ability to jit pennylane circuits.
 
-    def enable() -> None:
+    def enable_fn() -> None:
         """Enable the capturing mechanism of hybrid quantum-classical programs
         in a PennyLane Program Representation (plxpr)."""
         if not has_jax:
             raise ImportError("plxpr requires JAX to be installed.")
-        nonlocal _PLXPR_ENABLED
-        _PLXPR_ENABLED = True
+        nonlocal _FEATURE_ENABLED
+        _FEATURE_ENABLED = True
 
-    def disable() -> None:
+    def disable_fn() -> None:
         """Disable the capturing mechanism of hybrid quantum-classical programs
         in a PennyLane Program Representation (plxpr)."""
-        nonlocal _PLXPR_ENABLED
-        _PLXPR_ENABLED = False
+        nonlocal _FEATURE_ENABLED
+        _FEATURE_ENABLED = False
 
-    def status() -> bool:
+    def status_fn() -> bool:
         """Return whether the capturing mechanism of hybrid quantum-classical programs
         in a PennyLane Program Representation (plxpr) is enabled."""
-        nonlocal _PLXPR_ENABLED
-        return _PLXPR_ENABLED
+        nonlocal _FEATURE_ENABLED
+        return _FEATURE_ENABLED
 
-    return enable, disable, status
+    return enable_fn, disable_fn, status_fn
 
 
-enable_plxpr, disable_plxpr, plxpr_enabled = _make_switches()
+enable, disable, enabled = _make_switches()


Test patch:
diff --git a/tests/capture/test_switches.py b/tests/capture/test_switches.py
index 2d0310c49..3942d779f 100644
--- a/tests/capture/test_switches.py
+++ b/tests/capture/test_switches.py
@@ -22,19 +22,19 @@ import pennylane as qml
 def test_switches_with_jax():
     """Test switches and status reporting function."""
 
-    assert qml.capture.plxpr_enabled() is False
-    assert qml.capture.enable_plxpr() is None
-    assert qml.capture.plxpr_enabled() is True
-    assert qml.capture.disable_plxpr() is None
-    assert qml.capture.plxpr_enabled() is False
+    assert qml.capture.enabled() is False
+    assert qml.capture.enable() is None
+    assert qml.capture.enabled() is True
+    assert qml.capture.disable() is None
+    assert qml.capture.enabled() is False
 
 
 def test_switches_without_jax():
     """Test switches and status reporting function."""
 
-    assert qml.capture.plxpr_enabled() is False
+    assert qml.capture.enabled() is False
     with pytest.raises(ImportError, match="plxpr requires JAX to be installed."):
-        qml.capture.enable_plxpr()
-    assert qml.capture.plxpr_enabled() is False
-    assert qml.capture.disable_plxpr() is None
-    assert qml.capture.plxpr_enabled() is False
+        qml.capture.enable()
+    assert qml.capture.enabled() is False
+    assert qml.capture.disable() is None
+    assert qml.capture.enabled() is False