class_docstr: Tests for sparse hamiltonian observable
class_docstr_tok: ["Tests","for","sparse","hamiltonian","observable"]
docstr: Test that an error is raised when the observable is SparseHamiltonian and the
  differentiation method is not parameter-shift.
docstr_tok: ["Test","that","an","error","is","raised","when","the","observable","is","SparseHamiltonian","and","the","differentiation","method","is","not","parameter-shift","."]
code: def test_sparse_diffmethod_error(self):
      """Test that an error is raised when the observable is SparseHamiltonian and the
      differentiation method is not parameter-shift."""
      dev = qml.device("default.qubit", wires=2, shots=None)
  
      @qml.qnode(dev, diff_method="backprop")
      def circuit(param):
          qml.RX(param, wires=0)
          return qml.expval(
              qml.SparseHamiltonian(csr_matrix(np.eye(4)), [0, 1])
          )
  
      with pytest.raises(
          qml.QuantumFunctionError,
          match="SparseHamiltonian observable must be"
          " used with the parameter-shift differentiation method",
      ):
          qml.grad(circuit, argnum=0)([0.5])
  
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 6 for calling the TestSparse obj's underlying member method code with example usage: obj.test_sparse_diffmethod_error() and returns: qml