class_docstr: Tests kernel matrix computations.
class_docstr_tok: ["Tests","kernel","matrix","computations","."]
docstr: Test differentiability of the kernel matrix methods with PyTorch.
docstr_tok: ["Test","differentiability","of","the","kernel","matrix","methods","with","PyTorch","."]
code: def test_torch(self):
      """Test differentiability of the kernel matrix methods with PyTorch."""
      import torch
  
      X1 = torch.tensor(self.X1, requires_grad=True)
      X2 = torch.tensor(self.X2, requires_grad=True)
      K1 = kern.square_kernel_matrix(X1, _diffable_kernel, False)
      K2 = kern.kernel_matrix(X1, X2, _diffable_kernel)
      K3 = kern.square_kernel_matrix(X1, _diffable_kernel, True)
  
      assert qml.math.allclose(K1, self.expected_K1)
      assert qml.math.allclose(K2, self.expected_K2)
      assert qml.math.allclose(K3, self.expected_K3)
  
      jac = torch.autograd.functional.jacobian
      dK1 = jac(
          partial(
              kern.square_kernel_matrix,
              kernel=_diffable_kernel,
              assume_normalized_kernel=False,
          ),
          X1,
      )
      assert qml.math.allclose(dK1, self.expected_dK1)
      dK2 = jac(
          partial(kern.kernel_matrix, kernel=_diffable_kernel), (X1, X2)
      )
      assert qml.math.allclose(dK2[0], self.expected_dK2[0])
      assert qml.math.allclose(dK2[1], self.expected_dK2[1])
      dK3 = jac(
          partial(
              kern.square_kernel_matrix,
              kernel=_diffable_kernel,
              assume_normalized_kernel=True,
          ),
          X1,
      )
      assert qml.math.allclose(dK3, self.expected_dK3)
  
imports: import math
  import sys
  from functools import partial
  import pytest
  import numpy
  import pennylane
  import pennylane.kernels
  from pennylane import numpy
label_desc: Use image node_id 6 for calling the TestKernelMatrix obj's underlying member method code with example usage: obj.test_torch() without return types