class_docstr: Tests for sparse hamiltonian observable
class_docstr_tok: ["Tests","for","sparse","hamiltonian","observable"]
docstr: Tests if the __mul__ method of SparseHamiltonian gives the correct result.
docstr_tok: ["Tests","if","the","__mul__","method","of","SparseHamiltonian","gives","the","correct","result","."]
code: def test_scalar_multipication(self, sparse_hamiltonian):
      """Tests if the __mul__ method of SparseHamiltonian gives the correct result."""
  
      value = 0.1234
      num_wires = int(np.log2(len(sparse_hamiltonian)))
      H = csr_matrix(SPARSEHAMILTONIAN_TEST_MATRIX)
      H_multiplied = csr_matrix(SPARSEHAMILTONIAN_TEST_MATRIX * value)
  
      H_sparse_mul_method = (
          qml.SparseHamiltonian(H, wires=range(num_wires)) * value
      )
      H_sparse_mul_method = H_sparse_mul_method.sparse_matrix()
      H_sparse_multiplied_before = qml.SparseHamiltonian(
          H_multiplied, wires=range(num_wires)
      ).sparse_matrix()
  
      assert np.allclose(
          H_sparse_mul_method.toarray(),
          H_sparse_multiplied_before.toarray(),
      )
  
file_path: pennylane/tests/ops/qubit/test_sparse.py
imports: import pytest
  import numpy
  from scipy.sparse import coo_matrix, csr_matrix
  import pennylane
label_desc: Use image node_id 11 for calling the TestSparse obj's underlying member method code with example usage: obj.test_scalar_multipication(sparse_hamiltonian) without return types