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 that has separate input arguments
docstr_tok: ["Test","hessian","calculation","of","a","vector","valued","QNode","that","has","separate","input","arguments"]
code: def test_hessian_vector_valued_separate_args(
      self,
      interface,
      dev,
      diff_method,
      grad_on_execution,
      device_vjp,
      tol,
  ):
      """Test hessian calculation of a vector valued QNode that has separate input arguments"""
      if diff_method not in {"parameter-shift", "backprop"}:
          pytest.skip("Test only supports parameter-shift or backprop")
  
      @qnode(
          dev,
          diff_method=diff_method,
          interface=interface,
          grad_on_execution=grad_on_execution,
          device_vjp=device_vjp,
          max_diff=2,
      )
      def circuit(a, b):
          qml.RY(a, wires=0)
          qml.RX(b, wires=0)
          return qml.probs(wires=0)
  
      a = np.array(1.0, requires_grad=True)
      b = np.array(2.0, requires_grad=True)
      res = circuit(a, b)
  
      expected_res = [
          0.5 + 0.5 * np.cos(a) * np.cos(b),
          0.5 - 0.5 * np.cos(a) * np.cos(b),
      ]
      assert isinstance(res, np.ndarray)
      assert res.shape == (
          2,
      )  # pylint: disable=comparison-with-callable
      assert np.allclose(res, expected_res, atol=tol, rtol=0)
  
      jac_fn = qml.jacobian(circuit)
      g = jac_fn(a, b)
      assert isinstance(g, tuple) and len(g) == 2
  
      expected_g = (
          [-0.5 * np.sin(a) * np.cos(b), 0.5 * np.sin(a) * np.cos(b)],
          [-0.5 * np.cos(a) * np.sin(b), 0.5 * np.cos(a) * np.sin(b)],
      )
      assert g[0].shape == (2,)
      assert np.allclose(g[0], expected_g[0], atol=tol, rtol=0)
  
      assert g[1].shape == (2,)
      assert np.allclose(g[1], expected_g[1], atol=tol, rtol=0)
  
      def jac_fn_a(*args):
          return jac_fn(*args)[0]
  
      def jac_fn_b(*args):
          return jac_fn(*args)[1]
  
      hess_a = qml.jacobian(jac_fn_a)(a, b)
      hess_b = qml.jacobian(jac_fn_b)(a, b)
      assert isinstance(hess_a, tuple) and len(hess_a) == 2
      assert isinstance(hess_b, tuple) and len(hess_b) == 2
  
      exp_hess_a = (
          [-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)],
      )
      exp_hess_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)],
      )
  
      if diff_method in {"finite-diff"}:
          tol = 10e-2
  
      for hess, exp_hess in zip(
          [hess_a, hess_b], [exp_hess_a, exp_hess_b]
      ):
          assert np.allclose(hess[0], exp_hess[0], atol=tol, rtol=0)
          assert np.allclose(hess[1], exp_hess[1], atol=tol, rtol=0)
  
imports: import autograd
  import autograd.numpy
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane import qnode
  from pennylane.devices import DefaultQubit
label_desc: Use image node_id 12 for calling the TestQubitIntegration obj's underlying member method code with example usage: obj.test_hessian_vector_valued_separate_args(interface, dev, diff_method, grad_on_execution, device_vjp, tol) and returns: qml, jac_fn, jac_fn