Repository: PennyLaneAI/pennylane

Issue:
qml.jacobian returns 0 for all circuits
### Expected behavior

```python
def circuit_function(weights):
    qml.Hadamard(wires=0)
    qml.RY(weights[0], wires=0)
    return [ qml.expval(qml.PauliZ(wires=0)) ]

weights         = [0]
control_weights = np.array(weights, requires_grad=True)

dev   = qml.device("default.qubit", wires=1, shots=None)
qNode = qml.QNode(circuit_function, dev, diff_method="backprop")

gradients   = qml.jacobian(lambda x: np.stack(qNode(x)))(control_weights)
slope       = sum(gradients)
print(f'slope={slope}')
print(f'gradients={gradients}')
```

-------------------------------
Expected behavour is for gradients to return

```python
slope=[-1.]
gradients=[[-1.]]
```

### Actual behavior

```python
slope=[0]
gradients=[[0]]
```

change weights to [0.0] fixed this problem

```python
slope=[-1.]
gradients=[[-1.]]
```

### Additional information

This behaviour was really hard to track down and could easily break code.  PennyLane code should be assuming that rotations are floating point values even if presented in the control weights as integer values.

Thanks,
Ian
cs.uwaterloo.ca/~ijdavis

### Source code

```shell
def circuit_function(weights):
    qml.Hadamard(wires=0)
    qml.RY(weights[0], wires=0)
    return [ qml.expval(qml.PauliZ(wires=0)) ]

weights         = [0]
control_weights = np.array(weights, requires_grad=True)

dev   = qml.device("default.qubit", wires=1, shots=None)
qNode = qml.QNode(circuit_function, dev, diff_method="backprop")

gradients   = qml.jacobian(lambda x: np.stack(qNode(x)))(control_weights)
slope       = sum(gradients)
print(f'slope={slope}')
print(f'gradients={gradients}')
```


### Tracebacks

_No response_

### System information

```python
Name: PennyLane
Version: 0.33.1
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /usr/local/lib/python3.10/dist-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Lightning

Platform info:           Linux-5.15.120+-x86_64-with-glibc2.35
Python version:          3.10.12
Numpy version:           1.23.5
Scipy version:           1.11.3
Installed devices:
```


### 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/_grad.py b/pennylane/_grad.py
--- a/pennylane/_grad.py
+++ b/pennylane/_grad.py
@@ -92,6 +92,8 @@ def _get_grad_fn(self, args):
         for idx, arg in enumerate(args):
             trainable = getattr(arg, "requires_grad", None) or isinstance(arg, ArrayBox)
             if trainable:
+                if arg.dtype.name[:3] == "int":
+                    raise ValueError("Autograd does not support differentiation of ints.")
                 argnum.append(idx)
 
         if len(argnum) == 1:
@@ -135,7 +137,7 @@ def _grad_with_forward(fun, x):
         value."""
         vjp, ans = _make_vjp(fun, x)
 
-        if not vspace(ans).size == 1:
+        if vspace(ans).size != 1:
             raise TypeError(
                 "Grad only applies to real scalar-output functions. "
                 "Try jacobian, elementwise_grad or holomorphic_grad."
@@ -299,6 +301,8 @@ def _get_argnum(args):
         for idx, arg in enumerate(args):
             trainable = getattr(arg, "requires_grad", None) or isinstance(arg, ArrayBox)
             if trainable:
+                if arg.dtype.name[:3] == "int":
+                    raise ValueError("Autograd does not support differentiation of ints.")
                 argnum.append(idx)
 
         return argnum


Test patch:
diff --git a/tests/math/test_functions.py b/tests/math/test_functions.py
--- a/tests/math/test_functions.py
+++ b/tests/math/test_functions.py
@@ -1550,7 +1550,7 @@ def test_array_indexing(self, t):
     def test_array_indexing_autograd(self):
         """Test that indexing with a sequence properly extracts
         the elements from the flattened tensor"""
-        t = np.array([[[1, 2], [3, 4], [-1, 1]], [[5, 6], [0, -1], [2, 1]]])
+        t = np.array([[[1, 2], [3, 4], [-1, 1]], [[5, 6], [0, -1], [2, 1]]], dtype=np.float64)
         indices = [0, 2, 3, 6, -2]
 
         def cost_fn(t):
@@ -1593,7 +1593,7 @@ def test_multidimensional_indexing_along_axis(self, t):
     def test_multidimensional_indexing_along_axis_autograd(self):
         """Test that indexing with a sequence properly extracts
         the elements from the specified tensor axis"""
-        t = np.array([[[1, 2], [3, 4], [-1, 1]], [[5, 6], [0, -1], [2, 1]]])
+        t = np.array([[[1, 2], [3, 4], [-1, 1]], [[5, 6], [0, -1], [2, 1]]], dtype=np.float64)
         indices = np.array([[0, 0], [1, 0]])
 
         def cost_fn(t):
diff --git a/tests/ops/op_math/test_exp.py b/tests/ops/op_math/test_exp.py
--- a/tests/ops/op_math/test_exp.py
+++ b/tests/ops/op_math/test_exp.py
@@ -840,7 +840,7 @@ def circuit(phi):
     def test_autograd_measurement(self):
         """Test exp in a measurement with gradient and autograd."""
 
-        x = qml.numpy.array(2)
+        x = qml.numpy.array(2.0)
 
         @qml.qnode(qml.device("default.qubit", wires=1))
         def circuit(x):
diff --git a/tests/test_classical_gradients.py b/tests/test_classical_gradients.py
--- a/tests/test_classical_gradients.py
+++ b/tests/test_classical_gradients.py
@@ -24,6 +24,22 @@
 np.random.seed(42)
 
 
+def test_grad_no_ints():
+    """Test that grad raises a `ValueError` if the trainable parameter is an int."""
+
+    x = qml.numpy.array(2)
+
+    def f(x):
+        return x**2
+
+    with pytest.raises(ValueError, match="Autograd does not support differentiation of ints."):
+        qml.grad(f)(x)
+
+    y = qml.numpy.array([2, 2])
+    with pytest.raises(ValueError, match="Autograd does not support differentiation of ints."):
+        qml.jacobian(f)(y)
+
+
 class TestGradientUnivar:
     """Tests gradients of univariate unidimensional functions."""