class_docstr: Tests for simple single-qubit observables
class_docstr_tok: ["Tests","for","simple","single-qubit","observables"]
docstr: Test the method transforms standard observables into the Z-gate.
docstr_tok: ["Test","the","method","transforms","standard","observables","into","the","Z-gate","."]
code: def test_diagonalization(self, obs, _, eigs, tol):
      """Test the method transforms standard observables into the Z-gate."""
      ob = obs(wires=0)
      A = ob.matrix()
  
      diag_gates = ob.diagonalizing_gates()
      U = np.eye(2)
  
      if diag_gates:
          mats = [i.matrix() for i in diag_gates]
          # Need to revert the order in which the matrices are applied such that they adhere to the order
          # of matrix multiplication
          # E.g. for PauliY: [PauliZ(wires=self.wires), S(wires=self.wires), Hadamard(wires=self.wires)]
          # becomes Hadamard @ S @ PauliZ, where @ stands for matrix multiplication
          mats = mats[::-1]
          U = np.linalg.multi_dot([np.eye(2)] + mats)
  
      res = U @ A @ U.conj().T
      expected = np.diag(eigs)
      assert np.allclose(res, expected, 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 TestSimpleObservables obj's underlying member method code with example usage: obj.test_diagonalization(obs, _, eigs, tol) without return types