class_docstr: A TFUniformReplayBuffer with batched adds and uniform sampling.
class_docstr_tok: ["A","TFUniformReplayBuffer","with","batched","adds","and","uniform","sampling","."]
docstr: Creates a TFUniformReplayBuffer.
  
  The TFUniformReplayBuffer stores episodes in `B == batch_size` blocks of
  size `L == max_length`, with total frame capacity
  `C == L * B`.  Storage looks like:
  
  ```
  block1 ep1 frame1
             frame2
         ...
         ep2 frame1
             frame2
         ...
         <L frames total>
  block2 ep1 frame1
             frame2
         ...
         ep2 frame1
             frame2
         ...
         <L frames total>
  ...
  blockB ep1 frame1
             frame2
         ...
         ep2 frame1
             frame2
         ...
         <L frames total>
  ```
  Multiple episodes may be stored within a given block, up to `max_length`
  frames total.  In practice, new episodes will overwrite old ones as the
  block rolls over its `max_length`.
  
  Args:
    data_spec: A TensorSpec or a list/tuple/nest of TensorSpecs describing a
      single item that can be stored in this buffer.
    batch_size: Batch dimension of tensors when adding to buffer.
    max_length: The maximum number of items that can be stored in a single
      batch segment of the buffer.
    scope: Scope prefix for variables and ops created by this class.
    device: A TensorFlow device to place the Variables and ops.
    table_fn: Function to create tables `table_fn(data_spec, capacity)` that
      can read/write nested tensors.
    dataset_drop_remainder: If `True`, then when calling `as_dataset` with
      arguments `single_deterministic_pass=True` and `sample_batch_size is not
      None`, the final batch will be dropped if it does not contain exactly
      `sample_batch_size` items.  This is helpful for static shape inference
      as the resulting tensors will always have leading dimension
      `sample_batch_size` instead of `None`.
    dataset_window_shift: Window shift used when calling `as_dataset` with
      arguments `single_deterministic_pass=True` and `num_steps is not None`.
      This determines how the resulting frames are windowed.  If `None`, then
      there is no overlap created between frames and each frame is seen
      exactly once.  For example, if `max_length=5`, `num_steps=2`,
      `sample_batch_size=None`, and `dataset_window_shift=None`, then the
      datasets returned will have frames `{[0, 1], [2, 3], [4]}`.  If
      `dataset_window_shift is not None`, then windows are created with a
      window overlap of `dataset_window_shift` and you will see each frame up
      to `num_steps` times.  For example, if `max_length=5`, `num_steps=2`,
      `sample_batch_size=None`, and `dataset_window_shift=1`, then the
      datasets returned will have windows of shifted repeated frames: `{[0,
      1], [1, 2], [2, 3], [3, 4], [4, 5]}`.  For more details, see the
      documentation of `tf.data.Dataset.window`, specifically for the `shift`
      argument.  The default behavior is to not overlap frames
      (`dataset_window_shift=None`) but users often want to see all
      combinations of frame sequences, in which case `dataset_window_shift=1`
      is the appropriate value.
    stateful_dataset: whether the dataset contains stateful ops or not.
