class_docstr: Tests for the ``adjoint_jacobian`` method
class_docstr_tok: ["Tests","for","the","``","adjoint_jacobian","``","method"]
docstr: Test that computing the gradient of a tape that obtains the
  expectation value of a Hermitian operator works correctly.
docstr_tok: ["Test","that","computing","the","gradient","of","a","tape","that","obtains","the","expectation","value","of","a","Hermitian","operator","works","correctly","."]
code: def test_gradient_of_tape_with_hermitian(self, tol):
      """Test that computing the gradient of a tape that obtains the
      expectation value of a Hermitian operator works correctly."""
      dev = qml.device("default.qubit.legacy", wires=3)
  
      a, b, c = [0.5, 0.3, -0.7]
  
      def ansatz(a, b, c):
          qml.RX(a, wires=0)
          qml.RX(b, wires=1)
          qml.RX(c, wires=2)
          qml.CNOT(wires=[0, 1])
          qml.CNOT(wires=[1, 2])
  
      mx = qml.matrix(qml.PauliX(0) @ qml.PauliY(2))
      with qml.queuing.AnnotatedQueue() as q:
          ansatz(a, b, c)
          qml.RX(a, wires=0)
          qml.expval(qml.Hermitian(mx, wires=[0, 2]))
  
      tape = qml.tape.QuantumScript.from_queue(q)
      tape.trainable_params = {0, 1, 2}
      res = dev.adjoint_jacobian(tape)
  
      expected = [
          np.cos(a) * np.sin(b) * np.sin(c),
          np.cos(b) * np.sin(a) * np.sin(c),
          np.cos(c) * np.sin(b) * np.sin(a),
      ]
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
imports: import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 16 for calling the TestAdjointJacobian obj's underlying member method code with example usage: obj.test_gradient_of_tape_with_hermitian(tol) without return types