Repository: PennyLaneAI/pennylane

Issue:
[BUG][Return-types] Sample does not return the right type with interfaces
### Expected behavior

With the new return types activated `qml.enable_return()`. We expect `Sample` to return a tensor related to the desired interfaces but it currently only returns numpy array instead of `torch.tensor`, `tf.Variable` or `jax.array`.

### Actual behavior

```
import pennylane as qml
import tensorflow as tf

qml.enable_return()

measurements = [qml.sample(qml.PauliZ(0)), qml.sample(wires=[0]), qml.sample(wires=[0, 1])]

devices = ["default.qubit.tf", "default.mixed"]
shots = 100

for m in measurements:
    for d in devices:
        dev = qml.device(d, wires=2, shots=shots)

        def circuit(x):
            qml.Hadamard(wires=[0])
            qml.CRX(x, wires=[0, 1])
            return qml.apply(m)

        qnode = qml.QNode(circuit, dev, diff_method=None)
        res = qnode(tf.Variable(0.5))
        print(type(res))

import torch

measurements = [qml.sample(qml.PauliZ(0)), qml.sample(wires=[0]), qml.sample(wires=[0, 1])]

devices = ["default.qubit.torch", "default.mixed"]
shots = 100

for m in measurements:
    for d in devices:
        dev = qml.device(d, wires=2, shots=shots)

        def circuit(x):
            qml.Hadamard(wires=[0])
            qml.CRX(x, wires=[0, 1])
            return qml.apply(m)

        qnode = qml.QNode(circuit, dev, diff_method=None)
        res = qnode(torch.tensor(0.5))
        print(type(res))

devices = ["default.qubit.jax", "default.mixed"]
shots = 100

for m in measurements:
    for d in devices:
        dev = qml.device(d, wires=2, shots=shots)

        def circuit(x):
            qml.Hadamard(wires=[0])
            qml.CRX(x, wires=[0, 1])
            return qml.apply(m)

        qnode = qml.QNode(circuit, dev, diff_method=None)
        res = qnode(torch.tensor(0.5))
        print(type(res))

```
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
WARNING:absl:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
<class 'jaxlib.xla_extension.DeviceArray'>
<class 'numpy.ndarray'>
<class 'jaxlib.xla_extension.DeviceArray'>
<class 'numpy.ndarray'>
<class 'jaxlib.xla_extension.DeviceArray'>
<class 'numpy.ndarray'>

### Additional information

_No response_

### Source code

_No response_

### Tracebacks

_No response_

### System information

```shell
-
```


### Existing GitHub issues

- [X] I have searched existing GitHub issues to make sure the issue does not already exist.


Discussion:

Resolving patch:
diff --git a/pennylane/_qubit_device.py b/pennylane/_qubit_device.py
--- a/pennylane/_qubit_device.py
+++ b/pennylane/_qubit_device.py
@@ -911,7 +911,7 @@ def _statistics_new(self, observables, shot_range=None, bin_size=None):
 
             elif obs.return_type is Sample:
                 samples = self.sample(obs, shot_range=shot_range, bin_size=bin_size, counts=False)
-                result = qml.math.squeeze(samples)
+                result = self._asarray(qml.math.squeeze(samples))
 
             elif obs.return_type in (Counts, AllCounts):
                 result = self.sample(obs, shot_range=shot_range, bin_size=bin_size, counts=True)


Test patch:
diff --git a/tests/returntypes/test_new_return_types_qnode.py b/tests/returntypes/test_new_return_types_qnode.py
--- a/tests/returntypes/test_new_return_types_qnode.py
+++ b/tests/returntypes/test_new_return_types_qnode.py
@@ -417,7 +417,7 @@ def test_sample(self, measurement, device, shots=100):
         """Test the sample measurement."""
         import tensorflow as tf
 
-        if device == "default.mixed" or "default.qubit":
+        if device in ["default.mixed", "default.qubit"]:
             pytest.skip("Sample need to be rewritten for Tf.")
 
         dev = qml.device(device, wires=2, shots=shots)
@@ -631,7 +631,7 @@ def test_sample(self, measurement, device, shots=100):
         """Test the sample measurement."""
         import torch
 
-        if device == "default.mixed" or "default.qubit":
+        if device in ["default.mixed", "default.qubit"]:
             pytest.skip("Sample need to be rewritten for Torch.")
 
         dev = qml.device(device, wires=2, shots=shots)
@@ -1290,7 +1290,7 @@ def test_expval_sample(self, measurement, device, shots=100):
         """Test the expval and sample measurements together."""
         import tensorflow as tf
 
-        if device == "default.mixed" or "default.qubit":
+        if device in ["default.mixed", "default.qubit"]:
             pytest.skip("Sample must be reworked with interfaces.")
 
         dev = qml.device(device, wires=2, shots=shots)
@@ -1553,7 +1553,7 @@ def test_expval_sample(self, measurement, device, shots=100):
         """Test the expval and sample measurements together."""
         import torch
 
-        if device == "default.mixed" or "default.qubit":
+        if device in ["default.mixed", "default.qubit"]:
             pytest.skip("Sample need to be rewritten for interfaces.")
 
         dev = qml.device(device, wires=2, shots=shots)