class_docstr: A Hamiltonian represented directly as a sparse matrix in Compressed Sparse Row (CSR) format.
  
  .. warning::
  
      ``SparseHamiltonian`` observables can only be used to return expectation values.
      Variances and samples are not supported.
  
  **Details:**
  
  * Number of wires: Any
  * Number of parameters: 1
  * Gradient recipe: None
  
  Args:
      H (csr_matrix): a sparse matrix in SciPy Compressed Sparse Row (CSR) format with
          dimension :math:`(2^n, 2^n)`, where :math:`n` is the number of wires.
      wires (Sequence[int]): the wire(s) the operation acts on
      id (str or None): String representing the operation (optional)
  
  **Example**
  
  Sparse Hamiltonians can be constructed directly with a SciPy-compatible sparse matrix.
  
  Alternatively, you can construct your Hamiltonian as usual using :class:`~.Hamiltonian`, and then use
  :meth:`~.Hamiltonian.sparse_matrix` to construct the sparse matrix that serves as the input
  to ``SparseHamiltonian``:
  
  >>> wires = range(20)
  >>> coeffs = [1 for _ in wires]
  >>> observables = [qml.PauliZ(i) for i in wires]
  >>> H = qml.Hamiltonian(coeffs, observables)
  >>> Hmat = H.sparse_matrix()
  >>> H_sparse = qml.SparseHamiltonian(Hmat, wires)
class_docstr_tok: ["A","Hamiltonian","represented","directly","as","a","sparse","matrix","in","Compressed","Sparse","Row","(","CSR",")","format",".","..","warning",":",":","``","SparseHamiltonian","``","observables","can","only","be","used","to","return","expectation","values",".","Variances","and","samples","are","not","supported",".","*","*","Details",":","*","*","*","Number","of","wires",":","Any","*","Number","of","parameters",":","1","*","Gradient","recipe",":","None","Args",":","H","(","csr_matrix",")",":","a","sparse","matrix","in","SciPy","Compressed","Sparse","Row","(","CSR",")","format","with","dimension",":","math",":","`","(","2^n",",","2^n",")","`",",","where",":","math",":","`","n","`","is","the","number","of","wires",".","wires","(","Sequence","[","int","]",")",":","the","wire","(","s",")","the","operation","acts","on","id","(","str","or","None",")",":","String","representing","the","operation","(","optional",")","*","*","Example","*","*","Sparse","Hamiltonians","can","be","constructed","directly","with","a","SciPy-compatible","sparse","matrix",".","Alternatively",",","you","can","construct","your","Hamiltonian","as","usual","using",":","class",":","`","~.Hamiltonian","`",",","and","then","use",":","meth",":","`","~.Hamiltonian.sparse_matrix","`","to","construct","the","sparse","matrix","that","serves","as","the","input","to","``","SparseHamiltonian","``",":",">",">",">","wires","=","range","(","20",")",">",">",">","coeffs","=","[","1","for","_","in","wires","]",">",">",">","observables","=","[","qml.PauliZ","(","i",")","for","i","in","wires","]",">",">",">","H","=","qml.Hamiltonian","(","coeffs",",","observables",")",">",">",">","Hmat","=","H.sparse_matrix","(",")",">",">",">","H_sparse","=","qml.SparseHamiltonian","(","Hmat",",","wires",")"]
docstr: Representation of the operator as a canonical matrix in the computational basis (static method).
  
  The canonical matrix is the textbook matrix representation that does not consider wires.
  Implicitly, this assumes that the wires of the operator correspond to the global wire order.
  
  .. seealso:: :meth:`~.SparseHamiltonian.matrix`
  
  
  This method returns a dense matrix. For a sparse matrix representation, see
  :meth:`~.SparseHamiltonian.compute_sparse_matrix`.
  
  Args:
      H (scipy.sparse.csr_matrix): sparse matrix used to create the operator
  
  Returns:
      array: dense matrix
  
  **Example**
  
  >>> from scipy.sparse import csr_matrix
  >>> H = np.array([[6+0j, 1-2j],[1+2j, -1]])
  >>> H = csr_matrix(H)
  >>> res = qml.SparseHamiltonian.compute_matrix(H)
  >>> res
  [[ 6.+0.j  1.-2.j]
   [ 1.+2.j -1.+0.j]]
  >>> type(res)
  <class 'numpy.ndarray'>
docstr_tok: ["Representation","of","the","operator","as","a","canonical","matrix","in","the","computational","basis","(","static","method",")",".","The","canonical","matrix","is","the","textbook","matrix","representation","that","does","not","consider","wires",".","Implicitly",",","this","assumes","that","the","wires","of","the","operator","correspond","to","the","global","wire","order",".","..","seealso",":",":",":","meth",":","`","~.SparseHamiltonian.matrix","`","This","method","returns","a","dense","matrix",".","For","a","sparse","matrix","representation",",","see",":","meth",":","`","~.SparseHamiltonian.compute_sparse_matrix","`",".","Args",":","H","(","scipy.sparse.csr_matrix",")",":","sparse","matrix","used","to","create","the","operator","Returns",":","array",":","dense","matrix","*","*","Example","*","*",">",">",">","from","scipy.sparse","import","csr_matrix",">",">",">","H","=","np.array","(","[","[","6+0j",",","1-2j","]",",","[","1+2j",",","-1","]","]",")",">",">",">","H","=","csr_matrix","(","H",")",">",">",">","res","=","qml.SparseHamiltonian.compute_matrix","(","H",")",">",">",">","res","[","[","6.+0.j","1.-2.j","]","[","1.+2.j","-1.+0.j","]","]",">",">",">","type","(","res",")","<","class","'numpy.ndarray","'",">"]
code: def compute_matrix(H):  # pylint: disable=arguments-differ
      r"""Representation of the operator as a canonical matrix in the computational basis (static method).
  
      The canonical matrix is the textbook matrix representation that does not consider wires.
      Implicitly, this assumes that the wires of the operator correspond to the global wire order.
  
      .. seealso:: :meth:`~.SparseHamiltonian.matrix`
  
  
      This method returns a dense matrix. For a sparse matrix representation, see
      :meth:`~.SparseHamiltonian.compute_sparse_matrix`.
  
      Args:
          H (scipy.sparse.csr_matrix): sparse matrix used to create the operator
  
      Returns:
          array: dense matrix
  
      **Example**
  
      >>> from scipy.sparse import csr_matrix
      >>> H = np.array([[6+0j, 1-2j],[1+2j, -1]])
      >>> H = csr_matrix(H)
      >>> res = qml.SparseHamiltonian.compute_matrix(H)
      >>> res
      [[ 6.+0.j  1.-2.j]
       [ 1.+2.j -1.+0.j]]
      >>> type(res)
      <class 'numpy.ndarray'>
      """
      return H.toarray()
  
imports: from copy import copy
  from collections.abc import Sequence
  import numpy
  from scipy.sparse import csr_matrix
  import pennylane
  from pennylane.operation import AnyWires, Observable, Operation
  from pennylane.wires import Wires
  from .matrix_ops import QubitUnitary
label_desc: Use image node_id 4 for calling the SparseHamiltonian obj's underlying member method code with example usage: obj.compute_matrix(H) and returns: H