class_docstr: Test that tape expansion within the QNode integrates correctly
  with the Torch interface
class_docstr_tok: ["Test","that","tape","expansion","within","the","QNode","integrates","correctly","with","the","Torch","interface"]
docstr: Test that a *supported* operation with no gradient recipe is only
  expanded for parameter-shift and finite-differences when it is trainable.
docstr_tok: ["Test","that","a","*","supported","*","operation","with","no","gradient","recipe","is","only","expanded","for","parameter-shift","and","finite-differences","when","it","is","trainable","."]
code: def test_gradient_expansion_trainable_only(
      self,
      dev,
      diff_method,
      grad_on_execution,
      device_vjp,
      max_diff,
  ):
      """Test that a *supported* operation with no gradient recipe is only
      expanded for parameter-shift and finite-differences when it is trainable.
      """
      if diff_method not in (
          "parameter-shift",
          "finite-diff",
          "spsa",
          "hadamard",
      ):
          pytest.skip("Only supports gradient transforms")
  
      class PhaseShift(
          qml.PhaseShift
      ):  # pylint:disable=too-few-public-methods
          grad_method = None
  
          def decomposition(self):
              return [qml.RY(3 * self.data[0], wires=self.wires)]
  
      @qnode(
          dev,
          diff_method=diff_method,
          grad_on_execution=grad_on_execution,
          max_diff=max_diff,
          interface="torch",
          device_vjp=device_vjp,
      )
      def circuit(x, y):
          qml.Hadamard(wires=0)
          PhaseShift(x, wires=0)
          PhaseShift(2 * y, wires=0)
          return qml.expval(qml.PauliX(0))
  
      x = torch.tensor(0.5, requires_grad=True)
      y = torch.tensor(0.7, requires_grad=False)
  
      loss = circuit(x, y)
      loss.backward()
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane import qnode
  from pennylane.devices import DefaultQubit
label_desc: Use image node_id 2 for calling the TestTapeExpansion obj's underlying member method code with example usage: obj.test_gradient_expansion_trainable_only(dev, diff_method, grad_on_execution, device_vjp, max_diff) and returns: qml, list