code: def _batched_partial_trace(density_matrix, indices):
      """Compute the reduced density matrix by tracing out the provided indices.
  
      Args:
          density_matrix (tensor_like): 3D density matrix tensor. This tensor should be of size
              ``(batch_dim, 2**N, 2**N)``, for some integer number of wires``N``.
          indices (list(int)): List of indices to be traced.
  
      Returns:
          tensor_like: (reduced) Density matrix of size ``(batch_dim, 2**len(wires), 2**len(wires))``
  
      **Example**
  
      >>> x = np.array([[[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
      ...               [[0, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]])
      >>> _batched_partial_trace(x, indices=[0])
      array([[[1, 0],
              [0, 0]],
  
             [[0, 0],
              [0, 1]]])
  
      >>> x = tf.Variable([[[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
      ...                  [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 0]]], dtype=tf.complex128)
      >>> _batched_partial_trace(x, indices=[1])
      <tf.Tensor: shape=(2, 2, 2), dtype=complex128, numpy=
      array([[[1.+0.j, 0.+0.j],
              [0.+0.j, 0.+0.j]],
  
             [[1.+0.j, 0.+0.j],
              [0.+0.j, 0.+0.j]]])>
      """
      # Autograd does not support same indices sum in backprop, and tensorflow
      # has a limit of 8 dimensions if same indices are used
      if get_interface(density_matrix) in ["autograd", "tensorflow"]:
          return _batched_partial_trace_nonrep_indices(
              density_matrix, indices
          )
  
      # Dimension and reshape
      batch_dim, dim = density_matrix.shape[:2]
      num_indices = int(np.log2(dim))
      rho_dim = 2 * num_indices
  
      density_matrix = np.reshape(
          density_matrix, [batch_dim] + [2] * 2 * num_indices
      )
      indices = np.sort(indices)
  
      # For loop over wires
      for i, target_index in enumerate(indices):
          target_index = target_index - i
          state_indices = ABC[1 : rho_dim - 2 * i + 1]
          state_indices = list(state_indices)
  
          target_letter = state_indices[target_index]
          state_indices[target_index + num_indices - i] = target_letter
          state_indices = "".join(state_indices)
  
          einsum_indices = f"a{state_indices}"
          density_matrix = einsum(einsum_indices, density_matrix)
  
      number_wires_sub = num_indices - len(indices)
      reduced_density_matrix = np.reshape(
          density_matrix,
          (batch_dim, 2**number_wires_sub, 2**number_wires_sub),
      )
      return reduced_density_matrix
  
imports: import itertools
  import functools
  from string import ascii_letters
  from autoray import numpy
  from numpy import float64
  import pennylane
  from .None import single_dispatch
  from .multi_dispatch import diag, dot, scatter_element_add, einsum, get_interface
  from .utils import is_abstract, allclose, cast, convert_like, cast_like
  from .matrix_manipulation import _permute_dense_matrix
label_desc: Use image node_id 4 for calling a global function with example usage: _batched_partial_trace(density_matrix, indices) and returns: reduced_density_matrix, _batched_partial_trace_nonrep_indices