class_docstr: Tests for integration with the PassthruQNode
class_docstr_tok: ["Tests","for","integration","with","the","PassthruQNode"]
docstr: Tests that the gradient of an arbitrary U3 gate is correct
  using the Autograd interface, using a variety of differentiation methods.
docstr_tok: ["Tests","that","the","gradient","of","an","arbitrary","U3","gate","is","correct","using","the","Autograd","interface",",","using","a","variety","of","differentiation","methods","."]
code: def test_autograd_interface_gradient(
      self, operation, diff_method, tol
  ):
      """Tests that the gradient of an arbitrary U3 gate is correct
      using the Autograd interface, using a variety of differentiation methods.
      """
      dev = qml.device("default.mixed", wires=1)
      state = np.array(
          1j * np.array([1, -1]) / np.sqrt(2), requires_grad=False
      )
  
      @qml.qnode(dev, diff_method=diff_method, interface="autograd")
      def circuit(x, weights, w):
          """In this example, a mixture of scalar
          arguments, array arguments, and keyword arguments are used."""
          qml.StatePrep(state, wires=w)
          operation(x, weights[0], weights[1], wires=w)
          return qml.expval(qml.PauliX(w))
  
      def cost(params):
          """Perform some classical processing"""
          return circuit(params[0], params[1:], w=0) ** 2
  
      theta = 0.543
      phi = -0.234
      lam = 0.654
  
      params = np.array([theta, phi, lam], requires_grad=True)
  
      res = cost(params)
      expected_cost = (
          np.sin(lam) * np.sin(phi)
          - np.cos(theta) * np.cos(lam) * np.cos(phi)
      ) ** 2
      assert np.allclose(res, expected_cost, atol=tol, rtol=0)
  
      # Check that the correct differentiation method is being used.
      if diff_method == "backprop":
          assert circuit.gradient_fn == "backprop"
      elif diff_method == "parameter-shift":
          assert circuit.gradient_fn is qml.gradients.param_shift
      else:
          assert circuit.gradient_fn is qml.gradients.finite_diff
  
      res = qml.grad(cost)(params)
      expected_grad = (
          np.array(
              [
                  np.sin(theta) * np.cos(lam) * np.cos(phi),
                  np.cos(theta) * np.cos(lam) * np.sin(phi)
                  + np.sin(lam) * np.cos(phi),
                  np.cos(theta) * np.sin(lam) * np.cos(phi)
                  + np.cos(lam) * np.sin(phi),
              ]
          )
          * 2
          * (
              np.sin(lam) * np.sin(phi)
              - np.cos(theta) * np.cos(lam) * np.cos(phi)
          )
      )
      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 11 for calling the TestPassthruIntegration obj's underlying member method code with example usage: obj.test_autograd_interface_gradient(operation, diff_method, tol) and returns: qml, unknown