docstr_tok: ["Creates","a","TFUniformReplayBuffer",".","The","TFUniformReplayBuffer","stores","episodes","in","`","B","==","batch_size","`","blocks","of","size","`","L","==","max_length","`",",","with","total","frame","capacity","`","C","==","L","*","B","`",".","Storage","looks","like",":","``","`","block1","ep1","frame1","frame2","...","ep2","frame1","frame2","...","<","L","frames","total",">","block2","ep1","frame1","frame2","...","ep2","frame1","frame2","...","<","L","frames","total",">","...","blockB","ep1","frame1","frame2","...","ep2","frame1","frame2","...","<","L","frames","total",">","``","`","Multiple","episodes","may","be","stored","within","a","given","block",",","up","to","`","max_length","`","frames","total",".","In","practice",",","new","episodes","will","overwrite","old","ones","as","the","block","rolls","over","its","`","max_length","`",".","Args",":","data_spec",":","A","TensorSpec","or","a","list\/tuple\/nest","of","TensorSpecs","describing","a","single","item","that","can","be","stored","in","this","buffer",".","batch_size",":","Batch","dimension","of","tensors","when","adding","to","buffer",".","max_length",":","The","maximum","number","of","items","that","can","be","stored","in","a","single","batch","segment","of","the","buffer",".","scope",":","Scope","prefix","for","variables","and","ops","created","by","this","class",".","device",":","A","TensorFlow","device","to","place","the","Variables","and","ops",".","table_fn",":","Function","to","create","tables","`","table_fn","(","data_spec",",","capacity",")","`","that","can","read\/write","nested","tensors",".","dataset_drop_remainder",":","If","`","True","`",",","then","when","calling","`","as_dataset","`","with","arguments","`","single_deterministic_pass=True","`","and","`","sample_batch_size","is","not","None","`",",","the","final","batch","will","be","dropped","if","it","does","not","contain","exactly","`","sample_batch_size","`","items",".","This","is","helpful","for","static","shape","inference","as","the","resulting","tensors","will","always","have","leading","dimension","`","sample_batch_size","`","instead","of","`","None","`",".","dataset_window_shift",":","Window","shift","used","when","calling","`","as_dataset","`","with","arguments","`","single_deterministic_pass=True","`","and","`","num_steps","is","not","None","`",".","This","determines","how","the","resulting","frames","are","windowed",".","If","`","None","`",",","then","there","is","no","overlap","created","between","frames","and","each","frame","is","seen","exactly","once",".","For","example",",","if","`","max_length=5","`",",","`","num_steps=2","`",",","`","sample_batch_size=None","`",",","and","`","dataset_window_shift=None","`",",","then","the","datasets","returned","will","have","frames","`","{","[","0",",","1","]",",","[","2",",","3","]",",","[","4","]","}","`",".","If","`","dataset_window_shift","is","not","None","`",",","then","windows","are","created","with","a","window","overlap","of","`","dataset_window_shift","`","and","you","will","see","each","frame","up","to","`","num_steps","`","times",".","For","example",",","if","`","max_length=5","`",",","`","num_steps=2","`",",","`","sample_batch_size=None","`",",","and","`","dataset_window_shift=1","`",",","then","the","datasets","returned","will","have","windows","of","shifted","repeated","frames",":","`","{","[","0",",","1","]",",","[","1",",","2","]",",","[","2",",","3","]",",","[","3",",","4","]",",","[","4",",","5","]","}","`",".","For","more","details",",","see","the","documentation","of","`","tf.data.Dataset.window","`",",","specifically","for","the","`","shift","`","argument",".","The","default","behavior","is","to","not","overlap","frames","(","`","dataset_window_shift=None","`",")","but","users","often","want","to","see","all","combinations","of","frame","sequences",",","in","which","case","`","dataset_window_shift=1","`","is","the","appropriate","value",".","stateful_dataset",":","whether","the","dataset","contains","stateful","ops","or","not","."]
code: def __init__(
      self,
      data_spec,
      batch_size,
      max_length=1000,
      scope="TFUniformReplayBuffer",
      device="cpu:*",
      table_fn=table.Table,
      dataset_drop_remainder=False,
      dataset_window_shift=None,
      stateful_dataset=False,
  ):
      """Creates a TFUniformReplayBuffer.
  
      The TFUniformReplayBuffer stores episodes in `B == batch_size` blocks of
      size `L == max_length`, with total frame capacity
      `C == L * B`.  Storage looks like:
  
      ```
      block1 ep1 frame1
                 frame2
             ...
             ep2 frame1
                 frame2
             ...
             <L frames total>
      block2 ep1 frame1
                 frame2
             ...
             ep2 frame1
                 frame2
             ...
             <L frames total>
      ...
      blockB ep1 frame1
                 frame2
             ...
             ep2 frame1
                 frame2
             ...
             <L frames total>
      ```
      Multiple episodes may be stored within a given block, up to `max_length`
      frames total.  In practice, new episodes will overwrite old ones as the
      block rolls over its `max_length`.
  
      Args:
        data_spec: A TensorSpec or a list/tuple/nest of TensorSpecs describing a
          single item that can be stored in this buffer.
        batch_size: Batch dimension of tensors when adding to buffer.
        max_length: The maximum number of items that can be stored in a single
          batch segment of the buffer.
        scope: Scope prefix for variables and ops created by this class.
        device: A TensorFlow device to place the Variables and ops.
        table_fn: Function to create tables `table_fn(data_spec, capacity)` that
          can read/write nested tensors.
        dataset_drop_remainder: If `True`, then when calling `as_dataset` with
          arguments `single_deterministic_pass=True` and `sample_batch_size is not
          None`, the final batch will be dropped if it does not contain exactly
          `sample_batch_size` items.  This is helpful for static shape inference
          as the resulting tensors will always have leading dimension
          `sample_batch_size` instead of `None`.
        dataset_window_shift: Window shift used when calling `as_dataset` with
          arguments `single_deterministic_pass=True` and `num_steps is not None`.
          This determines how the resulting frames are windowed.  If `None`, then
          there is no overlap created between frames and each frame is seen
          exactly once.  For example, if `max_length=5`, `num_steps=2`,
          `sample_batch_size=None`, and `dataset_window_shift=None`, then the
          datasets returned will have frames `{[0, 1], [2, 3], [4]}`.  If
          `dataset_window_shift is not None`, then windows are created with a
          window overlap of `dataset_window_shift` and you will see each frame up
          to `num_steps` times.  For example, if `max_length=5`, `num_steps=2`,
          `sample_batch_size=None`, and `dataset_window_shift=1`, then the
          datasets returned will have windows of shifted repeated frames: `{[0,
          1], [1, 2], [2, 3], [3, 4], [4, 5]}`.  For more details, see the
          documentation of `tf.data.Dataset.window`, specifically for the `shift`
          argument.  The default behavior is to not overlap frames
          (`dataset_window_shift=None`) but users often want to see all
          combinations of frame sequences, in which case `dataset_window_shift=1`
          is the appropriate value.
        stateful_dataset: whether the dataset contains stateful ops or not.
      """
      self._batch_size = batch_size
      self._max_length = max_length
      capacity = self._batch_size * self._max_length
      super(TFUniformReplayBuffer, self).__init__(
          data_spec, capacity, stateful_dataset
      )
  
      self._id_spec = tensor_spec.TensorSpec(
          [], dtype=tf.int64, name="id"
      )
      self._capacity_value = np.int64(self._capacity)
      self._batch_offsets = (
          tf.range(self._batch_size, dtype=tf.int64) * self._max_length
      )
      self._scope = scope
      self._device = device
      self._table_fn = table_fn
      self._dataset_drop_remainder = dataset_drop_remainder
      self._dataset_window_shift = dataset_window_shift
      with tf.device(self._device), tf.compat.v1.variable_scope(
          self._scope
      ):
          self._capacity = tf.constant(capacity, dtype=tf.int64)
          self._data_table = table_fn(
              self._data_spec, self._capacity_value
          )
          self._id_table = table_fn(self._id_spec, self._capacity_value)
          self._last_id = common.create_variable("last_id", -1)
          self._last_id_cs = tf.CriticalSection(name="last_id")
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import gin
  import numpy
  import tensorflow
  from tf_agents.replay_buffers import replay_buffer
  from tf_agents.replay_buffers import table
  from tf_agents.specs import tensor_spec
  from tf_agents.utils import common
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 1 to create a new TFUniformReplayBuffer object from inherited base classes: replay_buffer with example: obj = TFUniformReplayBuffer(data_spec, batch_size, max_length, scope, device, table_fn, dataset_drop_remainder, dataset_window_shift, stateful_dataset)