class_docstr: Tests for the ``adjoint_jacobian`` method
class_docstr_tok: ["Tests","for","the","``","adjoint_jacobian","``","method"]
docstr: Tests that the gradients of circuits match between the finite difference and device
  methods.
docstr_tok: ["Tests","that","the","gradients","of","circuits","match","between","the","finite","difference","and","device","methods","."]
code: def test_gradients(self, op, obs, tol, dev):
      """Tests that the gradients of circuits match between the finite difference and device
      methods."""
  
      with qml.queuing.AnnotatedQueue() as q:
          qml.Hadamard(wires=0)
          qml.RX(0.543, wires=0)
          qml.CNOT(wires=[0, 1])
  
          qml.apply(op)
  
          qml.Rot(1.3, -2.3, 0.5, wires=[0])
          qml.RZ(-0.5, wires=0)
          qml.adjoint(qml.RY(0.5, wires=1))
          qml.CNOT(wires=[0, 1])
  
          qml.expval(obs(wires=0))
          qml.expval(qml.PauliZ(wires=1))
  
      tape = qml.tape.QuantumScript.from_queue(q)
      tape.trainable_params = set(range(1, 1 + op.num_params))
  
      tapes, fn = qml.gradients.finite_diff(tape)
      grad_F = fn(qml.execute(tapes, dev, None))
      grad_D = dev.adjoint_jacobian(tape)
  
      assert isinstance(grad_D, tuple)
      assert len(grad_D) == 2
  
      if op.num_params == 1:
          assert all(
              isinstance(g, np.ndarray) and g.shape == ()
              for g in grad_D
          )
      else:
          assert all(
              isinstance(g, tuple) and len(g) == op.num_params
              for g in grad_D
          )
          assert all(
              all(isinstance(_g, np.ndarray) for _g in g)
              for g in grad_D
          )
  
      assert np.allclose(grad_D, grad_F, atol=tol, rtol=0)
  
imports: import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 12 for calling the TestAdjointJacobian obj's underlying member method code with example usage: obj.test_gradients(op, obs, tol, dev) without return types