class_docstr: An out-of-graph Replay Buffer for Prioritized Experience Replay.
  See circular_replay_buffer.py for details.
docstr: Returns a batch of valid indices sampled as in Schaul et al. (2015).
  Args:
    batch_size: int, number of indices returned.
  Returns:
    1D tensor of ints, a batch of valid indices sampled uniformly.
  Raises:
    Exception: If the batch was not constructed after maximum number of tries.
code: def sample_index_batch(self, batch_size: int) -> torch.Tensor:
      """Returns a batch of valid indices sampled as in Schaul et al. (2015).
      Args:
        batch_size: int, number of indices returned.
      Returns:
        1D tensor of ints, a batch of valid indices sampled uniformly.
      Raises:
        Exception: If the batch was not constructed after maximum number of tries.
      """
      # TODO: do priority sampling with torch as well.
      # Sample stratified indices. Some of them might be invalid.
      indices = self.sum_tree.stratified_sample(batch_size)
      allowed_attempts = self._max_sample_attempts
      for i in range(len(indices)):
          if not self.is_valid_transition(indices[i]):
              if allowed_attempts == 0:
                  raise RuntimeError(
                      "Max sample attempts: Tried {} times but only sampled {}"
                      " valid indices. Batch size is {}".format(
                          self._max_sample_attempts, i, batch_size
                      )
                  )
              index = indices[i]
              while (
                  not self.is_valid_transition(index)
                  and allowed_attempts > 0
              ):
                  # If index i is not valid keep sampling others. Note that this
                  # is not stratified.
                  index = self.sum_tree.sample()
                  allowed_attempts -= 1
              indices[i] = index
      return torch.tensor(indices, dtype=torch.int64)
  
file_path: ReAgent/reagent/replay_memory/prioritized_replay_buffer.py
imports: import numpy
  import torch
  from reagent.replay_memory import circular_replay_buffer, sum_tree
label_desc: Use image node_id 3 for calling the PrioritizedReplayBuffer obj's underlying member method code with example usage: obj.sample_index_batch(batch_size) and returns: torch