class_docstr: Test gradients for a single measurement
class_docstr_tok: ["Test","gradients","for","a","single","measurement"]
docstr: Test derivatives when using JAX.
docstr_tok: ["Test","derivatives","when","using","JAX","."]
code: def test_jax(self, diff_method, tol, interface):
      """Test derivatives when using JAX."""
      import jax
  
      jnp = jax.numpy
      dev = qml.device("default.qubit", wires=2)
  
      @qml.batch_params
      @qml.qnode(dev, interface=interface, diff_method=diff_method)
      def circuit(x):
          qml.RX(x, wires=0)
          qml.RY(0.1, wires=1)
          qml.CNOT(wires=[0, 1])
          return qml.expval(qml.PauliZ(0) @ qml.PauliX(1))
  
      def cost(x):
          return jnp.sum(circuit(x))
  
      batch_size = 3
      x = jnp.linspace(0.1, 0.5, batch_size)
  
      res = jax.grad(cost)(x)
      expected = -np.sin(0.1) * np.sin(x)
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
imports: import functools
  import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 2 for calling the TestDiffSingle obj's underlying member method code with example usage: obj.test_jax(diff_method, tol, interface) and returns: qml, jnp