class_docstr: A replay buffer shard for multiagent setups.
  
  This buffer is meant to be run in parallel to distribute experiences
  across `num_shards` shards. Unlike simpler buffers, it holds a set of
  buffers - one for each policy ID.
docstr: Samples a MultiAgentBatch of `num_items` per one policy's buffer.
  
  If less than `num_items` records are in the policy's buffer,
  some samples in the results may be repeated to fulfil the batch size
  `num_items` request. Returns an empty batch if there are no items in
  the buffer.
  
  Args:
      num_items: Number of items to sample from a policy's buffer.
      policy_id: ID of the policy that created the experiences we sample. If
      none is given, sample from all policies.
  
  Returns:
      Concatenated MultiAgentBatch of items.
      ``**kwargs``: Forward compatibility kwargs.
docstr_tok: ["Samples","a","MultiAgentBatch","of","`","num_items","`","per","one","policy","'s","buffer",".","If","less","than","`","num_items","`","records","are","in","the","policy","'s","buffer",",","some","samples","in","the","results","may","be","repeated","to","fulfil","the","batch","size","`","num_items","`","request",".","Returns","an","empty","batch","if","there","are","no","items","in","the","buffer",".","Args",":","num_items",":","Number","of","items","to","sample","from","a","policy","'s","buffer",".","policy_id",":","ID","of","the","policy","that","created","the","experiences","we","sample",".","If","none","is","given",",","sample","from","all","policies",".","Returns",":","Concatenated","MultiAgentBatch","of","items",".","``","*","*","kwargs","``",":","Forward","compatibility","kwargs","."]
code: def sample(
      self,
      num_items: int,
      policy_id: Optional[PolicyID] = None,
      **kwargs,
  ) -> Optional[SampleBatchType]:
      """Samples a MultiAgentBatch of `num_items` per one policy's buffer.
  
      If less than `num_items` records are in the policy's buffer,
      some samples in the results may be repeated to fulfil the batch size
      `num_items` request. Returns an empty batch if there are no items in
      the buffer.
  
      Args:
          num_items: Number of items to sample from a policy's buffer.
          policy_id: ID of the policy that created the experiences we sample. If
          none is given, sample from all policies.
  
      Returns:
          Concatenated MultiAgentBatch of items.
          ``**kwargs``: Forward compatibility kwargs.
      """
      # Merge kwargs, overwriting standard call arguments
      kwargs = merge_dicts_with_warning(
          self.underlying_buffer_call_args, kwargs
      )
  
      with self.replay_timer:
          # Lockstep mode: Sample from all policies at the same time an
          # equal amount of steps.
          if self.replay_mode == ReplayMode.LOCKSTEP:
              assert (
                  policy_id is None
              ), "`policy_id` specifier not allowed in `lockstep` mode!"
              # In lockstep mode we sample MultiAgentBatches
              return self.replay_buffers[_ALL_POLICIES].sample(
                  num_items, **kwargs
              )
          elif policy_id is not None:
              sample = self.replay_buffers[policy_id].sample(
                  num_items, **kwargs
              )
              return MultiAgentBatch({policy_id: sample}, sample.count)
          else:
              samples = {}
              for (
                  policy_id,
                  replay_buffer,
              ) in self.replay_buffers.items():
                  samples[policy_id] = replay_buffer.sample(
                      num_items, **kwargs
                  )
              return MultiAgentBatch(
                  samples, sum(s.count for s in samples.values())
              )
  
imports: import collections
  import logging
  from enum import Enum
  from typing import Any, Dict, Optional
  from ray.util.timer import _Timer
  from ray.rllib.policy.rnn_sequencing import timeslice_along_seq_lens_with_overlap
  from ray.rllib.policy.sample_batch import MultiAgentBatch, SampleBatch
  from ray.rllib.utils.annotations import override
  from ray.rllib.utils.deprecation import Deprecated
  from ray.rllib.utils.from_config import from_config
  from ray.rllib.utils.replay_buffers.replay_buffer import _ALL_POLICIES, ReplayBuffer, StorageUnit
  from ray.rllib.utils.typing import PolicyID, SampleBatchType
  from ray.util.annotations import DeveloperAPI
  from ray.util.debug import log_once
label_desc: Use image node_id 6 for calling the MultiAgentReplayBuffer obj's underlying member method code with example usage: obj.sample(num_items, policy_id) and returns: self, MultiAgentBatch, MultiAgentBatch