class_docstr: Tests that ensure various qubit circuits integrate correctly
class_docstr_tok: ["Tests","that","ensure","various","qubit","circuits","integrate","correctly"]
docstr: Test hessian calculation of a vector valued QNode
docstr_tok: ["Test","hessian","calculation","of","a","vector","valued","QNode"]
code: def test_hessian_vector_valued(
      self,
      interface,
      dev,
      diff_method,
      grad_on_execution,
      device_vjp,
      tol,
  ):
      """Test hessian calculation of a vector valued QNode"""
      if diff_method in {"adjoint", "spsa"}:
          pytest.skip(
              "Adjoint and SPSA do not support second derivative."
          )
  
      options = {}
      if diff_method == "finite-diff":
          options = {"h": 1e-6}
  
      @qnode(
          dev,
          diff_method=diff_method,
          grad_on_execution=grad_on_execution,
          max_diff=2,
          interface=interface,
          device_vjp=device_vjp,
          **options,
      )
      def circuit(x):
          qml.RY(x[0], wires=0)
          qml.RX(x[1], wires=0)
          return qml.probs(wires=0)
  
      x = torch.tensor(
          [1.0, 2.0], requires_grad=True, dtype=torch.float64
      )
      res = circuit(x)
      jac_fn = lambda x: jacobian(circuit, x, create_graph=True)
  
      g = jac_fn(x)
      hess = jacobian(jac_fn, x)
  
      a, b = x.detach().numpy()
  
      assert isinstance(hess, torch.Tensor)
      assert tuple(hess.shape) == (2, 2, 2)
  
      expected_res = [
          0.5 + 0.5 * np.cos(a) * np.cos(b),
          0.5 - 0.5 * np.cos(a) * np.cos(b),
      ]
      assert np.allclose(res.detach(), expected_res, atol=tol, rtol=0)
  
      expected_g = [
          [-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)],
      ]
      assert np.allclose(g.detach(), expected_g, atol=tol, rtol=0)
  
      expected_hess = [
          [
              [
                  -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),
              ],
          ],
      ]
      if diff_method == "finite-diff":
          assert np.allclose(
              hess.detach(), expected_hess, atol=10e-2, rtol=0
          )
      else:
          assert np.allclose(
              hess.detach(), expected_hess, atol=tol, rtol=0
          )
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane import qnode
  from pennylane.devices import DefaultQubit
label_desc: Use image node_id 5 for calling the TestQubitIntegration obj's underlying member method code with example usage: obj.test_hessian_vector_valued(interface, dev, diff_method, grad_on_execution, device_vjp, tol) and returns: qml