BOPTEST-Gym
The OpenAI-Gym interface of the BOPTEST framework facilitates the assessment and benchmarking of RL algorithms for building energy management.
https://github.com/ibpsa/project1-boptest-gym
Category: Consumption
Sub Category: Buildings and Heating
Last synced: about 9 hours ago
JSON representation
Repository metadata
- Host: GitHub
- URL: https://github.com/ibpsa/project1-boptest-gym
- Owner: ibpsa
- License: other
- Created: 2020-11-05T16:15:12.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-02-20T17:43:23.000Z (2 months ago)
- Last Synced: 2025-04-17T22:59:20.596Z (10 days ago)
- Language: Python
- Size: 48.7 MB
- Stars: 48
- Watchers: 3
- Forks: 20
- Open Issues: 16
- Releases: 4
-
Metadata Files:
- Readme: README.md
- License: license.md
README.md
BOPTEST-Gym
BOPTESTS-Gym is the Gymnasium environment of the BOPTEST framework. This repository accommodates the BOPTEST API to the Gymnasium standard in order to facilitate the implementation, assessment and benchmarking of reinforcement learning (RL) algorithms for their application in building energy management. RL algorithms from the Stable-Baselines 3 repository are used to exemplify and test this framework.
The environment is described in this paper.
Structure
boptestGymEnv.py
contains the core functionality of this Gymnasium environment.environment.yml
contains the dependencies required to run this software./examples
contains prototype code for the interaction of RL algorithms with an emulator building model from BOPTEST./testing
contains code for testing this software.
Quick-Start
- Create an environment from the
environment.yml
file provided (instructions here). You can also see our Dockerfile in testing/Dockerfile that we use to define our testing environment. - Run the example below that uses the Bestest hydronic case with a heat-pump and the DQN algorithm from Stable-Baselines:
from boptestGymEnv import BoptestGymEnv, NormalizedObservationWrapper, DiscretizedActionWrapper
from stable_baselines3 import DQN
# url for the BOPTEST service.
url = 'https://api.boptest.net'
# Decide the state-action space of your test case
env = BoptestGymEnv(
url = url,
testcase = 'bestest_hydronic_heat_pump',
actions = ['oveHeaPumY_u'],
observations = {'time':(0,604800),
'reaTZon_y':(280.,310.),
'TDryBul':(265,303),
'HDirNor':(0,862),
'InternalGainsRad[1]':(0,219),
'PriceElectricPowerHighlyDynamic':(-0.4,0.4),
'LowerSetp[1]':(280.,310.),
'UpperSetp[1]':(280.,310.)},
predictive_period = 24*3600,
regressive_period = 6*3600,
random_start_time = True,
max_episode_length = 24*3600,
warmup_period = 24*3600,
step_period = 3600)
# Normalize observations and discretize action space
env = NormalizedObservationWrapper(env)
env = DiscretizedActionWrapper(env,n_bins_act=10)
# Instantiate an RL agent
model = DQN('MlpPolicy', env, verbose=1, gamma=0.99,
learning_rate=5e-4, batch_size=24,
buffer_size=365*24, learning_starts=24, train_freq=1)
# Main training loop
model.learn(total_timesteps=10)
# Loop for one episode of experience (one day)
done = False
obs, _ = env.reset()
while not done:
action, _ = model.predict(obs, deterministic=True)
obs,reward,terminated,truncated,info = env.step(action)
done = (terminated or truncated)
# Obtain KPIs for evaluation
env.get_kpis()
In this tutorial you can find more details on how to use BOPTEST-Gym and on RL applied to buildings in general.
Note 1: on running BOPTEST in the server vs. locally
The previous example interacts with BOPTEST in a server at https://api.boptest.net
which is readily available anytime. Interacting with BOPTEST from this server requires less configuration effort but is slower because of the communication overhead between the agent and the test case running in the cloud. Use this approach when you want to quickly check out the functionality of this repository.
If you prioritize speed (which is usually the case when training RL agents), running BOPTEST locally is substantially faster.
You can do so by downloading the BOPTEST repository and running:
docker compose up web worker provision
Further details in the BOPTEST GitHub page.
Then you only need to change the url
to point to your local BOPTEST service deployment instead of the remote server (`url = 'http://127.0.0.1').
Note 2: on running BOPTEST locally in a vectorized environment
BOPTEST allows the deployment of multiple test case instances using Docker Compose.
Running a vectorized environment enables the deployment of as many BoptestGymEnv instances as cores you have available for the agent to learn from all of them in parallel. See here for more information, we specifically use SubprocVecEnv
. This can substantially speed up the training process.
To do so, deploy BOPTEST with multiple workers to spin multiple test cases. See the example below that prepares BOPTEST to spin two test cases.
docker compose up --scale worker=2 web worker provision
Then you can train an RL agent with parallel learning with the vectorized BOPTEST-gym environment. See /examples/run_vectorized.py
for an example on how to do so.
Versioning and main dependencies
Current BOPTEST-Gym version is v0.7.0
which is compatible with BOPTEST v0.7.0
(BOPTEST-Gym version should always be even with the BOPTEST version used).
The framework has been tested with gymnasium==0.28.1
and stable-baselines3==2.0.0
.
You can see testing/Dockerfile for a full description of the testing environment.
Citing the project
Please use the following reference if you used this repository for your research.
@inproceedings{boptestgym2021,
author = {Javier Arroyo and Carlo Manna and Fred Spiessens and Lieve Helsen},
title = {{An OpenAI-Gym environment for the Building Optimization Testing (BOPTEST) framework}},
year = {2021},
month = {September},
booktitle = {Proceedings of the 17th IBPSA Conference},
address = {Bruges, Belgium},
}
Owner metadata
- Name: IBPSA
- Login: ibpsa
- Email: [email protected]
- Kind: organization
- Description: International Building Performance Simulation Association
- Website: http://www.ibpsa.org
- Location: Worldwide
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/16223588?v=4
- Repositories: 12
- Last ynced at: 2024-03-27T12:18:13.678Z
- Profile URL: https://github.com/ibpsa
GitHub Events
Total
- Create event: 1
- Release event: 1
- Issues event: 5
- Watch event: 8
- Issue comment event: 1
- Push event: 19
- Pull request event: 4
Last Year
- Create event: 1
- Release event: 1
- Issues event: 5
- Watch event: 8
- Issue comment event: 1
- Push event: 19
- Pull request event: 4
Committers metadata
Last synced: 7 days ago
Total Commits: 557
Total Committers: 5
Avg Commits per committer: 111.4
Development Distribution Score (DDS): 0.171
Commits in past year: 92
Committers in past year: 2
Avg Commits per committer in past year: 46.0
Development Distribution Score (DDS) in past year: 0.076
Name | Commits | |
---|---|---|
Javier Arroyo | j****o@k****e | 462 |
Javier Arroyo | j****o@d****m | 85 |
Aniket Dixit | 3****2 | 7 |
XiangweiW | 8****W | 2 |
Michael Wetter | m****r@l****v | 1 |
Committer domains:
- lbl.gov: 1
- dnergy.com: 1
- kuleuven.be: 1
Issue and Pull Request metadata
Last synced: 1 day ago
Total issues: 90
Total pull requests: 73
Average time to close issues: 3 months
Average time to close pull requests: 3 days
Total issue authors: 9
Total pull request authors: 5
Average comments per issue: 0.62
Average comments per pull request: 0.29
Merged pull request: 68
Bot issues: 0
Bot pull requests: 0
Past year issues: 11
Past year pull requests: 11
Past year average time to close issues: 6 days
Past year average time to close pull requests: 9 days
Past year issue authors: 3
Past year pull request authors: 2
Past year average comments per issue: 1.64
Past year average comments per pull request: 0.91
Past year merged pull request: 10
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- JavierArroyoBastida (69)
- javiarrobas (12)
- IamAniket12 (2)
- dhblum (2)
- billtubbs (1)
- XiangweiW (1)
- vadim0x60 (1)
- kevin-vanvaerenbergh (1)
- alexandrecuer (1)
Top Pull Request Authors
- JavierArroyoBastida (59)
- javiarrobas (9)
- IamAniket12 (2)
- XiangweiW (2)
- Learner0x5a (1)
Top Issue Labels
- enhancement (4)
- good first issue (3)
- bug (2)
- wontfix (1)
Top Pull Request Labels
Dependencies
- actions/checkout v3 composite
- ubuntu 20.04 build
- cloudpickle ==2.2.1
- cmake ==3.26.4
- contourpy ==1.1.0
- cycler ==0.11.0
- farama-notifications ==0.0.4
- filelock ==3.12.2
- fonttools ==4.40.0
- gym ==0.26.2
- gym-notices ==0.0.8
- gymnasium ==0.28.1
- jax-jumpy ==1.0.0
- jinja2 ==3.1.2
- kiwisolver ==1.4.4
- lit ==16.0.6
- markupsafe ==2.1.3
- matplotlib ==3.7.1
- mpmath ==1.3.0
- networkx ==3.1
- numpy ==1.25.0
- nvidia-cublas-cu11 ==11.10.3.66
- nvidia-cuda-cupti-cu11 ==11.7.101
- nvidia-cuda-nvrtc-cu11 ==11.7.99
- nvidia-cuda-runtime-cu11 ==11.7.99
- nvidia-cudnn-cu11 ==8.5.0.96
- nvidia-cufft-cu11 ==10.9.0.58
- nvidia-curand-cu11 ==10.2.10.91
- nvidia-cusolver-cu11 ==11.4.0.1
- nvidia-cusparse-cu11 ==11.7.4.91
- nvidia-nccl-cu11 ==2.14.3
- nvidia-nvtx-cu11 ==11.7.91
- packaging ==23.1
- pandas ==2.0.3
- pillow ==10.0.0
- pyparsing ==3.1.0
- python-dateutil ==2.8.2
- pytz ==2023.3
- scipy ==1.11.1
- shimmy ==1.1.0
- six ==1.16.0
- stable-baselines3 ==2.0.0
- sympy ==1.12
- torch ==2.0.1
- triton ==2.0.0
- typing-extensions ==4.7.1
- tzdata ==2023.3
Score: 5.768320995793772