class_docstr: Utility class for storing rollouts.
  
  Currently supports two behaviours: the original, which
  simply dumps everything to a pickle file once complete,
  and a mode which stores each rollout as an entry in a Python
  shelf db file. The latter mode is more robust to memory problems
  or crashes part-way through the rollout generation. Each rollout
  is stored with a key based on the episode number (0-indexed),
  and the number of episodes is stored with the key "num_episodes",
  so to load the shelf file, use something like:
  
  with shelve.open('rollouts.pkl') as rollouts:
     for episode_index in range(rollouts["num_episodes"]):
        rollout = rollouts[str(episode_index)]
  
  If outfile is None, this class does nothing.
code: def __enter__(self):
      if self._outfile:
          if self._use_shelve:
              # Open a shelf file to store each rollout as they come in
              self._shelf = shelve.open(self._outfile)
          else:
              # Original behaviour - keep all rollouts in memory and save
              # them all at the end.
              # But check we can actually write to the outfile before going
              # through the effort of generating the rollouts:
              try:
                  with open(self._outfile, "wb") as _:
                      pass
              except IOError as x:
                  print(
                      "Can not open {} for writing - cancelling rollouts.".format(
                          self._outfile
                      )
                  )
                  raise x
          if self._write_update_file:
              # Open a file to track rollout progress:
              self._update_file = (
                  self._get_tmp_progress_filename().open(mode="w")
              )
      return self
  
imports: import collections
  import copy
  import gymnasium
  import json
  import os
  from pathlib import Path
  import shelve
  import typer
  import ray
  import ray.cloudpickle
  from ray.rllib.env import MultiAgentEnv
  from ray.rllib.env.base_env import _DUMMY_AGENT_ID
  from ray.rllib.env.env_context import EnvContext
  from ray.rllib.evaluation.worker_set import WorkerSet
  from ray.rllib.policy.sample_batch import DEFAULT_POLICY_ID
  from ray.rllib.utils.spaces.space_utils import flatten_to_single_ndarray
  from ray.rllib.common import CLIArguments
  from ray.train._checkpoint import Checkpoint
  from ray.train._internal.session import _TrainingResult
  from ray.tune.utils import merge_dicts
  from ray.tune.registry import get_trainable_cls, _global_registry, ENV_CREATOR
label_desc: Use image node_id 4 for calling the RolloutSaver obj's underlying member method code with example usage: obj.__enter__() and returns: self