class_docstr: Test for caching behaviour
class_docstr_tok: ["Test","for","caching","behaviour"]
docstr: Test that caching produces the optimum number of adjoint evaluations
  when mode=backward
docstr_tok: ["Test","that","caching","produces","the","optimum","number","of","adjoint","evaluations","when","mode=backward"]
code: def test_caching_adjoint_backward(self):
      """Test that caching produces the optimum number of adjoint evaluations
      when mode=backward"""
      dev = qml.device("default.qubit.legacy", wires=2)
      params = jax.numpy.array([0.1, 0.2, 0.3])
  
      def cost(a, cache):
          with qml.queuing.AnnotatedQueue() as q:
              qml.RY(a[0], wires=0)
              qml.RX(a[1], wires=0)
              qml.RY(a[2], wires=0)
              qml.expval(qml.PauliZ(0))
  
          tape = qml.tape.QuantumScript.from_queue(q)
  
          return execute(
              [tape],
              dev,
              gradient_fn="device",
              cache=cache,
              grad_on_execution=False,
              gradient_kwargs={"method": "adjoint_jacobian"},
          )[0]
  
      # Without caching, 2 evaluations are required.
      # 1 for the forward pass, and one per output dimension
      # on the backward pass.
      jax.grad(cost)(params, cache=None)
      assert dev.num_executions == 2
  
      # With caching, also 2 evaluations are required. One
      # for the forward pass, and one for the backward pass.
      dev._num_executions = 0
      jac_fn = jax.grad(cost)
      jac_fn(params, cache=True)
      assert dev.num_executions == 2
  
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 TestCaching obj's underlying member method code with example usage: obj.test_caching_adjoint_backward() and returns: execute