Repository: PennyLaneAI/pennylane
Pull request #5047 (2024-01-11 20:56:36)

deprecate mp.name and mp.data
`mp.name` has always been "Identity", and `mp.data` has always been `[]`. This was needed as a hack in the past, but we don't need it anymore.

This PR deprecates those values, and they will be removed in the next release.

[sc-43949]

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/5047?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:
> Comparison is base [(`c01cb4b`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/c01cb4b96f758a9f1a0c4e422115829b80e113cb?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) 99.67% compared to head [(`23a8ca7`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/5047?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) 99.66%.


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


```diff
@@            Coverage Diff             @@
##           master    #5047      +/-   ##
==========================================
- Coverage   99.67%   99.66%   -0.01%     
==========================================
  Files         394      394              
  Lines       35670    35409     -261     
==========================================
- Hits        35554    35292     -262     
- Misses        116      117       +1     
```



</details>

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


Patch:
diff --git a/doc/development/deprecations.rst b/doc/development/deprecations.rst
index 052efade3..ecb11419e 100644
--- a/doc/development/deprecations.rst
+++ b/doc/development/deprecations.rst
@@ -9,6 +9,12 @@ deprecations are listed below.
 Pending deprecations
 --------------------
 
+* ``MeasurementProcess.name`` and ``MeasurementProcess.data`` have been deprecated, as they contain
+  dummy values that are no longer needed.
+
+  - Deprecated in v0.35
+  - Will be removed in v0.36
+
 * The contents of ``qml.interfaces`` is moved inside ``qml.workflow``.
 
   - Contents moved in v0.35
diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index 943d25b20..c92d5e213 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -54,6 +54,10 @@
 * Matrix and tensor products between `PauliWord` and `PauliSentence` instances are done using the `@` operator, `*` will be used only for scalar multiplication.
   [(#4989)](https://github.com/PennyLaneAI/pennylane/pull/4989)
 
+* `MeasurementProcess.name` and `MeasurementProcess.data` are now deprecated, as they contain dummy
+  values that are no longer needed.
+  [(#5047)](https://github.com/PennyLaneAI/pennylane/pull/5047)
+
 <h3>Documentation 📝</h3>
 
 * A typo in a code example in the `qml.transforms` API has been fixed.
diff --git a/pennylane/measurements/measurements.py b/pennylane/measurements/measurements.py
index 1fe2699b3..7bcbb2808 100644
--- a/pennylane/measurements/measurements.py
+++ b/pennylane/measurements/measurements.py
@@ -18,6 +18,8 @@ and measurement samples using AnnotatedQueues.
 """
 import copy
 import functools
+from warnings import warn
+
 from abc import ABC, abstractmethod
 from enum import Enum
 from typing import Sequence, Tuple, Optional, Union
@@ -185,22 +187,31 @@ class MeasurementProcess(ABC):
 
             self._eigvals = qml.math.asarray(eigvals)
 
-        # TODO: remove the following lines once devices
-        # have been refactored to accept and understand receiving
-        # measurement processes rather than specific observables.
-
-        # The following lines are only applicable for measurement processes
-        # that do not have corresponding observables (e.g., Probability). We use
-        # them to 'trick' the device into thinking it has received an observable.
-
-        # Below, we imitate an identity observable, so that the
-        # device undertakes no action upon receiving this observable.
-        self.name = "Identity"
-        self.data = []
-
         # Queue the measurement process
         self.queue()
 
+    @property
+    def name(self):
+        """A deprecated property that always returns 'Identity'."""
+        warn(
+            "MeasurementProcess.name is deprecated, and will be removed "
+            "in an upcoming release. To get the name of an observable "
+            "from a measurement, use MeasurementProcess.obs.name instead",
+            qml.PennyLaneDeprecationWarning,
+        )
+        return "Identity"
+
+    @property
+    def data(self):
+        """A deprecated property that always returns an empty list."""
+        warn(
+            "MeasurementProcess.data is deprecated, and will be removed "
+            "in an upcoming release. To get the data of an observable "
+            "from a measurement, use MeasurementProcess.obs.data instead",
+            qml.PennyLaneDeprecationWarning,
+        )
+        return []
+
     @property
     def return_type(self) -> Optional[ObservableReturnTypes]:
         """Measurement return type."""


Test patch:
diff --git a/tests/measurements/test_measurements.py b/tests/measurements/test_measurements.py
index 26fc40305..20e3db2a9 100644
--- a/tests/measurements/test_measurements.py
+++ b/tests/measurements/test_measurements.py
@@ -414,6 +414,18 @@ class TestProperties:
         mapped_mp2 = mp2.map_wires(wire_map)
         assert qml.equal(mapped_mp2, qml.sample(op=m2 * m3))
 
+    def test_name_and_data_are_deprecated(self):
+        """Test that MP.name and MP.data are deprecated."""
+        mp = qml.expval(qml.PauliZ(0))
+        with pytest.warns(
+            qml.PennyLaneDeprecationWarning, match="MeasurementProcess.name is deprecated"
+        ):
+            _ = mp.name
+        with pytest.warns(
+            qml.PennyLaneDeprecationWarning, match="MeasurementProcess.data is deprecated"
+        ):
+            _ = mp.data
+
 
 class TestExpansion:
     """Test for measurement expansion"""