class_docstr: This buffer adds replayed samples to a stream of new experiences.
  
  - Any newly added batch (`add()`) is immediately returned upon
  the next `replay` call (close to on-policy) as well as being moved
  into the buffer.
  - Additionally, a certain number of old samples is mixed into the
  returned sample according to a given "replay ratio".
  - If >1 calls to `add()` are made without any `replay()` calls
  in between, all newly added batches are returned (plus some older samples
  according to the "replay ratio").
  
  .. testcode::
  
      from ray.rllib.execution.buffers.mixin_replay_buffer import (
          MixInMultiAgentReplayBuffer)
      from ray.rllib.policy.sample_batch import SampleBatch
      # replay ratio 0.66 (2/3 replayed, 1/3 new samples):
      buffer = MixInMultiAgentReplayBuffer(capacity=100,
                                           replay_ratio=0.66)
      A, B, C = (SampleBatch({"obs": [1]}), SampleBatch({"obs": [2]}),
          SampleBatch({"obs": [3]}))
      buffer.add(A)
      buffer.add(B)
      buffer.add(B)
      print(buffer.replay()["obs"])
  
  .. testoutput::
      :hide:
  
      ...
class_docstr_tok: ["This","buffer","adds","replayed","samples","to","a","stream","of","new","experiences",".","-","Any","newly","added","batch","(","`","add","(",")","`",")","is","immediately","returned","upon","the","next","`","replay","`","call","(","close","to","on-policy",")","as","well","as","being","moved","into","the","buffer",".","-","Additionally",",","a","certain","number","of","old","samples","is","mixed","into","the","returned","sample","according","to","a","given","``","replay","ratio","''",".","-","If",">","1","calls","to","`","add","(",")","`","are","made","without","any","`","replay","(",")","`","calls","in","between",",","all","newly","added","batches","are","returned","(","plus","some","older","samples","according","to","the","``","replay","ratio","''",")",".","..","testcode",":",":","from","ray.rllib.execution.buffers.mixin_replay_buffer","import","(","MixInMultiAgentReplayBuffer",")","from","ray.rllib.policy.sample_batch","import","SampleBatch","#","replay","ratio","0.66","(","2\/3","replayed",",","1\/3","new","samples",")",":","buffer","=","MixInMultiAgentReplayBuffer","(","capacity=100",",","replay_ratio=0.66",")","A",",","B",",","C","=","(","SampleBatch","(","{","``","obs","''",":","[","1","]","}",")",",","SampleBatch","(","{","``","obs","''",":","[","2","]","}",")",",","SampleBatch","(","{","``","obs","''",":","[","3","]","}",")",")","buffer.add","(","A",")","buffer.add","(","B",")","buffer.add","(","B",")","print","(","buffer.replay","(",")","[","``","obs","''","]",")","..","testoutput",":",":",":","hide",":","..."]
docstr: Adds a batch to the appropriate policy's replay buffer.
  
  Turns the batch into a MultiAgentBatch of the DEFAULT_POLICY_ID if
  it is not a MultiAgentBatch. Subsequently adds the individual policy
  batches to the storage.
  
  Args:
      batch: The batch to be added.
docstr_tok: ["Adds","a","batch","to","the","appropriate","policy","'s","replay","buffer",".","Turns","the","batch","into","a","MultiAgentBatch","of","the","DEFAULT_POLICY_ID","if","it","is","not","a","MultiAgentBatch",".","Subsequently","adds","the","individual","policy","batches","to","the","storage",".","Args",":","batch",":","The","batch","to","be","added","."]
code: def add(self, batch: SampleBatchType) -> None:
      """Adds a batch to the appropriate policy's replay buffer.
  
      Turns the batch into a MultiAgentBatch of the DEFAULT_POLICY_ID if
      it is not a MultiAgentBatch. Subsequently adds the individual policy
      batches to the storage.
  
      Args:
          batch: The batch to be added.
      """
      # Make a copy so the replay buffer doesn't pin plasma memory.
      batch = batch.copy()
      batch = batch.as_multi_agent()
  
      with self.add_batch_timer:
          if self.replay_mode == ReplayMode.LOCKSTEP:
              # Lockstep mode: Store under _ALL_POLICIES key (we will always
              # only sample from all policies at the same time).
              # This means storing a MultiAgentBatch to the underlying buffer
              self.replay_buffers[_ALL_POLICIES].add_batch(batch)
              self.last_added_batches[_ALL_POLICIES].append(batch)
          else:
              # Store independent SampleBatches
              for (
                  policy_id,
                  sample_batch,
              ) in batch.policy_batches.items():
                  self.replay_buffers[policy_id].add_batch(sample_batch)
                  self.last_added_batches[policy_id].append(
                      sample_batch
                  )
  
      self.num_added += batch.count
  
file_path: ray/rllib/execution/buffers/mixin_replay_buffer.py
imports: import collections
  import platform
  import random
  from typing import Optional
  from ray.util.timer import _Timer
  from ray.rllib.execution.replay_ops import SimpleReplayBuffer
  from ray.rllib.policy.sample_batch import DEFAULT_POLICY_ID, concat_samples
  from ray.rllib.utils.deprecation import Deprecated
  from ray.rllib.utils.replay_buffers.multi_agent_replay_buffer import ReplayMode
  from ray.rllib.utils.replay_buffers.replay_buffer import _ALL_POLICIES
  from ray.rllib.utils.typing import PolicyID, SampleBatchType
label_desc: Use image node_id 2 for calling the MixInMultiAgentReplayBuffer obj's underlying member method code with example usage: obj.add(batch) without return types