class_docstr: Tests that ensure various qubit circuits integrate correctly when computing higher-order derivatives
class_docstr_tok: ["Tests","that","ensure","various","qubit","circuits","integrate","correctly","when","computing","higher-order","derivatives"]
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,
      dev,
      diff_method,
      grad_on_execution,
      device_vjp,
      interface,
      tol,
  ):
      """Test hessian calculation of a vector valued QNode that has separate input arguments"""
      gradient_kwargs = {}
      if diff_method == "adjoint":
          pytest.skip("Adjoint does not support second derivative.")
      elif diff_method == "spsa":
          gradient_kwargs = {
              "h": H_FOR_SPSA,
              "num_directions": 20,
              "sampler_rng": np.random.default_rng(SEED_FOR_SPSA),
          }
          tol = TOL_FOR_SPSA
  
      @qnode(
          dev,
          diff_method=diff_method,
          interface=interface,
          grad_on_execution=grad_on_execution,
          device_vjp=device_vjp,
          max_diff=2,
          **gradient_kwargs,
      )
      def circuit(a, b):
          qml.RY(a, wires=0)
          qml.RX(b, wires=0)
          return qml.probs(wires=0)
  
      a = jax.numpy.array(1.0)
      b = jax.numpy.array(2.0)
      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 np.allclose(res, expected_res, atol=tol, rtol=0)
  
      jac_fn = jax.jacobian(circuit, argnums=[0, 1])
      g = jac_fn(a, b)
  
      expected_g = np.array(
          [
              [
                  -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, expected_g.T, atol=tol, rtol=0)
  
      hess = jax.jacobian(jac_fn, argnums=[0, 1])(a, b)
  
      expected_hess = np.array(
          [
              [
                  [
                      -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.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 == "finite-diff":
          assert np.allclose(hess, expected_hess, atol=10e-2, rtol=0)
      else:
          assert np.allclose(hess, expected_hess, atol=tol, rtol=0)
  
imports: from itertools import product
  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 TestQubitIntegrationHigherOrder obj's underlying member method code with example usage: obj.test_hessian_vector_valued_separate_args(dev, diff_method, grad_on_execution, device_vjp, interface, tol) and returns: qml