class_docstr: Unit tests for jax execution
class_docstr_tok: ["Unit","tests","for","jax","execution"]
docstr: Test that `grad_on_execution=False` uses the `device.execute_and_gradients`.
docstr_tok: ["Test","that","`","grad_on_execution=False","`","uses","the","`","device.execute_and_gradients","`","."]
code: def test_no_grad_on_execution(self, mocker):
      """Test that `grad_on_execution=False` uses the `device.execute_and_gradients`."""
      dev = qml.device("default.qubit.legacy", wires=1)
      spy_execute = mocker.spy(
          qml.devices.DefaultQubitLegacy, "batch_execute"
      )
      spy_gradients = mocker.spy(
          qml.devices.DefaultQubitLegacy, "execute_and_gradients"
      )
  
      def cost(a):
          with qml.queuing.AnnotatedQueue() as q:
              qml.RY(a[0], wires=0)
              qml.RX(a[1], wires=0)
              qml.expval(qml.PauliZ(0))
  
          tape = qml.tape.QuantumScript.from_queue(q)
          return execute(
              [tape],
              dev,
              gradient_fn="device",
              grad_on_execution=False,
              gradient_kwargs={"method": "adjoint_jacobian"},
          )[0]
  
      a = jax.numpy.array([0.1, 0.2])
      cost(a)
  
      assert dev.num_executions == 1
      spy_execute.assert_called()
      spy_gradients.assert_not_called()
  
      jax.grad(cost)(a)
      spy_gradients.assert_called()
  
imports: import pytest
  import numpy
  import pennylane
  from pennylane.gradients import param_shift
  from pennylane import execute
label_desc: Use image node_id 5 for calling the TestJaxExecuteUnitTests obj's underlying member method code with example usage: obj.test_no_grad_on_execution(mocker) and returns: execute