class_docstr: Test that the torch execute function can be differentiated
class_docstr_tok: ["Test","that","the","torch","execute","function","can","be","differentiated"]
docstr: Tests that the output of the parameter-shift transform
  can be differentiated using torch, yielding second derivatives.
code: def test_parameter_shift_hessian(self, torch_device, params, tol):
      """Tests that the output of the parameter-shift transform
      can be differentiated using torch, yielding second derivatives."""
      # pylint: disable=unused-argument
      dev = qml.device("default.qubit.legacy", wires=2)
      params = torch.tensor(
          [0.543, -0.654], requires_grad=True, dtype=torch.float64
      )
  
      def cost_fn(x):
          with qml.queuing.AnnotatedQueue() as q1:
              qml.RX(x[0], wires=[0])
              qml.RY(x[1], wires=[1])
              qml.CNOT(wires=[0, 1])
              qml.var(qml.PauliZ(0) @ qml.PauliX(1))
  
          tape1 = qml.tape.QuantumScript.from_queue(q1)
  
          with qml.queuing.AnnotatedQueue() as q2:
              qml.RX(x[0], wires=0)
              qml.RY(x[0], wires=1)
              qml.CNOT(wires=[0, 1])
              qml.probs(wires=1)
  
          tape2 = qml.tape.QuantumScript.from_queue(q2)
  
          result = execute(
              [tape1, tape2],
              dev,
              gradient_fn=param_shift,
              interface="torch",
              max_diff=2,
          )
          return result[0] + result[1][0]
  
      res = cost_fn(params)
      x, y = params.detach()
      expected = torch.as_tensor(
          0.5 * (3 + np.cos(x) ** 2 * np.cos(2 * y))
      )
      assert torch.allclose(res, expected, atol=tol, rtol=0)
  
      res.backward()
      expected = torch.tensor(
          [
              -np.cos(x) * np.cos(2 * y) * np.sin(x),
              -np.cos(x) ** 2 * np.sin(2 * y),
          ]
      )
      assert torch.allclose(
          params.grad.detach(), expected, atol=tol, rtol=0
      )
  
      res = torch.autograd.functional.hessian(cost_fn, params)
      expected = torch.tensor(
          [
              [
                  -np.cos(2 * x) * np.cos(2 * y),
                  np.sin(2 * x) * np.sin(2 * y),
              ],
              [
                  np.sin(2 * x) * np.sin(2 * y),
                  -2 * np.cos(x) ** 2 * np.cos(2 * y),
              ],
          ]
      )
      assert torch.allclose(res, expected, atol=tol, rtol=0)
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane.gradients import finite_diff, param_shift
  from pennylane import execute
label_desc: Use image node_id 1 for calling the TestHigherOrderDerivatives obj's underlying member method code with example usage: obj.test_parameter_shift_hessian(torch_device, params, tol) and returns: unknown