-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(v3.5.5) - Tqdm progress bar and terminal messages improvement (#439)
* Constants: Deleted mock path due to some containers don't have tests/ folder, instead specify direcly in fixtures * Logging: Update and improve some sinergym terminal logging messages. * Simulator: Add episode num in constructor, and update instantiation in environment * Simulator: Improve progres bar with tqdm (parameters set carefully) * TerminalLogger: Updated consoleHandler with a new created TqdmLoggingHandler to syncronize with tqdm bar * Constants: Add callback log level * Requirements: Add tqdm dependency * Updated Sinergym version from 3.5.4 to 3.5.5 * Scripts: Updating script to use Sinergym terminal logger * Tests: Update test about simulator * delete print test_stable_baselines.py * Isort fix project
- Loading branch information
1 parent
594a527
commit b7d9a69
Showing
15 changed files
with
160 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ pytype | |
twine | ||
xlsxwriter | ||
pipdeptree | ||
wandb | ||
wandb | ||
tqdm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,48 @@ | ||
import logging | ||
|
||
import gymnasium as gym | ||
import numpy as np | ||
from gymnasium.wrappers.normalize import NormalizeReward | ||
|
||
import sinergym | ||
from sinergym.utils.logger import TerminalLogger | ||
from sinergym.utils.wrappers import (LoggerWrapper, NormalizeAction, | ||
NormalizeObservation) | ||
|
||
# Optional: Terminal log in the same format as Sinergym. | ||
# Logger info can be replaced by print. | ||
terminal_logger = TerminalLogger() | ||
logger = terminal_logger.getLogger( | ||
name='MAIN', | ||
level=logging.INFO | ||
) | ||
|
||
env = gym.make('Eplus-demo-v1') | ||
env = NormalizeAction(env) | ||
env = NormalizeObservation(env) | ||
env = NormalizeReward(env) | ||
env = LoggerWrapper(env) | ||
|
||
# Execute interactions during 1 episode | ||
for i in range(1): | ||
# Reset the environment to start a new episode | ||
obs, info = env.reset() | ||
rewards = [] | ||
truncated = terminated = False | ||
current_month = 0 | ||
while not (terminated or truncated): | ||
# Random action control | ||
a = env.action_space.sample() | ||
# Read observation and reward | ||
obs, reward, terminated, truncated, info = env.step(a) | ||
rewards.append(reward) | ||
# If this timestep is a new month start | ||
if info['month'] != current_month: # display results every month | ||
current_month = info['month'] | ||
print('Reward: ', sum(rewards), info) | ||
print( | ||
'Episode ', | ||
i, | ||
'Mean reward: ', | ||
np.mean(rewards), | ||
'Cumulative reward: ', | ||
sum(rewards)) | ||
# Print information | ||
logger.info('Reward: {}'.format(sum(rewards))) | ||
logger.info('Info: {}'.format(info)) | ||
# Final episode information print | ||
logger.info('Episode {} - Mean reward: {} - Cumulative Reward: {}'.format(i, | ||
np.mean(rewards), sum(rewards))) | ||
env.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.