class_docstr: Tests to ensure the transform is fully differentiable in all interfaces for
  single-qubit unitary decompositions.
docstr: Tests differentiability in torch interface.
docstr_tok: ["Tests","differentiability","in","torch","interface","."]
code: def test_gradient_unitary_to_rot_torch(self, rot_angles, diff_method):
      """Tests differentiability in torch interface."""
      import torch
  
      def qfunc_with_qubit_unitary(angles):
          z = angles[0]
          x = angles[1]
  
          # Had to do this in order to make a torch tensor of torch tensors
          Z_mat = torch.stack(
              [
                  torch.exp(-1j * z / 2),
                  torch.tensor(0.0),
                  torch.tensor(0.0),
                  torch.exp(1j * z / 2),
              ]
          ).reshape(2, 2)
  
          # Variables need to be complex
          c = torch.cos(x / 2).type(torch.complex64)
          s = torch.sin(x / 2) * 1j
  
          X_mat = torch.stack([c, -s, -s, c]).reshape(2, 2)
  
          qml.Hadamard(wires="a")
          qml.QubitUnitary(Z_mat, wires="a")
          qml.QubitUnitary(X_mat, wires="b")
          qml.CNOT(wires=["b", "a"])
          return qml.expval(qml.PauliX(wires="a"))
  
      dev = qml.device("default.qubit", wires=["a", "b"])
  
      original_qnode = qml.QNode(
          original_qfunc_for_grad, dev, diff_method=diff_method
      )
      original_input = torch.tensor(
          rot_angles, dtype=torch.float64, requires_grad=True
      )
      original_result = original_qnode(original_input)
  
      transformed_qfunc = unitary_to_rot(qfunc_with_qubit_unitary)
      transformed_qnode = qml.QNode(
          transformed_qfunc, dev, diff_method=diff_method
      )
      transformed_input = torch.tensor(
          rot_angles, dtype=torch.float64, requires_grad=True
      )
      transformed_result = transformed_qnode(transformed_input)
  
      assert qml.math.allclose(
          original_result, transformed_result, atol=1e-7
      )
  
      original_result.backward()
      transformed_result.backward()
  
      assert qml.math.allclose(
          original_input.grad, transformed_input.grad, atol=1e-7
      )
  
imports: from itertools import product
  import pytest
  from gate_data import I, Z, S, T, H, X
  from test_optimization.utils import check_matrix_equivalence
  import pennylane
  from pennylane import numpy
  from pennylane.wires import Wires
  from pennylane.transforms import unitary_to_rot
label_desc: Use image node_id 2 for calling the TestQubitUnitaryDifferentiability obj's underlying member method code with example usage: obj.test_gradient_unitary_to_rot_torch(rot_angles, diff_method) and returns: qml