class_docstr: Tests that ensure various qubit circuits integrate correctly
class_docstr_tok: ["Tests","that","ensure","various","qubit","circuits","integrate","correctly"]
docstr: Test that the variance of a projector is correctly returned
docstr_tok: ["Test","that","the","variance","of","a","projector","is","correctly","returned"]
code: def test_projector(
      self,
      state,
      interface,
      dev,
      diff_method,
      grad_on_execution,
      device_vjp,
      tol,
  ):
      """Test that the variance of a projector is correctly returned"""
      if diff_method == "adjoint":
          pytest.skip(
              "adjoint supports either expvals or diagonal measurements."
          )
      kwargs = dict(
          diff_method=diff_method,
          interface=interface,
          grad_on_execution=grad_on_execution,
          device_vjp=device_vjp,
      )
  
      if diff_method == "spsa":
          kwargs["sampler_rng"] = np.random.default_rng(SEED_FOR_SPSA)
          tol = TOL_FOR_SPSA
      elif diff_method == "hadamard":
          pytest.skip("Hadamard gradient does not support variances.")
  
      P = np.array(state, requires_grad=False)
      x, y = np.array([0.765, -0.654], requires_grad=True)
  
      @qnode(dev, **kwargs)
      def circuit(x, y):
          qml.RX(x, wires=0)
          qml.RY(y, wires=1)
          qml.CNOT(wires=[0, 1])
          return qml.var(qml.Projector(P, wires=0) @ qml.PauliX(1))
  
      res = circuit(x, y)
      expected = (
          0.25
          * np.sin(x / 2) ** 2
          * (3 + np.cos(2 * y) + 2 * np.cos(x) * np.sin(y) ** 2)
      )
      # assert isinstance(res, np.ndarray)
      # assert res.shape == ()
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
      jac = qml.jacobian(circuit)(x, y)
      expected = np.array(
          [
              [
                  0.5
                  * np.sin(x)
                  * (
                      np.cos(x / 2) ** 2
                      + np.cos(2 * y) * np.sin(x / 2) ** 2
                  ),
                  -2 * np.cos(y) * np.sin(x / 2) ** 4 * np.sin(y),
              ]
          ]
      )
  
      assert isinstance(jac, tuple)
      assert len(jac) == 2
  
      assert isinstance(jac[0], np.ndarray)
      assert jac[0].shape == ()
  
      assert isinstance(jac[1], np.ndarray)
      assert jac[1].shape == ()
  
      assert np.allclose(jac, expected, 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 15 for calling the TestQubitIntegration obj's underlying member method code with example usage: obj.test_projector(state, interface, dev, diff_method, grad_on_execution, device_vjp, tol) and returns: qml