GithubHelp home page GithubHelp logo

bsl546 / energym Goto Github PK

View Code? Open in Web Editor NEW
61.0 7.0 10.0 115.79 MB

Energym is an open source building simulation library designed to test climate control and energy management strategies on buildings in a systematic and reproducible way.

License: Other

Dockerfile 1.54% Shell 0.11% Python 56.38% Modelica 41.97%
building control mpc reinforcement learning energyplus modelica energy-management-strategies benchmarking control-algorithms

energym's Introduction

General

Energym is an open source building simulation library designed to test climate control and energy management strategies on buildings in a systematic and reproducible way. Energym includes a number of building models that are calibrated on site data and defines standard metrics, quantifying the objective to be reached and allowing a standardized comparison between different controllers and publications.

The library offers an intuitive interface to a variety of building models, similar to the one popularized by the Gym library used in the robotic control community. Energym relies on the functional mockup interface (FMI) standard in order to support models generated in multiple modelling languages easily. It currently includes 14 models developed in Modelica and EnergyPlus as well as specific classes for simulating weather forecasts and appliances consumption figures.

With the models already incorporated, Energym offers the possibility to benchmark controllers on buildings models that are representative of real-world HVAC systems. They cover different buildings typologies (institutional building, office building, etc.) and configuration of the HVAC where control can be performed at different levels (control of energy generation, control of final demand through setpoints, etc.).

New models are under development and will be integrated in due date.

Documentation

The full documentation (with installation instructions, usage examples, buildings characteristics) is available at Energym

Working principles

Energym is a toolkit for developing and comparing control algorithms for buildings. It makes no assumptions about the structure of the control algorithms, whose implementation is left up to the user.

The Energym library includes a collection of test problems — environments — that can be used to benchmark algorithms. An environement typically contains one building and all its equipment (heat pumps, chillers, batteries, Photovoltaic installation, etc), and defines the boundary conditions that affect the building, for example the weather patterns. The environments have a shared interface, allowing you to write general algorithms.

Energym allows to apply control inputs to the buildings subsystems, for example temperature setpoints, and to receive information about the current state of the building, including for example zone temperatures, power consumption, etc. The observation can be then used by the controller to adapt the control inputs.

basic scheme of controller - environement interactions

System requirements

Precompiled FMU files are made available to the user, for both Windows 10 and Linux platforms. The linux files have been tested on Ubuntu 18.04, 20.04 and CentOS 7.

Getting Started

The library runs with EnergyPlus and Modelica. To ensure that FMU models compiled from EnergyPlus models work, please install the following version of EnergyPlus:

  • EnergyPlus 9.5 link

Communication between the Python code and the FMU's relies on the package FMPy, which is installed with the default installation.

Installation

Firstly git clone the present repository and move inside with cd energym. Then run python setup.py install.

Docker version

For users willing to use containers, a dockerfile, called Dockerfile, is made available. It creates an Ubuntu 20.04 container, with EnergyPlus 9.5 and Python 3.8. This docker file is not made to compile .idf or .mo files and works with the precompiled FMU's. For this latter particular task, another dockerfile is provided, that downloads a pre-built docker image on dockerhub.

Available environments

Following environments are available:

Environment Thermostat Heat Pump Battery AHU EV PV Software
Apartments2Thermal-v0 ✔️ ✔️ ✔️ ✔️ 🔶 E+
Apartments2Grid-v0 ✔️ 🔶 ✔️ ✔️ 🔶 E+
ApartmentsThermal-v0 ✔️ ✔️ ✔️ ✔️ 🔶 E+
ApartmentsGrid-v0 ✔️ 🔶 ✔️ ✔️ 🔶 E+
OfficesThermostat-v0 ✔️ 🔶 E+
MixedUseFanFCU-v0 ✔️ ✔️ E+
SeminarcenterThermostat-v0 ✔️ 🔶 🔶 E+
SeminarcenterFull-v0 ✔️ ✔️ 🔶 E+
SimpleHouseRad-v0 ✔️ 🔶 Mod
SimpleHouseRSla-v0 ✔️ 🔶 Mod
SwissHouseRSlaW2W-v0 ✔️ 🔶 Mod
SwissHouseRSlaA2W-v0 ✔️ 🔶 Mod
SwissHouseRSlaTank-v0 ✔️ 🔶 Mod
SwissHouseRSlaTankDhw-v0 ✔️ 🔶 Mod

