class_docstr: The base class for all distributed workers with buffer.
  
  Distributed workers run rollouts independently. Rollouts are collected by calling the collect_rollouts method and
  are then added to the buffer.
  
  :param env_factory: Factory function for envs to run rollouts on
  :param worker_policy: Structured policy to sample actions from
  :param n_rollout_steps: Number of rollouts steps to record in one rollout
  :param n_workers: Number of distributed workers to run simultaneously
  :param batch_size: Size of the batch the rollouts are collected in
  :param rollouts_per_iteration: The number of rollouts to collect each time the collect_rollouts method is called.
  :param split_rollouts_into_transitions: Specify whether all computed rollouts should be split into
                                          transitions before processing them
  :param env_instance_seeds: A list of seeds for each workers envs.
  :param replay_buffer: The replay buffer to use.
class_docstr_tok: ["The","base","class","for","all","distributed","workers","with","buffer",".","Distributed","workers","run","rollouts","independently",".","Rollouts","are","collected","by","calling","the","collect_rollouts","method","and","are","then","added","to","the","buffer",".",":","param","env_factory",":","Factory","function","for","envs","to","run","rollouts","on",":","param","worker_policy",":","Structured","policy","to","sample","actions","from",":","param","n_rollout_steps",":","Number","of","rollouts","steps","to","record","in","one","rollout",":","param","n_workers",":","Number","of","distributed","workers","to","run","simultaneously",":","param","batch_size",":","Size","of","the","batch","the","rollouts","are","collected","in",":","param","rollouts_per_iteration",":","The","number","of","rollouts","to","collect","each","time","the","collect_rollouts","method","is","called",".",":","param","split_rollouts_into_transitions",":","Specify","whether","all","computed","rollouts","should","be","split","into","transitions","before","processing","them",":","param","env_instance_seeds",":","A","list","of","seeds","for","each","workers","envs",".",":","param","replay_buffer",":","The","replay","buffer","to","use","."]
docstr: Sample a batch from the buffer and return it as a batched structured spaces record.
  
  :param learner_device: The device of the learner (cpu or cuda).
  :return: An batched structured spaces record object holding the batched rollouts.
docstr_tok: ["Sample","a","batch","from","the","buffer","and","return","it","as","a","batched","structured","spaces","record",".",":","param","learner_device",":","The","device","of","the","learner","(","cpu","or","cuda",")",".",":","return",":","An","batched","structured","spaces","record","object","holding","the","batched","rollouts","."]
code: def sample_batch(self, learner_device: str) -> StructuredSpacesRecord:
      """Sample a batch from the buffer and return it as a batched structured spaces record.
  
      :param learner_device: The device of the learner (cpu or cuda).
      :return: An batched structured spaces record object holding the batched rollouts.
      """
      batch = self.replay_buffer.sample_batch(
          n_samples=self.batch_size, learner_device=learner_device
      )
      if self.split_rollouts_into_transitions:
          # Stack records into one, then add an additional dimension
          stacked_records = StructuredSpacesRecord.stack_records(batch)
          return StructuredSpacesRecord.stack_records(
              [stacked_records]
          ).to_torch(learner_device)
      else:
          # Stack trajectories in time major, then stack into a single spaces record
          return (
              SpacesTrajectoryRecord.stack_trajectories(batch)
              .stack()
              .to_torch(learner_device)
          )
  
imports: from abc import abstractmethod
  from typing import Callable, Optional, Union, Dict, Tuple, List
  from omegaconf import DictConfig
  from maze.core.agent.policy import Policy
  from maze.core.agent.torch_policy import TorchPolicy
  from maze.core.env.structured_env import StructuredEnv
  from maze.core.env.structured_env_spaces_mixin import StructuredEnvSpacesMixin
  from maze.core.log_stats.log_stats import LogStatsAggregator, LogStatsLevel, LogStatsValue, get_stats_logger
  from maze.core.log_stats.log_stats_env import LogStatsEnv
  from maze.core.rollout.rollout_generator import RolloutGenerator
  from maze.core.trajectory_recording.records.structured_spaces_record import StructuredSpacesRecord
  from maze.core.trajectory_recording.records.trajectory_record import SpacesTrajectoryRecord
  from maze.core.utils.factory import Factory
  from maze.train.trainers.common.replay_buffer.replay_buffer import BaseReplayBuffer
  from maze.train.trainers.common.replay_buffer.uniform_replay_buffer import UniformReplayBuffer
label_desc: Use image node_id 7 for calling the BaseDistributedWorkersWithBuffer obj's underlying member method code with example usage: obj.sample_batch(learner_device) and returns: StructuredSpacesRecord, SpacesTrajectoryRecord