Warning

This package is in maintenance mode, please use Stable-Baselines3 (SB3) for an up-to-date version. You can find a migration guide in SB3 documentation.

Monitor Wrapper

class stable_baselines.bench.monitor.Monitor(env: gym.core.Env, filename: Optional[str], allow_early_resets: bool = True, reset_keywords=(), info_keywords=())[source]

A monitor wrapper for Gym environments, it is used to know the episode reward, length, time and other data.

Parameters:
  • env – (gym.Env) The environment
  • filename – (Optional[str]) the location to save a log file, can be None for no log
  • allow_early_resets – (bool) allows the reset of the environment before it is done
  • reset_keywords – (tuple) extra keywords for the reset call, if extra parameters are needed at reset
  • info_keywords – (tuple) extra information to log, from the information return of environment.step
close()[source]

Closes the environment

get_episode_lengths() → List[int][source]

Returns the number of timesteps of all the episodes

Returns:([int])
get_episode_rewards() → List[float][source]

Returns the rewards of all the episodes

Returns:([float])
get_episode_times() → List[float][source]

Returns the runtime in seconds of all the episodes

Returns:([float])
get_total_steps() → int[source]

Returns the total number of timesteps

Returns:(int)
reset(**kwargs) → numpy.ndarray[source]

Calls the Gym environment reset. Can only be called if the environment is over, or if allow_early_resets is True

Parameters:kwargs – Extra keywords saved for the next episode. only if defined by reset_keywords
Returns:(np.ndarray) the first observation of the environment
step(action: numpy.ndarray) → Tuple[numpy.ndarray, float, bool, Dict[Any, Any]][source]

Step the environment with the given action

Parameters:action – (np.ndarray) the action
Returns:(Tuple[np.ndarray, float, bool, Dict[Any, Any]]) observation, reward, done, information
stable_baselines.bench.monitor.get_monitor_files(path: str) → List[str][source]

get all the monitor files in the given path

Parameters:path – (str) the logging folder
Returns:([str]) the log files
stable_baselines.bench.monitor.load_results(path: str) → pandas.core.frame.DataFrame[source]

Load all Monitor logs from a given directory path matching *monitor.csv and *monitor.json

Parameters:path – (str) the directory path containing the log file(s)
Returns:(pandas.DataFrame) the logged data