✔️ : present and controllable, 🔶 : present but not controllable, ❌ : absent.

Control variables are outlined in yaml files for all environments in the simulation folder. Environment simulations are packed into FMU's for windows and debian distributions.

Use the interface

An examplatory usage of Energym (assuming a function get_input() for computing the controls) looks as follows

import energym

envName = "Apartments2Grid-v0"
nsteps = 10
env = energym.make(envName, simulation_days=100)
obs = env.get_output()
for _ in range(nsteps):
    inputs = get_input(obs)
    obs = env.step(inputs)
env.close()

Run an example

Examples of using the models can be found here

Input/Output reference for E+ models

Every FMU generated by an E+ model specifies certain inputs and outputs. Their format is defined as zone_type(_device(_sp(_out)))

The different parts of the naming convention refer to:

  • zone: Specifies the measured location, e.g. building zones (Z01, ..., Z99), the whole building Bd or the exterior Ext.
  • type: Specifies the measured unit, e.g. the temperature T, the relative humidity RH, the power demand Pw, the energy consumption or production E or the flow rate Fl.
  • device (optional): Specifies the measured object, e.g. a thermostat Thermostat, a heat pump HP, a HVAC unit HVAC, a solar panel PV or the combination of all energy consuming devices All.
  • sp (optional): Specifies that the given value is used as a setpoint.
  • out (optional): Specifies that a given setpoint is output.

Solar panels are the only devices in these buildings that produce energy.

Examples:

  • Z01_Pw_HVAC
  • Ext_T
  • Z99_T_Thermostat_sp_out

For every environment, a list of inputs, outputs and weather files used is specified in the energym/envs folder for every building project.

Contributing new models

Users are encouraged to upload new environments that present an interest for building control.

On Windows

Please, download the latest version of EnergyPlus as well as a C/C++ compiler (for e.g., microsoft visual studio build tools). On windows, change the default compiler address in the .bat files in EnergyPlusToFMU/Scripts/win to your current C compiler address. To create a new model, please create a new folder in simulation/energyplus or simulation/modelica. The folder must have following structure:

  • fmus: where FMU's will be stored
  • src: with .idf or .mo files: reference files to build the FMU's on any platform
  • wf: weather files to be used for training and benchmarking evaluation

The energym/envs folder contains the specifics of the model: inputs, outputs as well as weather files for benchmarking and benchmarking metrics KPI's on the output

Once those steps have been carried out, run the script script/create_eplus_env.py to build EnergyPlus FMU's or scripts/create_mo_env_jmod.py to build Modelica FMU's (ensure before that you have JModelica installed and running under Python 2.7).

Docker files (runs on linux machines or windows machines with WSL2)

Two docker pre-built images are stored on dockerhub, one for model launching and interaction, and one heavier for model compilation.

Cite

If you use our library for your work, please cite our paper:

Scharnhorst, P.; Schubnel, B.; Fernández Bandera, C.; Salom, J.; Taddeo, P.; Boegli, M.; Gorecki, T.; Stauffer, Y.; Peppas, A.; Politi, C. Energym: A Building Model Library for Controller Benchmarking. Appl. Sci. 2021, 11, 3518. https://doi.org/10.3390/app11083518

energym's People

Contributors

bsl546 avatar mxbgl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

energym's Issues

Update : Missing observation space while linking Model with environment

Code:

import energym
from energym.examples.Controller import LabController
from energym.wrappers.rl_wrapper import RLWrapper
import gym
from stable_baselines3 import PPO

envName = "Apartments2Thermal-v0"
env = energym.make(envName, weather = "ESP_CT_Barcelona", simulation_days=300)
reward = lambda output : 1/(abs(output['Z01_T']-22)+0.1)
env_RL = RLWrapper(env, reward)
inputs = env_RL.get_inputs_names()
model = PPO('MlpPolicy', env_RL, verbose=1)
model.learn(total_timesteps=4800)

