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 that the state can be returned and differentiated
docstr_tok: ["Test","that","the","state","can","be","returned","and","differentiated"]
code: def test_state(
      self, dev_name, diff_method, grad_on_execution, interface, tol
  ):
      """Test that the state can be returned and differentiated"""
      if diff_method == "adjoint":
          pytest.skip("Adjoint does not support states")
  
      num_wires = 2
  
      if diff_method == "hadamard":
          num_wires = 3
  
      dev = qml.device(dev_name, wires=num_wires)
  
      x = jax.numpy.array(0.543)
      y = jax.numpy.array(-0.654)
  
      @qnode(
          dev,
          diff_method=diff_method,
          interface=interface,
          grad_on_execution=grad_on_execution,
      )
      def circuit(x, y):
          qml.RX(x, wires=[0])
          qml.RY(y, wires=[1])
          qml.CNOT(wires=[0, 1])
          return qml.state()
  
      def cost_fn(x, y):
          res = circuit(x, y)
          assert res.dtype is np.dtype("complex128")
          probs = jax.numpy.abs(res) ** 2
          return probs[0] + probs[2]
  
      res = cost_fn(x, y)
  
      if diff_method not in {"backprop"}:
          pytest.skip("Test only supports backprop")
  
      res = jax.grad(cost_fn, argnums=[0, 1])(x, y)
      expected = np.array(
          [-np.sin(x) * np.cos(y) / 2, -np.cos(x) * np.sin(y) / 2]
      )
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
imports: import pytest
  import pennylane
  from pennylane import numpy
  from pennylane import qnode
  from pennylane.tape import QuantumScript
label_desc: Use image node_id 6 for calling the TestQubitIntegrationHigherOrder obj's underlying member method code with example usage: obj.test_state(dev_name, diff_method, grad_on_execution, interface, tol) and returns: qml, unknown