code: def _run_rollout_loop(
      env: Union[BaseEnv, gym.Env],
      n_steps_per_episode: int,
      n_episodes: int,
      writer: LogEventsWriter,
  ):
      LogEventsWriterRegistry.writers = (
          []
      )  # Ensure there is no other writer
      LogEventsWriterRegistry.register_writer(writer)
  
      env = LogStatsWrapper.wrap(env)
      for _ in range(n_episodes):
          env.reset()
          for i in range(n_steps_per_episode):
              env.step(env.action_space.sample())
              if i == n_steps_per_episode - 1:
                  env.render_stats()
      env.close()
      env.write_epoch_stats()
  
imports: import random
  from abc import ABC
  from typing import Tuple, Optional
  from typing import Union, List, Type, Dict
  import gym
  import numpy
  from maze.core.env.base_env import BaseEnv
  from maze.core.env.base_env_events import BaseEnvEvents
  from maze.core.env.maze_state import MazeStateType
  from maze.core.env.time_env_mixin import TimeEnvMixin
  from maze.core.events.pubsub import Pubsub
  from maze.core.log_events.episode_event_log import EpisodeEventLog
  from maze.core.log_events.kpi_calculator import KpiCalculator
  from maze.core.log_events.log_events_writer import LogEventsWriter
  from maze.core.log_events.log_events_writer_registry import LogEventsWriterRegistry
  from maze.core.log_stats.event_decorators import define_episode_stats, define_step_stats, define_epoch_stats
  from maze.core.wrappers.log_stats_wrapper import LogStatsWrapper
  from maze.core.wrappers.maze_gym_env_wrapper import GymMazeEnv
  from maze.test.shared_test_utils.dummy_env.dummy_core_env import DummyCoreEnvironment
  from maze.test.shared_test_utils.dummy_env.dummy_maze_env import DummyEnvironment
  from maze.test.shared_test_utils.dummy_env.dummy_struct_env import DummyStructuredEnvironment
  from maze.test.shared_test_utils.dummy_env.reward.base import RewardAggregator
  from maze.test.shared_test_utils.dummy_env.space_interfaces.action_conversion.dict import DictActionConversion
  from maze.test.shared_test_utils.dummy_env.space_interfaces.action_conversion.dict import DictActionConversion
  from maze.test.shared_test_utils.dummy_env.space_interfaces.observation_conversion.dict import ObservationConversion
  from maze.test.shared_test_utils.dummy_env.space_interfaces.observation_conversion.dict import ObservationConversion
label_desc: Use image node_id 1 for calling a global function with example usage: _run_rollout_loop(env, n_steps_per_episode, n_episodes, writer) without return types