Here is the error traceback:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-142-2f18c2afcb80> in <module>
----> 1 model = PPO('MlpPolicy', env_RL, verbose=1)
      2 model.learn(total_timesteps=4800)

~/.local/lib/python3.8/site-packages/stable_baselines3/ppo/ppo.py in __init__(self, policy, env, learning_rate, n_steps, batch_size, n_epochs, gamma, gae_lambda, clip_range, clip_range_vf, ent_coef, vf_coef, max_grad_norm, use_sde, sde_sample_freq, target_kl, tensorboard_log, create_eval_env, policy_kwargs, verbose, seed, device, _init_setup_model)
     90     ):
     91 
---> 92         super(PPO, self).__init__(
     93             policy,
     94             env,

~/.local/lib/python3.8/site-packages/stable_baselines3/common/on_policy_algorithm.py in __init__(self, policy, env, learning_rate, n_steps, gamma, gae_lambda, ent_coef, vf_coef, max_grad_norm, use_sde, sde_sample_freq, tensorboard_log, create_eval_env, monitor_wrapper, policy_kwargs, verbose, seed, device, _init_setup_model)
     72     ):
     73 
---> 74         super(OnPolicyAlgorithm, self).__init__(
     75             policy=policy,
     76             env=env,

~/.local/lib/python3.8/site-packages/stable_baselines3/common/base_class.py in __init__(self, policy, env, policy_base, learning_rate, policy_kwargs, tensorboard_log, verbose, device, support_multi_env, create_eval_env, monitor_wrapper, seed, use_sde, sde_sample_freq)
    155 
    156             env = maybe_make_env(env, monitor_wrapper, self.verbose)
--> 157             env = self._wrap_env(env, self.verbose)
    158 
    159             self.observation_space = env.observation_space

~/.local/lib/python3.8/site-packages/stable_baselines3/common/base_class.py in _wrap_env(env, verbose)
    175             if verbose >= 1:
    176                 print("Wrapping the env in a DummyVecEnv.")
--> 177             env = DummyVecEnv([lambda: env])
    178 
    179         if is_image_space(env.observation_space) and not is_wrapped(env, VecTransposeImage):

~/.local/lib/python3.8/site-packages/stable_baselines3/common/vec_env/dummy_vec_env.py in __init__(self, env_fns)
     25         self.envs = [fn() for fn in env_fns]
     26         env = self.envs[0]
---> 27         VecEnv.__init__(self, len(env_fns), env.observation_space, env.action_space)
     28         obs_space = env.observation_space
     29         self.keys, shapes, dtypes = obs_space_info(obs_space)

/usr/local/lib/python3.8/dist-packages/energym-0.1-py3.8.egg/energym/envs/env.py in __getattr__(self, name)
    164                 "attempted to get missing private attribute '{}'".format(name)
    165             )
--> 166         return getattr(self.env, name)
    167 
    168     @classmethod

AttributeError: 'Apartments2' object has no attribute 'observation_space'

adjust simulation year

Hello! I have a question that has been bothering me. The result I obtained indicates that the start date of the simulation environment for the MixedUse environment is January 1, 2017, but isn't the default in the MixedUse class supposed to be 2019? Why isn't the start date of the simulation environment January 1, 2019? Could it be that I misunderstood something? Also, if I want to start from January 1, 2014, and run the experiment in the MixedUse simulation environment for one year, how should I modify it? I have tried many methods, but the start date of the simulation environment in the experiment remains January 1, 2017.
image
image

Difference between simulation days and number of steps

Hello,

Thank you for your work!

I just had a couple of questions regarding the simulation days and number of steps. What is the difference, and what should be considered when selecting them?

For example:

import energym

weather = "GRC_A_Athens"
env = energym.make("OfficesThermostat-v0", weather=weather, simulation_days=300)
steps = 96*10
for _ in range(steps):
    # etc...

