From 47b429603c9dfb418203ac54354f076ee8df4917 Mon Sep 17 00:00:00 2001 From: AlejandroCN7 Date: Thu, 27 Jun 2024 09:04:26 +0000 Subject: [PATCH 1/5] Fix evalLoggerCallback for deactivate normalization update and update mean and var calibration from training env automatically (when NormalizeObservation was activated) --- scripts/train/train_agent.py | 3 ++- sinergym/utils/callbacks.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/train/train_agent.py b/scripts/train/train_agent.py index 610a53d31..c53fefa67 100644 --- a/scripts/train/train_agent.py +++ b/scripts/train/train_agent.py @@ -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') + diff --git a/sinergym/utils/callbacks.py b/sinergym/utils/callbacks.py index 6107edf2a..b13dda4de 100644 --- a/sinergym/utils/callbacks.py +++ b/sinergym/utils/callbacks.py @@ -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, @@ -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: @@ -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 = [] @@ -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')) From a38bbdcb2f1870ba2c55fb420046ae65154e8bfe Mon Sep 17 00:00:00 2001 From: AlejandroCN7 Date: Thu, 27 Jun 2024 09:04:57 +0000 Subject: [PATCH 2/5] Update Sinergym version from 3.3.5 to 3.3.6 --- sinergym/version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sinergym/version.txt b/sinergym/version.txt index 0163af7e8..eedb52bac 100644 --- a/sinergym/version.txt +++ b/sinergym/version.txt @@ -1 +1 @@ -3.3.5 \ No newline at end of file +3.3.6 \ No newline at end of file From 637b09ff8c0c636610d0b588bbb012f783b9e326 Mon Sep 17 00:00:00 2001 From: AlejandroCN7 Date: Thu, 27 Jun 2024 10:02:34 +0000 Subject: [PATCH 3/5] Fix opyplus update inconsistency --- sinergym/utils/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sinergym/utils/common.py b/sinergym/utils/common.py index 99a574b61..3222b50a8 100644 --- a/sinergym/utils/common.py +++ b/sinergym/utils/common.py @@ -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 From b4c14152a840a98e0b2caf107682ed029d88f3dd Mon Sep 17 00:00:00 2001 From: AlejandroCN7 Date: Thu, 27 Jun 2024 10:49:51 +0000 Subject: [PATCH 4/5] Dockerfile: Updated Ubuntu and Python version (24.04 and 3.12.3) --- .devcontainer/Dockerfile | 5 +++-- Dockerfile | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 0e8336fe7..3105822f6 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -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) @@ -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 diff --git a/Dockerfile b/Dockerfile index 0e8336fe7..3105822f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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) @@ -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 From 0b6ea6c6ab3b760efa57553ac4ec3bb4ca38e46c Mon Sep 17 00:00:00 2001 From: AlejandroCN7 Date: Thu, 27 Jun 2024 10:52:34 +0000 Subject: [PATCH 5/5] Added version documentation --- INSTALL.md | 1 + docs/source/pages/installation.rst | 2 ++ 2 files changed, 3 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index c3988a8d6..a39c57b6d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -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, diff --git a/docs/source/pages/installation.rst b/docs/source/pages/installation.rst index 17f2533fb..2f17f00f4 100644 --- a/docs/source/pages/installation.rst +++ b/docs/source/pages/installation.rst @@ -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,