Repository: PennyLaneAI/pennylane
Pull request #4730 (2023-10-25 18:04:08)

qml demo fixes: avoid queuing unneeded projectors
the `qml.pulse.rdyberg_iteraction` function was queuing projectors, which are now treated as operations in and affect the output of the simulation.

This fix prevents from the being queued.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/4730?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:
> :exclamation: No coverage uploaded for pull request base (`v0.33.0-rc0@4c7ae04`). [Click here to learn what that means](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).

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


```diff
@@              Coverage Diff               @@
##             v0.33.0-rc0    #4730   +/-   ##
==============================================
  Coverage               ?   99.58%           
==============================================
  Files                  ?      380           
  Lines                  ?    33995           
  Branches               ?        0           
==============================================
  Hits                   ?    33855           
  Misses                 ?      140           
  Partials               ?        0           
```




</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/4730?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/pennylane/pulse/rydberg.py b/pennylane/pulse/rydberg.py
index ec388d794..620792884 100644
--- a/pennylane/pulse/rydberg.py
+++ b/pennylane/pulse/rydberg.py
@@ -112,8 +112,9 @@ def rydberg_interaction(
                 2 * np.pi * interaction_coeff / (abs(atom_distance) ** 6)
             )  # van der Waals potential
             coeffs.append(Vij)
-            observables.append(qml.prod(qml.Projector([1], wire1), qml.Projector([1], wire2)))
-            # Rydberg projectors
+            with qml.QueuingManager.stop_recording():
+                observables.append(qml.prod(qml.Projector([1], wire1), qml.Projector([1], wire2)))
+                # Rydberg projectors
 
     settings = RydbergSettings(register, interaction_coeff)
 


Test patch:
diff --git a/tests/pulse/test_rydberg.py b/tests/pulse/test_rydberg.py
index 09b9dec3a..ab4e765f4 100644
--- a/tests/pulse/test_rydberg.py
+++ b/tests/pulse/test_rydberg.py
@@ -37,6 +37,13 @@ wires = [1, 6, 0, 2, 4, 3]
 class TestRydbergInteraction:
     """Unit tests for the ``rydberg_interaction`` function."""
 
+    def test_queuing(self):
+        """Test that the function does not queue any objects."""
+        with qml.queuing.AnnotatedQueue() as q:
+            rydberg_interaction(register=atom_coordinates, wires=wires, interaction_coeff=1)
+
+        assert len(q) == 0
+
     def test_attributes_and_number_of_terms(self):
         """Test that the attributes and the number of terms of the ``ParametrizedHamiltonian`` returned by
         ``rydberg_interaction`` are correct."""