Monitor Wrapper

class stable_baselines3.common.monitor.Monitor(env, filename=None, allow_early_resets=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 (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[str, …]) – extra keywords for the reset call, if extra parameters are needed at reset

  • info_keywords (Tuple[str, …]) – extra information to log, from the information return of env.step()

close()[source]

Closes the environment

Return type

None

get_episode_lengths()[source]

Returns the number of timesteps of all the episodes

Return type

List[int]

Returns

get_episode_rewards()[source]

Returns the rewards of all the episodes

Return type

List[float]

Returns

get_episode_times()[source]

Returns the runtime in seconds of all the episodes

Return type

List[float]

Returns

get_total_steps()[source]

Returns the total number of timesteps

Return type

int

Returns

reset(**kwargs)[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

Return type

Union[Tuple, Dict[str, Any], ndarray, int]

Returns

the first observation of the environment

step(action)[source]

Step the environment with the given action

Parameters

action (Union[ndarray, int]) – the action

Return type

Tuple[Union[Tuple, Dict[str, Any], ndarray, int], float, bool, Dict]

Returns

observation, reward, done, information

stable_baselines3.common.monitor.get_monitor_files(path)[source]

get all the monitor files in the given path

Parameters

path (str) – the logging folder

Return type

List[str]

Returns

the log files

stable_baselines3.common.monitor.load_results(path)[source]

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

Parameters

path (str) – the directory path containing the log file(s)

Return type

DataFrame

Returns

the logged data