It is mentioned, here 96 steps per day for 10 days. If it means 96 steps for 10 days, then what is the purpose of the simulation steps, and why are they not the same?

Thank you so much in advance!

SwissHouseRSlaTank-v0 return NoneType

hi! trying the code copied by the notebook example into the documentation of SwissHouseRSlaTank-v0 model i found an error. The compilation return the following error:
AttributeError: 'NoneType' object has no attribute 'get_inputs_names'.

Seems that it can't build the environment correctly. i've tried other models, and all of them work properly.

Following, the full error log:

Unable to build model. Failed to validate modelDescription.xml:

  • The combination causality="local" and variability="constant" in variable "heaPum.eva.port_b.p" (line 1684) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.preDro.port_b.p" (line 1792) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.dynBal.medium.p" (line 2072) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.dynBal.medium.state.p" (line 2100) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.dynBal.p_start" (line 2112) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.dynBal.ports[1].p" (line 2128) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.dynBal.ports[2].p" (line 2144) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.p" (line 2280) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.p_start" (line 2284) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.ports[1].p" (line 2304) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.ports[2].p" (line 2320) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.state_start.p" (line 2380) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.port_b2.p" (line 2500) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.staB2.p" (line 2552) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.sta_b2.p" (line 2600) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.state_b2_inflow.p" (line 2648) is not allowed.
  • The combination causality="local" and variability="constant" in variable "hole.p_in_internal" (line 2736) is not allowed.
  • The combination causality="local" and variability="constant" in variable "hole.ports[1].p" (line 2752) is not allowed.
    Traceback (most recent call last):
    File "C:\Users\filip\AppData\Local\Programs\Python\Python311\Lib\site-packages\energym-0.1-py3.11.egg\energym\factory.py", line 570, in make
    return SwissHouse(
    ^^^^^^^^^^^
    File "C:\Users\filip\AppData\Local\Programs\Python\Python311\Lib\site-packages\energym-0.1-py3.11.egg\energym\envs\swiss_house\swiss_house.py", line 261, in init
    super().init(
    File "C:\Users\filip\AppData\Local\Programs\Python\Python311\Lib\site-packages\energym-0.1-py3.11.egg\energym\envs\env_fmu_mod.py", line 131, in init
    super().init(
    File "C:\Users\filip\AppData\Local\Programs\Python\Python311\Lib\site-packages\energym-0.1-py3.11.egg\energym\envs\env_fmu.py", line 159, in init
    self.model_description = read_model_description(self.fmu_file)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\filip\AppData\Local\Programs\Python\Python311\Lib\site-packages\fmpy-0.3.20-py3.11.egg\fmpy\model_description.py", line 889, in read_model_description
    raise ValidationError(problems)
    fmpy.model_description.ValidationError: Failed to validate modelDescription.xml:
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.port_b.p" (line 1684) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.preDro.port_b.p" (line 1792) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.dynBal.medium.p" (line 2072) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.dynBal.medium.state.p" (line 2100) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.dynBal.p_start" (line 2112) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.dynBal.ports[1].p" (line 2128) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.dynBal.ports[2].p" (line 2144) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.p" (line 2280) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.p_start" (line 2284) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.ports[1].p" (line 2304) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.ports[2].p" (line 2320) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.eva.vol.state_start.p" (line 2380) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.port_b2.p" (line 2500) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.staB2.p" (line 2552) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.sta_b2.p" (line 2600) is not allowed.
  • The combination causality="local" and variability="constant" in variable "heaPum.state_b2_inflow.p" (line 2648) is not allowed.
  • The combination causality="local" and variability="constant" in variable "hole.p_in_internal" (line 2736) is not allowed.
  • The combination causality="local" and variability="constant" in variable "hole.ports[1].p" (line 2752) is not allowed.
    Traceback (most recent call last):
    File "c:\Users\filip\Desktop\politecnico\tesi\EnerGym\SwissHouseRSlTank.py", line 6, in
    inputs = env.get_inputs_names()
    ^^^^^^^^^^^^^^^^^^^^
    AttributeError: 'NoneType' object has no attribute 'get_inputs_names'

The code:

import energym
weather = "CH_BS_Basel"
env = energym.make("SwissHouseRSlaTank-v0", weather=weather, simulation_days=20)
inputs = env.get_inputs_names()
outputs = env.get_outputs_names()
print("inputs:", inputs)
print("outputs:", outputs)

thanks in advance.
Filippo

How do I specify EnergyPlus executable path?

I got the error fmi2EnterInitializationMode: The FMU instance could instance1658863597 not be initialized. EnergyPlus can't start . Check if EnergyPlus is installed and on the system path. Unable to build model. fmi2EnterInitializationMode failed with status 3 (error).

by creating an environment. I do have EnergyPlus installed, however, how do I let Energym know where do I put it?

Note: detailed information pasted below:
Screen Shot 2022-07-26 at 12 28 28 PM

Documentation : Add examples of energym used in the context of HVAC Problems

I thought it might be a good idea to document how to use the energym api in the context of a Wrapped Environement (RL) for research purposes.
Thanks for the hardwork guys and here is the minimal example, where in the end there is a small fix to make the loop work :)

Code:

import energym
from energym.examples.Controller import LabController
from energym.wrappers.rl_wrapper import RLWrapper

envName = "Apartments2Thermal-v0"
env = energym.make(envName, weather = "ESP_CT_Barcelona", simulation_days=300)
reward = lambda output : 1/(abs(output['Z01_T']-22)+0.1)
env_RL = RLWrapper(env, reward)
inputs = env_RL.get_inputs_names()
controller = LabController(control_list=inputs, lower_tol=0.3, upper_tol=0.8
                           
                          )
steps = 480*10
out_list = []
outputs = env_RL.get_output()
controls = []
hour = 0
for i in range(steps):
    control = controller.get_control(outputs, 21, hour)
    control['Bd_Ch_EV1Bat_sp'] = [0.0]
    control['Bd_Ch_EV2Bat_sp'] = [0.0]
    controls +=[ {p:control[p][0] for p in control} ]
    outputs = env_RL.step(control)
    outputs[0].update({"reward":outputs[1]})
    out_list.append(outputs)
    outputs,_,_,_ = outputs
    del outputs["reward"]
    _,hour,_,_ = env_RL.get_date()
    

代码运行时间过长

为什么我使用 Energym 库中的控制器来控制enerpuls中的建筑模型,代码运行好几天一直停留在下面这个界面,是这个代码本身就需要运行这么长吗?还是我的环境没配置好
@ )BVX)VY5L$5VDS% T{FQA
LSO2X_DTI4{ZWG@1SDGJ~3A

Adding new models

Dear,

Thanks for your great work. I'm trying to add new models to the environment but after compiling the FMU it is unclear how to use it. By reading a little bit of the code of the existing ones I have understood that I have to create a enviromnet.py script but is completely unclear how to and in particular how to add it to the factory.py script that is the one in charge of doing the make command. Could you provide some guidelines for it or a tutorial?

Thanks a lot

2022.12.26 erro

Starting Simulation at 01/01/2017 for ALL_YEAR
ExternalInterface starts first data exchange.
Error: Unspecified error when reading from socket.
**FATAL:Error in ExternalInterface: Check EnergyPlus *.err file.

Obtain output csv from EnergyPlus

Hello everyone, firstly I wanted to congratulate you on your work as I find it very useful!

I'm writing to you because I would like to get in output from EnergyPlus a detailed csv with the results. I realized that in the idf the following statement has not been inserted for any of the building examples:
"Output:Diagnostics,
DisplayAdvancedReportVariables; "

I tried to manually add this, the problem is that energym goes to consider the fmu that was created for the default idf. I tried to create the fmu therefore, however without any success. I wanted to ask you if you could help me with the creation of the fmu (I get this error
"Problem configuring the Visual Studio tools for command-line use
ERROR from script file {utilManageCompileLink.py}
Failed to create object file for source code file {...\EnergyPlusToFMU\SourceCode\v20\fmu-export-prep\fmu-export-write-model-desc.cpp})
or if you could create it starting from the idf with the possibility to print the output csv directly from energyplus.

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.