class_docstr: This buffer implements Prioritized Experience Replay.
  
  The algorithm has been described by Tom Schaul et. al. in "Prioritized
  Experience Replay". See https://arxiv.org/pdf/1511.05952.pdf for
  the full paper.
docstr: Sample `num_items` items from this buffer, including prio. weights.
  
  Samples in the results may be repeated.
  
  Examples for storage of SamplesBatches:
  - If storage unit `timesteps` has been chosen and batches of
  size 5 have been added, sample(5) will yield a concatenated batch of
  15 timesteps.
  - If storage unit 'sequences' has been chosen and sequences of
  different lengths have been added, sample(5) will yield a concatenated
  batch with a number of timesteps equal to the sum of timesteps in
  the 5 sampled sequences.
  - If storage unit 'episodes' has been chosen and episodes of
  different lengths have been added, sample(5) will yield a concatenated
  batch with a number of timesteps equal to the sum of timesteps in
  the 5 sampled episodes.
  
  Args:
      num_items: Number of items to sample from this buffer.
      beta: To what degree to use importance weights (0 - no corrections,
      1 - full correction).
      ``**kwargs``: Forward compatibility kwargs.
  
  Returns:
      Concatenated SampleBatch of items including "weights" and
      "batch_indexes" fields denoting IS of each sampled
      transition and original idxes in buffer of sampled experiences.
docstr_tok: ["Sample","`","num_items","`","items","from","this","buffer",",","including","prio",".","weights",".","Samples","in","the","results","may","be","repeated",".","Examples","for","storage","of","SamplesBatches",":","-","If","storage","unit","`","timesteps","`","has","been","chosen","and","batches","of","size","5","have","been","added",",","sample","(","5",")","will","yield","a","concatenated","batch","of","15","timesteps",".","-","If","storage","unit","'sequences","'","has","been","chosen","and","sequences","of","different","lengths","have","been","added",",","sample","(","5",")","will","yield","a","concatenated","batch","with","a","number","of","timesteps","equal","to","the","sum","of","timesteps","in","the","5","sampled","sequences",".","-","If","storage","unit","'episodes","'","has","been","chosen","and","episodes","of","different","lengths","have","been","added",",","sample","(","5",")","will","yield","a","concatenated","batch","with","a","number","of","timesteps","equal","to","the","sum","of","timesteps","in","the","5","sampled","episodes",".","Args",":","num_items",":","Number","of","items","to","sample","from","this","buffer",".","beta",":","To","what","degree","to","use","importance","weights","(","0","-","no","corrections",",","1","-","full","correction",")",".","``","*","*","kwargs","``",":","Forward","compatibility","kwargs",".","Returns",":","Concatenated","SampleBatch","of","items","including","``","weights","''","and","``","batch_indexes","''","fields","denoting","IS","of","each","sampled","transition","and","original","idxes","in","buffer","of","sampled","experiences","."]
code: def sample(
      self, num_items: int, beta: float, **kwargs
  ) -> Optional[SampleBatchType]:
      """Sample `num_items` items from this buffer, including prio. weights.
  
      Samples in the results may be repeated.
  
      Examples for storage of SamplesBatches:
      - If storage unit `timesteps` has been chosen and batches of
      size 5 have been added, sample(5) will yield a concatenated batch of
      15 timesteps.
      - If storage unit 'sequences' has been chosen and sequences of
      different lengths have been added, sample(5) will yield a concatenated
      batch with a number of timesteps equal to the sum of timesteps in
      the 5 sampled sequences.
      - If storage unit 'episodes' has been chosen and episodes of
      different lengths have been added, sample(5) will yield a concatenated
      batch with a number of timesteps equal to the sum of timesteps in
      the 5 sampled episodes.
  
      Args:
          num_items: Number of items to sample from this buffer.
          beta: To what degree to use importance weights (0 - no corrections,
          1 - full correction).
          ``**kwargs``: Forward compatibility kwargs.
  
      Returns:
          Concatenated SampleBatch of items including "weights" and
          "batch_indexes" fields denoting IS of each sampled
          transition and original idxes in buffer of sampled experiences.
      """
      assert beta >= 0.0
  
      if len(self) == 0:
          raise ValueError("Trying to sample from an empty buffer.")
  
      idxes = self._sample_proportional(num_items)
  
      weights = []
      batch_indexes = []
      p_min = self._it_min.min() / self._it_sum.sum()
      max_weight = (p_min * len(self)) ** (-beta)
  
      for idx in idxes:
          p_sample = self._it_sum[idx] / self._it_sum.sum()
          weight = (p_sample * len(self)) ** (-beta)
          count = self._storage[idx].count
          # If zero-padded, count will not be the actual batch size of the
          # data.
          if (
              isinstance(self._storage[idx], SampleBatch)
              and self._storage[idx].zero_padded
          ):
              actual_size = self._storage[idx].max_seq_len
          else:
              actual_size = count
          weights.extend([weight / max_weight] * actual_size)
          batch_indexes.extend([idx] * actual_size)
          self._num_timesteps_sampled += count
      batch = self._encode_sample(idxes)
  
      # Note: prioritization is not supported in multi agent lockstep
      if isinstance(batch, SampleBatch):
          batch["weights"] = np.array(weights)
          batch["batch_indexes"] = np.array(batch_indexes)
  
      return batch
  
imports: import random
  from typing import Any, Dict, List, Optional
  import numpy
  import ray
  import psutil
  from ray.rllib.execution.segment_tree import SumSegmentTree, MinSegmentTree
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.annotations import override
  from ray.rllib.utils.metrics.window_stat import WindowStat
  from ray.rllib.utils.replay_buffers.replay_buffer import ReplayBuffer
  from ray.rllib.utils.typing import SampleBatchType
  from ray.util.annotations import DeveloperAPI
label_desc: Use image node_id 4 for calling the PrioritizedReplayBuffer obj's underlying member method code with example usage: obj.sample(num_items, beta) and returns: batch