class_docstr: Test that using the QNode with Autograd integrates with the PennyLane stack
class_docstr_tok: ["Test","that","using","the","QNode","with","Autograd","integrates","with","the","PennyLane","stack"]
docstr: Test that operation and nested tape expansion
  is differentiable
docstr_tok: ["Test","that","operation","and","nested","tape","expansion","is","differentiable"]
code: def test_differentiable_expand(
      self,
      interface,
      dev,
      diff_method,
      grad_on_execution,
      device_vjp,
      tol,
  ):
      """Test that operation and nested tape expansion
      is differentiable"""
      kwargs = dict(
          diff_method=diff_method,
          interface=interface,
          grad_on_execution=grad_on_execution,
          device_vjp=device_vjp,
      )
  
      if diff_method == "spsa":
          kwargs["sampler_rng"] = np.random.default_rng(SEED_FOR_SPSA)
          kwargs["num_directions"] = 10
          tol = TOL_FOR_SPSA
  
      # pylint: disable=too-few-public-methods
      class U3(qml.U3):
          """Custom U3."""
  
          def decomposition(self):
              theta, phi, lam = self.data
              wires = self.wires
              return [
                  qml.Rot(lam, theta, -lam, wires=wires),
                  qml.PhaseShift(phi + lam, wires=wires),
              ]
  
      a = np.array(0.1, requires_grad=False)
      p = np.array([0.1, 0.2, 0.3], requires_grad=True)
  
      @qnode(dev, **kwargs)
      def circuit(a, p):
          qml.RX(a, wires=0)
          U3(p[0], p[1], p[2], wires=0)
          return qml.expval(qml.PauliX(0))
  
      res = circuit(a, p)
      expected = np.cos(a) * np.cos(p[1]) * np.sin(p[0]) + np.sin(a) * (
          np.cos(p[2]) * np.sin(p[1])
          + np.cos(p[0]) * np.cos(p[1]) * np.sin(p[2])
      )
      # assert isinstance(res, np.ndarray)
      # assert res.shape == ()
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
      res = qml.grad(circuit)(a, p)
  
      # assert isinstance(res, np.ndarray)
      # assert len(res) == 3
  
      expected = np.array(
          [
              np.cos(p[1])
              * (
                  np.cos(a) * np.cos(p[0])
                  - np.sin(a) * np.sin(p[0]) * np.sin(p[2])
              ),
              np.cos(p[1]) * np.cos(p[2]) * np.sin(a)
              - np.sin(p[1])
              * (
                  np.cos(a) * np.sin(p[0])
                  + np.cos(p[0]) * np.sin(a) * np.sin(p[2])
              ),
              np.sin(a)
              * (
                  np.cos(p[0]) * np.cos(p[1]) * np.cos(p[2])
                  - np.sin(p[1]) * np.sin(p[2])
              ),
          ]
      )
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
imports: import autograd
  import autograd.numpy
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane import qnode
  from pennylane.devices import DefaultQubit
label_desc: Use image node_id 11 for calling the TestQNode obj's underlying member method code with example usage: obj.test_differentiable_expand(interface, dev, diff_method, grad_on_execution, device_vjp, tol) and returns: qml, list