class_docstr: Dictionary representing a linear combination of Pauli words, with the keys
  as :class:`~pennylane.pauli.PauliWord` instances and the values correspond to coefficients.
  
  .. note::
  
      An empty :class:`~.PauliSentence` will be treated as the additive
      identity (i.e 0 * Identity on all wires).
  
  **Examples**
  
  >>> ps = PauliSentence({
          PauliWord({0:'X', 1:'Y'}): 1.23,
          PauliWord({2:'Z', 0:'Y'}): -0.45j
      })
  >>> ps
  1.23 * X(0) @ Y(1)
  + (-0-0.45j) * Z(2) @ Y(0)
  
  Combining Pauli words automatically results in Pauli sentences that can be used to construct more complicated operators.
  
  >>> w1 = PauliWord({0:"X", 1:"Y"})
  >>> w2 = PauliWord({1:"X", 2:"Z"})
  >>> ps = 0.5 * w1 - 1.5 * w2 + 2
  >>> ps + PauliWord({3:"Z"}) - 1
  0.5 * X(0) @ Y(1)
  + -1.5 * X(1) @ Z(2)
  + 1 * I
  + 1.0 * Z(3)
class_docstr_tok: ["Dictionary","representing","a","linear","combination","of","Pauli","words",",","with","the","keys","as",":","class",":","`","~pennylane.pauli.PauliWord","`","instances","and","the","values","correspond","to","coefficients",".","..","note",":",":","An","empty",":","class",":","`","~.PauliSentence","`","will","be","treated","as","the","additive","identity","(","i.e","0","*","Identity","on","all","wires",")",".","*","*","Examples","*","*",">",">",">","ps","=","PauliSentence","(","{","PauliWord","(","{","0",":","'","X","'",",","1",":","'","Y","'","}",")",":","1.23",",","PauliWord","(","{","2",":","'","Z","'",",","0",":","'","Y","'","}",")",":","-0.45j","}",")",">",">",">","ps","1.23","*","X","(","0",")","@","Y","(","1",")","+","(","-0-0.45j",")","*","Z","(","2",")","@","Y","(","0",")","Combining","Pauli","words","automatically","results","in","Pauli","sentences","that","can","be","used","to","construct","more","complicated","operators",".",">",">",">","w1","=","PauliWord","(","{","0",":","''","X","''",",","1",":","''","Y","''","}",")",">",">",">","w2","=","PauliWord","(","{","1",":","''","X","''",",","2",":","''","Z","''","}",")",">",">",">","ps","=","0.5","*","w1","-","1.5","*","w2","+","2",">",">",">","ps","+","PauliWord","(","{","3",":","''","Z","''","}",")","-","1","0.5","*","X","(","0",")","@","Y","(","1",")","+","-1.5","*","X","(","1",")","@","Z","(","2",")","+","1","*","I","+","1.0","*","Z","(","3",")"]
docstr: Compute the sparse matrix of the Pauli sentence by efficiently adding the Pauli words
  that it is composed of. See pauli_sparse_matrices.md for the technical details.
docstr_tok: ["Compute","the","sparse","matrix","of","the","Pauli","sentence","by","efficiently","adding","the","Pauli","words","that","it","is","composed","of",".","See","pauli_sparse_matrices.md","for","the","technical","details","."]
code: def _to_sparse_mat(self, wire_order, buffer_size=None):
      """Compute the sparse matrix of the Pauli sentence by efficiently adding the Pauli words
      that it is composed of. See pauli_sparse_matrices.md for the technical details.
      """
      pauli_words = list(self)  # Ensure consistent ordering
      n_wires = len(wire_order)
      matrix_size = 2**n_wires
      matrix = sparse.csr_matrix(
          (matrix_size, matrix_size), dtype="complex128"
      )
      op_sparse_idx = _ps_to_sparse_index(pauli_words, wire_order)
      _, unique_sparse_structures, unique_invs = np.unique(
          op_sparse_idx, axis=0, return_index=True, return_inverse=True
      )
      pw_sparse_structures = unique_sparse_structures[unique_invs]
  
      buffer_size = buffer_size or 2**30  # Default to 1GB of memory
      # Convert bytes to number of matrices:
      # complex128 (16) for each data entry and int64 (8) for each indices entry
      buffer_size = max(1, buffer_size // ((16 + 8) * matrix_size))
      mat_data = np.empty(
          (matrix_size, buffer_size), dtype=np.complex128
      )
      mat_indices = np.empty((matrix_size, buffer_size), dtype=np.int64)
      n_matrices_in_buffer = 0
      for sparse_structure in unique_sparse_structures:
          indices, *_ = np.nonzero(
              pw_sparse_structures == sparse_structure
          )
          mat = self._sum_same_structure_pws(
              [pauli_words[i] for i in indices], wire_order
          )
          mat_data[:, n_matrices_in_buffer] = mat.data
          mat_indices[:, n_matrices_in_buffer] = mat.indices
  
          n_matrices_in_buffer += 1
          if n_matrices_in_buffer == buffer_size:
              # Add partial results in batches to control the memory usage
              matrix += self._sum_different_structure_pws(
                  mat_indices, mat_data
              )
              n_matrices_in_buffer = 0
  
      matrix += self._sum_different_structure_pws(
          mat_indices[:, :n_matrices_in_buffer],
          mat_data[:, :n_matrices_in_buffer],
      )
      matrix.eliminate_zeros()
      return matrix
  
imports: import warnings
  from copy import copy
  from functools import reduce, lru_cache
  from typing import Iterable
  import numpy
  from scipy import sparse
  import pennylane
  from pennylane import math
  from pennylane.typing import TensorLike
  from pennylane.wires import Wires
  from pennylane.operation import Tensor
  from pennylane.ops import Hamiltonian, Identity, PauliX, PauliY, PauliZ, prod, s_prod
label_desc: Use image node_id 15 for calling the PauliSentence obj's underlying member method code with example usage: obj._to_sparse_mat(wire_order, buffer_size) and returns: matrix