nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: PennyLaneAI/pennylane
Pull request #6780 (2025-01-07 21:27:39)

Mudit's QA fixes for v0.40.0
Update logic in `LegacyDevice` to check for whether the device supports `LinearCombination` or not.

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.

Patch:
diff --git a/pennylane/devices/_legacy_device.py b/pennylane/devices/_legacy_device.py
index 93342f9d2..33400c376 100644
--- a/pennylane/devices/_legacy_device.py
+++ b/pennylane/devices/_legacy_device.py
@@ -813,7 +813,10 @@ class Device(abc.ABC, metaclass=_LegacyMeta):
                 # Some measurements are not observable based.
                 continue
 
-            if mp.obs.name == "LinearCombination" and not self.supports_observable("Hamiltonian"):
+            if mp.obs.name == "LinearCombination" and not (
+                self.supports_observable("Hamiltonian")
+                or self.supports_observable("LinearCombination")
+            ):
                 return False
 
             if mp.obs.name in (


Test patch:
diff --git a/tests/devices/test_legacy_device.py b/tests/devices/test_legacy_device.py
index 671425692..bd8d2e7b2 100644
--- a/tests/devices/test_legacy_device.py
+++ b/tests/devices/test_legacy_device.py
@@ -278,6 +278,20 @@ class TestDeviceSupportedLogic:
         ):
             dev.supports_observable(operation)
 
+    @pytest.mark.parametrize("supported_multi_term_obs", ["Hamiltonian", "LinearCombination"])
+    @pytest.mark.parametrize("obs_type", [qml.ops.LinearCombination, qml.Hamiltonian])
+    def test_all_multi_term_obs_supported_linear_combination(
+        self, mock_device, supported_multi_term_obs, obs_type
+    ):
+        """Test that LinearCombination is supported when the device supports either
+        LinearCombination or Hamiltonian."""
+        dev = mock_device()
+        dev.observables = dev.observables + [supported_multi_term_obs]
+
+        obs = obs_type([1.0, 2.0], [qml.Z(0), qml.Z(0)])
+        circuit = qml.tape.QuantumScript([], [qml.expval(obs)])
+        assert dev._all_multi_term_obs_supported(circuit)  # pylint: disable=protected-access
+
 
 class TestInternalFunctions:  # pylint:disable=too-many-public-methods
     """Test the internal functions of the abstract Device class"""
Repository: PennyLaneAI/pennylane
Pull request #6844 (2025-01-16 17:22:07)

Cast input to `BasisState` to an int
**Context:**

PR #6770  accidentally broke lightning, becasue we are now sending numpy data to lightning instead of autograd.  The autograd arrays had slightly different casting rules. With numpy, we are no longer implicitly casting to integers.

**Description of the Change:**

Always cast the input to `BasisState` to integers.

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**



Patch:
diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index 659407fc5..b0acd30f9 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -78,6 +78,9 @@
 
 <h3>Bug fixes 🐛</h3>
 
+* `BasisState` now casts its input to integers.
+  [(#6844)](https://github.com/PennyLaneAI/pennylane/pull/6844)
+
 <h3>Contributors ✍️</h3>
 
 This release contains contributions from (in alphabetical order):
diff --git a/pennylane/ops/qubit/state_preparation.py b/pennylane/ops/qubit/state_preparation.py
index d51a4f55f..a7c79dded 100644
--- a/pennylane/ops/qubit/state_preparation.py
+++ b/pennylane/ops/qubit/state_preparation.py
@@ -102,7 +102,7 @@ class BasisState(StatePrepBase):
             state_list = list(qml.math.toarray(state))
             if not set(state_list).issubset({0, 1}):
                 raise ValueError(f"Basis state must only consist of 0s and 1s; got {state_list}")
-
+        state = qml.math.cast(state, int)
         super().__init__(state, wires=wires, id=id)
 
     def _flatten(self):
@@ -287,7 +287,7 @@ class StatePrep(StatePrepBase):
     ndim_params = (1,)
     """int: Number of dimensions per trainable parameter of the operator."""
 
-    # pylint: disable=too-many-arguments
+    # pylint: disable=too-many-arguments,too-many-positional-arguments
     def __init__(
         self,
         state: TensorLike,


Test patch:
diff --git a/tests/ops/qubit/test_state_prep.py b/tests/ops/qubit/test_state_prep.py
index 342aaff5d..23e202e51 100644
--- a/tests/ops/qubit/test_state_prep.py
+++ b/tests/ops/qubit/test_state_prep.py
@@ -14,15 +14,23 @@
 """
 Unit tests for the available qubit state preparation operations.
 """
+import numpy as np
 import pytest
 
 import pennylane as qml
-from pennylane import numpy as np
 from pennylane.wires import WireError
 
 densitymat0 = np.array([[1.0, 0.0], [0.0, 0.0]])
 
 
+def test_basis_state_input_cast_to_int():
+    """Test that the input to BasisState is cast to an int."""
+
+    state = np.array([1.0, 0.0], dtype=np.float64)
+    op = qml.BasisState(state, wires=(0, 1))
+    assert op.data[0].dtype == np.int64
+
+
 @pytest.mark.parametrize(
     "op",
     [