class_docstr: Test expectation values
class_docstr_tok: ["Test","expectation","values"]
docstr: Test that arbitrary Projector expectation values are correct
code: def test_projector_expectation(self, device, tol):
      """Test that arbitrary Projector expectation values are correct"""
      n_wires = 2
      dev = device(n_wires)
  
      if "Projector" not in dev.observables:
          pytest.skip(
              "Skipped because device does not support the Projector observable."
          )
  
      theta = 0.732
      phi = 0.523
  
      @qml.qnode(dev)
      def circuit(state):
          qml.RY(theta, wires=[0])
          qml.RY(phi, wires=[1])
          qml.CNOT(wires=[0, 1])
          return qml.expval(qml.Projector(state, wires=[0, 1]))
  
      basis_state, state_vector = [0, 0], [1, 0, 0, 0]
      expected = (np.cos(phi / 2) * np.cos(theta / 2)) ** 2
      assert np.allclose(
          circuit(basis_state), expected, atol=tol(dev.shots)
      )
      assert np.allclose(
          circuit(state_vector), expected, atol=tol(dev.shots)
      )
  
      basis_state, state_vector = [0, 1], [0, 1, 0, 0]
      expected = (np.sin(phi / 2) * np.cos(theta / 2)) ** 2
      assert np.allclose(
          circuit(basis_state), expected, atol=tol(dev.shots)
      )
      assert np.allclose(
          circuit(state_vector), expected, atol=tol(dev.shots)
      )
  
      basis_state, state_vector = [1, 0], [0, 0, 1, 0]
      expected = (np.sin(phi / 2) * np.sin(theta / 2)) ** 2
      assert np.allclose(
          circuit(basis_state), expected, atol=tol(dev.shots)
      )
      assert np.allclose(
          circuit(state_vector), expected, atol=tol(dev.shots)
      )
  
      basis_state, state_vector = [1, 1], [0, 0, 0, 1]
      expected = (np.cos(phi / 2) * np.sin(theta / 2)) ** 2
      assert np.allclose(
          circuit(basis_state), expected, atol=tol(dev.shots)
      )
      assert np.allclose(
          circuit(state_vector), expected, atol=tol(dev.shots)
      )
  
imports: import pytest
  from flaky import flaky
  from scipy.sparse import csr_matrix
  import pennylane
  from pennylane import numpy
  from pennylane.measurements import ClassicalShadowMP, MeasurementTransform, SampleMeasurement, SampleMP, StateMeasurement, StateMP
label_desc: Use image node_id 7 for calling the TestExpval obj's underlying member method code with example usage: obj.test_projector_expectation(device, tol) and returns: qml