code: def _sparse_swap_mat(qubit_i, qubit_j, n):
      """Helper function which generates the sparse matrix of SWAP
      for qubits: i <--> j with final shape (2**n, 2**n)."""
  
      def swap_qubits(index, i, j):
          s = list(format(index, f"0{n}b"))  # convert to binary
          si, sj = s[i], s[j]
          if si == sj:
              return index
          s[i], s[j] = sj, si  # swap qubits
          return int(f"0b{''.join(s)}", 2)  # convert to int
  
      data = [1] * (2**n)
      index_i = list(range(2**n))  # bras (we don't change anything)
      index_j = [
          swap_qubits(idx, qubit_i, qubit_j) for idx in index_i
      ]  # kets (we swap qubits i and j): |10> --> |01>
      return csr_matrix((data, (index_i, index_j)))
  
file_path: pennylane/pennylane/math/matrix_manipulation.py
imports: import itertools
  from functools import reduce
  from typing import Generator, Iterable, Tuple
  import numpy
  from scipy.sparse import csr_matrix, eye, kron
  import pennylane
  from pennylane.wires import Wires
label_desc: Use image node_id 4 for calling a global function with example usage: _sparse_swap_mat(qubit_i, qubit_j, n) and returns: csr_matrix, int, index