code: def __iter__(self):
      mdp_id = 0
      global_num_steps = 0
      rewards = []
  
      # TODO: We probably should put member vars into local vars to
      # reduce indirection, improving perf
  
      while self._num_episodes is None or mdp_id < self._num_episodes:
          obs = self._env.reset()
          possible_actions_mask = self._env.possible_actions_mask
          terminal = False
          num_steps = 0
          episode_reward_sum = 0
          trajectory = Trajectory()
          while not terminal:
              action, log_prob = self._agent.act(
                  obs, possible_actions_mask
              )
              next_obs, reward, terminal, info = self._env.step(action)
              next_possible_actions_mask = (
                  self._env.possible_actions_mask
              )
              if (
                  self._max_steps is not None
                  and num_steps >= self._max_steps
              ):
                  terminal = True
  
              # Only partially filled. Agent can fill in more fields.
              transition = Transition(
                  mdp_id=mdp_id,
                  sequence_number=num_steps,
                  observation=obs,
                  action=action,
                  reward=float(reward),
                  terminal=bool(terminal),
                  log_prob=log_prob,
                  possible_actions_mask=possible_actions_mask,
              )
              trajectory.add_transition(transition)
              self._replay_buffer_inserter(
                  self._replay_buffer, transition
              )
              episode_reward_sum += reward
              if (
                  global_num_steps % self._training_frequency == 0
                  and self._replay_buffer.size >= self._batch_size
              ):
                  train_batch = (
                      self._replay_buffer.sample_transition_batch(
                          batch_size=self._batch_size
                      )
                  )
                  if self._trainer_preprocessor:
                      train_batch = self._trainer_preprocessor(
                          train_batch
                      )
                  yield train_batch
  
              obs = next_obs
              possible_actions_mask = next_possible_actions_mask
              num_steps += 1
              global_num_steps += 1
              if self._agent.post_step:
                  self._agent.post_step(transition)
          if self._post_episode_callback:
              self._post_episode_callback(trajectory, info)
  
          rewards.append(episode_reward_sum)
          mdp_id += 1
          logger.info(
              f"Training episode: {mdp_id}, total episode reward = {episode_reward_sum}"
          )
  
      logger.info(f"Episode rewards during training: {rewards}")
  
file_path: ReAgent/reagent/gym/datasets/replay_buffer_dataset.py
imports: import logging
  from typing import Callable, Optional
  import torch
  from reagent.gym.agents.agent import Agent
  from reagent.gym.envs import EnvWrapper
  from reagent.gym.preprocessors import make_replay_buffer_inserter, make_replay_buffer_trainer_preprocessor
  from reagent.gym.types import Trajectory, Transition
  from reagent.replay_memory.circular_replay_buffer import ReplayBuffer
label_desc: Use image node_id 3 for calling the ReplayBufferDataset obj's underlying member method code with example usage: obj.__iter__() without return types