docstr: Test that the eigenvalues of a sparse Hamiltonian are correctly returned
docstr_tok: ["Test","that","the","eigenvalues","of","a","sparse","Hamiltonian","are","correctly","returned"]
code: def test_sparse_hamiltonian(self, row, col, dat):
      """Test that the eigenvalues of a sparse Hamiltonian are correctly returned"""
      # N x N matrix with N = 16
      h_mat = scipy.sparse.csr_matrix((dat, (row, col)), shape=(16, 16))
      h_sparse = qml.SparseHamiltonian(h_mat, wires=range(4))
  
      dense_mat = h_mat.todense()
      dense_eigvals = np.sort(np.linalg.eigvals(dense_mat))
  
      # k = 1  (< N-1) scipy.sparse.linalg is used:
      val_groundstate = qml.eigvals(h_sparse, k=1)
      assert np.allclose(val_groundstate, dense_eigvals[0])
  
      # k = 14  (< N-1) scipy.sparse.linalg is used:
      val_n_sparse = np.sort(qml.eigvals(h_sparse, k=14))
      assert np.allclose(val_n_sparse, dense_eigvals[0:-2])
  
      # k = 16 (> N-1) qml.math.linalg is used:
      val_all = np.sort(qml.eigvals(h_sparse, k=16))
      assert np.allclose(val_all, dense_eigvals)
  
imports: from functools import reduce
  import pytest
  import scipy
  from gate_data import CNOT, H, I, S, X, Y, Z
  import pennylane
  from pennylane import numpy
  from pennylane.transforms.op_transforms import OperationTransformError
label_desc: Use image node_id 12 for calling the TestSingleOperation obj's underlying member method code with example usage: obj.test_sparse_hamiltonian(row, col, dat) without return types