class_docstr: Test the Hermitian observable
class_docstr_tok: ["Test","the","Hermitian","observable"]
docstr: Tests that the diagonalizing_gates method of the Hermitian class returns the correct results.
docstr_tok: ["Tests","that","the","diagonalizing_gates","method","of","the","Hermitian","class","returns","the","correct","results","."]
code: def test_hermitian_diagonalizing_gates(
      self, observable, eigvals, eigvecs, tol, mocker
  ):
      """Tests that the diagonalizing_gates method of the Hermitian class returns the correct results."""
      # pylint: disable=too-many-arguments
  
      # check calling `diagonalizing_gates` when `observable` is not in `_eigs` adds expected entry to `_eigs`
      spy = mocker.spy(np.linalg, "eigh")
  
      qubit_unitary = qml.Hermitian(
          observable, wires=[0]
      ).diagonalizing_gates()
  
      assert spy.call_count == 1
  
      key = tuple(observable.flatten().tolist())
      assert np.allclose(
          qml.Hermitian._eigs[key]["eigval"], eigvals, atol=tol, rtol=0
      )
      assert np.allclose(
          qml.Hermitian._eigs[key]["eigvec"], eigvecs, atol=tol, rtol=0
      )
  
      assert np.allclose(
          qubit_unitary[0].data, eigvecs.conj().T, atol=tol, rtol=0
      )
      assert len(qml.Hermitian._eigs) == 1
  
      # calling it again doesn't recalculate or add anything to _eigs (uses cached value)
      _ = qml.Hermitian(observable, wires=[0]).diagonalizing_gates()
      assert spy.call_count == 1
      assert len(qml.Hermitian._eigs) == 1
  
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 8 for calling the TestHermitian obj's underlying member method code with example usage: obj.test_hermitian_diagonalizing_gates(observable, eigvals, eigvecs, tol, mocker) without return types