sinergym.utils.logger.CSVLogger

class sinergym.utils.logger.CSVLogger(monitor_header: str, progress_header: str, log_progress_file: str, log_file: str | None = None, flag: bool = True)

CSV Logger for agent interaction with environment.

Parameters:
  • monitor_header – CSV header for sub_run_N/monitor.csv which record interaction step by step.

  • progress_header – CSV header for res_N/progress.csv which record main data episode by episode.

  • log_file – log_file path for monitor.csv, there will be one CSV per episode.

  • log_progress_file – log_file path for progress.csv, there will be only one CSV per whole simulation.

  • flag – This flag is used to activate (True) or deactivate (False) Logger in real time.

  • etc (steps_data, rewards, powers,) – These arrays are used to record steps data to elaborate main data for progress.csv later.

  • total_timesteps – Current episode timesteps executed.

  • total_time_elapsed – Current episode time elapsed (simulation hours).

  • comfort_violation_timesteps – Current episode timesteps whose comfort_penalty!=0.

  • steps_data – It is a array of str’s. Each element belong to a step data.

__init__(monitor_header: str, progress_header: str, log_progress_file: str, log_file: str | None = None, flag: bool = True)

CSVLogger constructor

Parameters:
  • monitor_header (str) – CSV header for sub_run_N/monitor.csv which record interaction step by step.

  • progress_header (str) – CSV header for res_N/progress.csv which record main data episode by episode.

  • log_progress_file (str) – log_file path for progress.csv, there will be only one CSV per whole simulation.

  • log_file (Optional[str], optional) – log_file path for monitor.csv, there will be one CSV per episode. Defaults to None.

  • flag (bool, optional) – Activate (True) or deactivate (False) Logger in real time. Defaults to True.

Methods

__init__(monitor_header, progress_header, ...)

CSVLogger constructor

activate_flag()

Activate Sinergym CSV logger

deactivate_flag()

Deactivate Sinergym CSV logger

log_episode(episode)

Log episode main information using steps_data param.

log_step(obs, action, terminated, truncated, ...)

Log step information and store it in steps_data attribute.

log_step_normalize(obs, action, terminated, ...)

Log step information and store it in steps_data attribute.

set_log_file(new_log_file)

Change log_file path for monitor.csv when an episode ends.

activate_flag() None

Activate Sinergym CSV logger

deactivate_flag() None

Deactivate Sinergym CSV logger

log_episode(episode: int) None

Log episode main information using steps_data param.

Parameters:

episode (int) – Current simulation episode number.

log_step(obs: List[Any], action: int | ndarray | List[Any], terminated: bool, truncated: bool, info: Dict[str, Any]) None

Log step information and store it in steps_data attribute.

Parameters:
  • obs (List[Any]) – Observation from step.

  • action (Union[int, np.ndarray, List[Any]]) – Action done in step.

  • terminated (bool) – terminated flag in step.

  • truncated (bool) – truncated flag in step.

  • info (Dict[str, Any]) – Extra info collected in step.

log_step_normalize(obs: List[Any], action: int | ndarray | List[Any], terminated: bool, truncated: bool, info: Dict[str, Any]) None

Log step information and store it in steps_data attribute.

Parameters:
  • obs (List[Any]) – Observation from step.

  • action (Union[int, np.ndarray, List[Any]]) – Action done in step.

  • reward (Optional[float]) – Reward returned in step.

  • terminated (bool) – terminated flag in step.

  • truncated (bool) – truncated flag in step.

  • info (Optional[Dict[str, Any]]) – Extra info collected in step.

set_log_file(new_log_file: str) None

Change log_file path for monitor.csv when an episode ends.

Parameters:

new_log_file (str) – New log path depending on simulation.