class_docstr: Tests for integration with the PassthruQNode
class_docstr_tok: ["Tests","for","integration","with","the","PassthruQNode"]
docstr: Tests that the gradient of expval is correct
docstr_tok: ["Tests","that","the","gradient","of","expval","is","correct"]
code: def test_expval_gradient(self, tol):
      """Tests that the gradient of expval is correct"""
      dev = qml.device("default.mixed", wires=2)
  
      @qml.qnode(dev, diff_method="backprop", interface="autograd")
      def circuit(a, b):
          qml.RX(a, wires=0)
          qml.CRX(b, wires=[0, 1])
          return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))
  
      a = np.array(-0.234, requires_grad=True)
      b = np.array(0.654, requires_grad=True)
  
      res = circuit(a, b)
      expected_cost = 0.5 * (
          np.cos(a) * np.cos(b) + np.cos(a) - np.cos(b) + 1
      )
      assert np.allclose(res, expected_cost, atol=tol, rtol=0)
  
      res = qml.grad(circuit)(a, b)
      expected_grad = np.array(
          [
              -0.5 * np.sin(a) * (np.cos(b) + 1),
              0.5 * np.sin(b) * (1 - np.cos(a)),
          ]
      )
      assert np.allclose(res, expected_grad, atol=tol, rtol=0)
  
imports: import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.devices.default_mixed import DefaultMixed
  from pennylane import DeviceError
label_desc: Use image node_id 9 for calling the TestPassthruIntegration obj's underlying member method code with example usage: obj.test_expval_gradient(tol) and returns: qml