class_docstr: Test the gradient of qml.math.fidelity
docstr: Test gradients are correct for torch
code: def test_grad_torch(
      self, x, cost_fn, expected_res, expected_grad, tol
  ):
      """Test gradients are correct for torch"""
      x = torch.from_numpy(np.array(x)).requires_grad_()
      res = cost_fn(x)
      res.backward()
      grad = x.grad
  
      assert qml.math.allclose(res, expected_res(x), tol)
      assert qml.math.allclose(grad, expected_grad(x), tol)
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 4 for calling the TestGradient obj's underlying member method code with example usage: obj.test_grad_torch(x, cost_fn, expected_res, expected_grad, tol) without return types