Repository: PennyLaneAI/pennylane
Pull request #5904 (2024-06-25 14:06:21)

Raise DeprecationWarning only when the qasm code contains measurements
**Context:**
https://github.com/PennyLaneAI/pennylane/pull/5882 led to deprecation warnings raised in non-applicable scenarios

**Description of the Change:**
Only raise deprecation warning if the circuit contains measurements

**Benefits:**
Less confusing deprecation warnings


astralcai: [sc-66318]
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/5904?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:
> Please [upload](https://docs.codecov.com/docs/codecov-uploader) report for BASE (`v0.37.0-rc0@0da4c3d`). [Learn more](https://docs.codecov.io/docs/error-reference?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI#section-missing-base-commit) about missing BASE report.

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


```diff
@@              Coverage Diff               @@
##             v0.37.0-rc0    #5904   +/-   ##
==============================================
  Coverage               ?   99.66%           
==============================================
  Files                  ?      425           
  Lines                  ?    40458           
  Branches               ?        0           
==============================================
  Hits                   ?    40324           
  Misses                 ?      134           
  Partials               ?        0           
```

</details>

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

trbromley: Interesting branch name!

Patch:
diff --git a/doc/development/deprecations.rst b/doc/development/deprecations.rst
index 23f2c0749..97ef6cb6e 100644
--- a/doc/development/deprecations.rst
+++ b/doc/development/deprecations.rst
@@ -22,9 +22,9 @@ Pending deprecations
   - Will be removed in v0.38
 
 * ``qml.from_qasm`` will no longer remove measurements from the QASM code. Calling ``qml.from_qasm``
-  without specifying ``measurements`` will raise a deprecation warning in v0.37, and in v0.38,
-  the default behaviour will be changed to keeping measurements. Use ``measurements=[]`` to remove
-  measurements from the original circuit.
+  on a circuit containing measurements without specifying ``measurements`` will raise a deprecation 
+  warning in v0.37, and in v0.38, the default behaviour will be changed to keeping measurements. Use 
+  ``measurements=[]`` to remove measurements from the original circuit.
 
   - Deprecated in v0.37
   - Default behaviour will be changed in v0.38
diff --git a/doc/releases/changelog-0.37.0.md b/doc/releases/changelog-0.37.0.md
index eaa2edfd2..e5db54be2 100644
--- a/doc/releases/changelog-0.37.0.md
+++ b/doc/releases/changelog-0.37.0.md
@@ -306,7 +306,6 @@
 * The `qml.data` module now supports PyTree data types as dataset attributes
   [(#5732)](https://github.com/PennyLaneAI/pennylane/pull/5732)
 
-
 * `qml.ops.Conditional` now inherits from `qml.ops.SymbolicOp`, thus it inherits several useful common functionalities. Other properties such as adjoint and diagonalizing gates have been added using the `base` properties.
   [(##5772)](https://github.com/PennyLaneAI/pennylane/pull/5772)
 
@@ -416,6 +415,7 @@
 
 * The default behaviour of `qml.from_qasm()` to remove measurements in the QASM code is deprecated. Use `measurements=[]` to keep this behaviour or `measurements=None` to keep the measurements from the QASM code.
   [(#5882)](https://github.com/PennyLaneAI/pennylane/pull/5882)
+  [(#5904)](https://github.com/PennyLaneAI/pennylane/pull/5904)
 
 <h3>Documentation 📝</h3>
 
diff --git a/pennylane/io.py b/pennylane/io.py
index 444655212..3416f9b9b 100644
--- a/pennylane/io.py
+++ b/pennylane/io.py
@@ -505,14 +505,15 @@ def from_qasm(quantum_circuit: str, measurements=False):
     """
     plugin_converter = plugin_converters["qasm"].load()
     if measurements is False:
-        warnings.warn(
-            "The current default behaviour of removing measurements in the QASM code is "
-            "deprecated. Set measurements=None to keep the existing measurements in the QASM "
-            "code or set measurements=[] to remove them from the returned circuit. Starting "
-            "in version 0.38, measurements=None will be the new default.",
-            qml.PennyLaneDeprecationWarning,
-        )
         measurements = []
+        if "measure" in quantum_circuit:
+            warnings.warn(
+                "The current default behaviour of removing measurements in the QASM code "
+                "is deprecated. Set measurements=None to keep existing measurements in the QASM "
+                "code or set measurements=[] to remove them from the returned circuit. Starting "
+                "in version 0.38, measurements=None will be the new default.",
+                qml.PennyLaneDeprecationWarning,
+            )
     return plugin_converter(quantum_circuit, measurements=measurements)
 
 


Test patch:
diff --git a/tests/test_io.py b/tests/test_io.py
index d59b22ba8..fa3ed2dc6 100644
--- a/tests/test_io.py
+++ b/tests/test_io.py
@@ -137,7 +137,7 @@ class TestLoad:
     def test_from_qasm(self, mock_plugin_converters):
         """Tests that the correct entry point is called for from_qasm."""
 
-        qml.from_qasm("Test", measurements=None)
+        qml.from_qasm("Test")
         assert mock_plugin_converters["qasm"].called
         assert mock_plugin_converters["qasm"].last_args == ("Test",)
 
@@ -149,10 +149,10 @@ class TestLoad:
         """Tests that the current default behaviour of from_qasm is deprecated."""
 
         with pytest.warns(qml.PennyLaneDeprecationWarning, match="The current default behaviour"):
-            qml.from_qasm("Test")
+            qml.from_qasm("measure q[i] -> c[i];")
 
         called_args, called_kwargs = mock_plugin_converters["qasm"].call_args
-        assert called_args == ("Test",)
+        assert called_args == ("measure q[i] -> c[i];",)
         assert called_kwargs == {"measurements": []}
 
     @pytest.mark.parametrize(