Skip to content

Commit

Permalink
(v3.2.0) - Sinergym episode metric in WandB (#387)
Browse files Browse the repository at this point in the history
* Added repobeats in README.md

* Added episode/episode_num metric in WandB Callback for SB3 algorithms

* Sinergym updated from version 3.1.8 to 3.2.0
  • Loading branch information
AlejandroCN7 authored Feb 7, 2024
1 parent 6f66a1e commit 89f824a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ The following are some of the projects benefiting from the advantages of Sinergy
</a>
</p>

## Repo Activity

![Alt](https://repobeats.axiom.co/api/embed/d8dc96d423d6996351e728a2412dba2551f99cca.svg "Repobeats analytics image")

## Citing Sinergym

If you use *Sinergym* in your work, please cite our [paper](https://dl.acm.org/doi/abs/10.1145/3486611.3488729):
Expand Down
7 changes: 6 additions & 1 deletion sinergym/utils/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def _on_training_start(self):
self.training_env.env_method('activate_logger')
else:
self.training_env.env_method('deactivate_logger')
# Global training step count
# Global training step and episode count
self.timestep = 1
self.episode_num = 1

def _on_step(self) -> bool:

Expand Down Expand Up @@ -142,6 +143,7 @@ def _on_step(self) -> bool:
if done:
# store last episode metrics
self.episode_metrics = {}
self.episode_metrics['episode_num'] = self.episode_num
self.episode_metrics['episode_length'] = self.episode_logs['timesteps']
self.episode_metrics['cumulative_reward'] = np.sum(
self.episode_logs['rewards'])
Expand Down Expand Up @@ -186,6 +188,9 @@ def _on_step(self) -> bool:
'episode/' + key, metric)
self.logger.dump(step=self.timestep)

# Count next episode
self.episode_num += 1

# DUMP with the frequency specified
if self.timestep % self.dump_frequency == 0:
self.logger.dump(step=self.timestep)
Expand Down
2 changes: 1 addition & 1 deletion sinergym/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.8
3.2.0

0 comments on commit 89f824a

Please sign in to comment.