class_docstr: Test that the torch execute function can be differentiated
class_docstr_tok: ["Test","that","the","torch","execute","function","can","be","differentiated"]
docstr: Test hessian calculation of a vector valued tape
code: def test_hessian_vector_valued(self, torch_device, tol):
      """Test hessian calculation of a vector valued tape"""
      dev = qml.device("default.qubit.legacy", wires=1)
  
      def circuit(x):
          with qml.queuing.AnnotatedQueue() as q:
              qml.RY(x[0], wires=0)
              qml.RX(x[1], wires=0)
              qml.probs(wires=0)
  
          tape = qml.tape.QuantumScript.from_queue(q)
  
          return torch.stack(
              execute(
                  [tape],
                  dev,
                  gradient_fn=param_shift,
                  interface="torch",
                  max_diff=2,
              )
          )
  
      x = torch.tensor(
          [1.0, 2.0], requires_grad=True, device=torch_device
      )
      res = circuit(x)
  
      if torch_device is not None:
          a, b = x.detach().cpu().numpy()
      else:
          a, b = x.detach().numpy()
  
      expected_res = torch.tensor(
          [
              0.5 + 0.5 * np.cos(a) * np.cos(b),
              0.5 - 0.5 * np.cos(a) * np.cos(b),
          ],
          dtype=res.dtype,
          device=torch_device,
      )
      assert torch.allclose(
          res.detach(), expected_res, atol=tol, rtol=0
      )
  
      def jac_fn(x):
          return torch_functional.jacobian(
              circuit, x, create_graph=True
          )
  
      g = jac_fn(x)
  
      hess = torch_functional.jacobian(jac_fn, x)
  
      expected_g = torch.tensor(
          [
              [
                  -0.5 * np.sin(a) * np.cos(b),
                  -0.5 * np.cos(a) * np.sin(b),
              ],
              [
                  0.5 * np.sin(a) * np.cos(b),
                  0.5 * np.cos(a) * np.sin(b),
              ],
          ],
          dtype=g.dtype,
          device=torch_device,
      )
      assert torch.allclose(g.detach(), expected_g, atol=tol, rtol=0)
  
      expected_hess = torch.tensor(
          [
              [
                  [
                      -0.5 * np.cos(a) * np.cos(b),
                      0.5 * np.sin(a) * np.sin(b),
                  ],
                  [
                      0.5 * np.sin(a) * np.sin(b),
                      -0.5 * np.cos(a) * np.cos(b),
                  ],
              ],
              [
                  [
                      0.5 * np.cos(a) * np.cos(b),
                      -0.5 * np.sin(a) * np.sin(b),
                  ],
                  [
                      -0.5 * np.sin(a) * np.sin(b),
                      0.5 * np.cos(a) * np.cos(b),
                  ],
              ],
          ],
          dtype=hess.dtype,
          device=torch_device,
      )
      assert torch.allclose(
          hess.detach(), expected_hess, 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 2 for calling the TestHigherOrderDerivatives obj's underlying member method code with example usage: obj.test_hessian_vector_valued(torch_device, tol) and returns: torch, torch_functional