Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(v3.3.6) - Sinergym normalization fix for DRL evaluations and new Ubuntu and Python version #419

Merged
merged 5 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Base on nrel/energyplus from Nicholas Long but using
# Ubuntu, Python 3.10 and BCVTB
ARG UBUNTU_VERSION=22.04
ARG UBUNTU_VERSION=24.04
FROM ubuntu:${UBUNTU_VERSION}

# Arguments for EnergyPlus version (default values of version 8.6.0 if is not specified)
Expand All @@ -12,7 +12,8 @@ ARG ENERGYPLUS_SHA=87ed9199d4
ARG SINERGYM_EXTRAS=[extras]

# Argument for choosing Python version
ARG PYTHON_VERSION=3.10
ARG PYTHON_VERSION=3.12
ENV PIP_BREAK_SYSTEM_PACKAGES=1

# WANDB_API_KEY
ARG WANDB_API_KEY
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Base on nrel/energyplus from Nicholas Long but using
# Ubuntu, Python 3.10 and BCVTB
ARG UBUNTU_VERSION=22.04
ARG UBUNTU_VERSION=24.04
FROM ubuntu:${UBUNTU_VERSION}

# Arguments for EnergyPlus version (default values of version 8.6.0 if is not specified)
Expand All @@ -12,7 +12,8 @@ ARG ENERGYPLUS_SHA=87ed9199d4
ARG SINERGYM_EXTRAS=[extras]

# Argument for choosing Python version
ARG PYTHON_VERSION=3.10
ARG PYTHON_VERSION=3.12
ENV PIP_BREAK_SYSTEM_PACKAGES=1

# WANDB_API_KEY
ARG WANDB_API_KEY
Expand Down
1 change: 1 addition & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The table below provides a summary of the versions supported by *Sinergym* acros
| **1.9.5** | **22.04 LTS** | **3.10.6** | 9.5.0 | IDF |
| **2.4.0** | 22.04 LTS | 3.10.6 | 9.5.0 | **epJSON** |
| **2.5.0** | 22.04 LTS | 3.10.6 | **23.1.0** | epJSON |
| **3.3.6** | **24.04 LTS** | **3.12.3** | 23.1.0 | epJSON |

We recommend always using the latest version of *Sinergym* that is supported by the container.
This approach helps you avoid the complexities of the installation process. However,
Expand Down
2 changes: 2 additions & 0 deletions docs/source/pages/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The table below provides a summary of the versions supported by *Sinergym* acros
+----------------------+--------------------+--------------------+------------------------+---------------------------+
| **2.5.0** | 22.04 LTS | 3.10.6 | **23.1.0** | epJSON |
+----------------------+--------------------+--------------------+------------------------+---------------------------+
| **3.3.6** | **24.04 LTS** | **3.12.3** | 23.1.0 | epJSON |
+----------------------+--------------------+--------------------+------------------------+---------------------------+

We recommend always using the latest version of *Sinergym* that is supported by the container.
This approach helps you avoid the complexities of the installation process. However,
Expand Down
3 changes: 2 additions & 1 deletion scripts/train/train_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ def process_algorithm_parameters(alg_params: dict):
# Set up Evaluation and saving best model
if conf.get('evaluation'):
eval_callback = LoggerEvalCallback(
eval_env,
eval_env=eval_env,
train_env=env,
best_model_save_path=eval_env.get_wrapper_attr('workspace_path') +
'/best_model/',
log_path=eval_env.get_wrapper_attr('workspace_path') +
Expand Down
16 changes: 16 additions & 0 deletions sinergym/utils/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ class LoggerEvalCallback(EventCallback):
def __init__(
self,
eval_env: Union[gym.Env, VecEnv],
train_env: Union[gym.Env, VecEnv],
callback_on_new_best: Optional[BaseCallback] = None,
callback_after_eval: Optional[BaseCallback] = None,
n_eval_episodes: int = 5,
Expand Down Expand Up @@ -273,6 +274,7 @@ def __init__(
# eval_env = DummyVecEnv([lambda: eval_env])

self.eval_env = eval_env
self.train_env = train_env
self.best_model_save_path = best_model_save_path
# Logs will be written in ``evaluations.npz``
if log_path is not None:
Expand Down Expand Up @@ -351,6 +353,7 @@ def _on_step(self) -> bool:
"Training and eval env are not wrapped the same way, "
"see https://stable-baselines3.readthedocs.io/en/master/guide/callbacks.html#evalcallback "
"and warning above.") from e
self._sync_envs()

# Reset success rate buffer
self._is_success_buffer = []
Expand Down Expand Up @@ -489,3 +492,16 @@ def update_child_locals(self, locals_: Dict[str, Any]) -> None:
"""
if self.callback:
self.callback.update_locals(locals_)

def _sync_envs(self):
# normalization
if is_wrapped(
self.train_env,
NormalizeObservation) and is_wrapped(
self.eval_env,
NormalizeObservation):
self.eval_env.get_wrapper_attr('deactivate_update')()
self.eval_env.get_wrapper_attr('set_mean')(
self.train_env.get_wrapper_attr('mean'))
self.eval_env.get_wrapper_attr('set_var')(
self.train_env.get_wrapper_attr('var'))
2 changes: 1 addition & 1 deletion sinergym/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pandas as pd
import xlsxwriter
from eppy.modeleditor import IDF
from opyplus.epm.record import Record
from opyplus.epgm.record import Record

import sinergym
from sinergym.utils.constants import YEAR
Expand Down
2 changes: 1 addition & 1 deletion sinergym/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.5
3.3.6
Loading