class_docstr: Tests for the basis state projector observable.
class_docstr_tok: ["Tests","for","the","basis","state","projector","observable","."]
docstr: Tests that the eigvals property of the Projector class returns the correct results.
docstr_tok: ["Tests","that","the","eigvals","property","of","the","Projector","class","returns","the","correct","results","."]
code: def test_projector_eigvals(self, basis_state, tol):
      """Tests that the eigvals property of the Projector class returns the correct results."""
      num_wires = len(basis_state)
      eigvals = qml.Projector(
          basis_state, wires=range(num_wires)
      ).eigvals()
  
      if basis_state[0] == 0:
          observable = np.array([[1, 0], [0, 0]])
      elif basis_state[0] == 1:
          observable = np.array([[0, 0], [0, 1]])
      for i in basis_state[1:]:
          if i == 0:
              observable = np.kron(
                  observable, np.array([[1, 0], [0, 0]])
              )
          elif i == 1:
              observable = np.kron(
                  observable, np.array([[0, 0], [0, 1]])
              )
      expected_eigvals, expected_eigvecs = np.linalg.eig(observable)
  
      assert np.allclose(
          np.sort(eigvals), np.sort(expected_eigvals), atol=tol, rtol=0
      )
      assert np.allclose(
          eigvals,
          expected_eigvecs[np.where(expected_eigvals == 1)[0][0]],
          atol=tol,
          rtol=0,
      )
  
imports: import functools
  import pickle
  import pytest
  import numpy
  from gate_data import I, X, Y, Z, H
  import pennylane
  from pennylane.ops.qubit.observables import BasisStateProjector, StateVectorProjector
label_desc: Use image node_id 1 for calling the TestBasisStateProjector obj's underlying member method code with example usage: obj.test_projector_eigvals(basis_state, tol) without return types