class_docstr: Tests for state vector projector observable.
class_docstr_tok: ["Tests","for","state","vector","projector","observable","."]
docstr: Test that the projector returns valid diagonalizing gates consistent with eigvals.
docstr_tok: ["Test","that","the","projector","returns","valid","diagonalizing","gates","consistent","with","eigvals","."]
code: def test_projector_diagonalization(self, state_vector, tol):
      """Test that the projector returns valid diagonalizing gates consistent with eigvals."""
      num_wires = np.log2(len(state_vector)).astype(int)
      proj = qml.Projector(state_vector, wires=range(num_wires))
      diag_gates = proj.diagonalizing_gates()
      diag_gates_static = (
          StateVectorProjector.compute_diagonalizing_gates(
              state_vector, wires=range(num_wires)
          )
      )
  
      diagonalizing_matrices = [
          diag_gates[0].matrix(),
          diag_gates_static[0].matrix(),
      ]
      for u in diagonalizing_matrices:
          diagonal_matrix = u.conj().T @ proj.matrix() @ u
          assert np.allclose(
              diagonal_matrix - np.diag(np.diagonal(diagonal_matrix)),
              0,
              atol=tol,
              rtol=0,
          )
          assert np.allclose(
              np.diagonal(diagonal_matrix),
              proj.eigvals(),
              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 2 for calling the TestStateVectorProjector obj's underlying member method code with example usage: obj.test_projector_diagonalization(state_vector, tol) without return types