![analysis domains encompassed by BESOS.](docs/images/besos.png)


BESOS: Building and Energy Systems Optimization and Surrogate-modelling
=====

[![PyPI Latest Release](https://img.shields.io/pypi/v/besos.svg)](https://pypi.org/project/besos/)
[![PyPi Package format](https://img.shields.io/pypi/format/besos)](https://pypi.org/project/besos/)
[![PyPI Downloads](https://img.shields.io/pypi/dm/besos)](https://pypi.org/project/besos/)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4633738.svg)](https://doi.org/10.5281/zenodo.4633738)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.02677/status.svg)](https://doi.org/10.21105/joss.02677)

[![Documentation](https://img.shields.io/readthedocs/besos)](https://besos.readthedocs.io/en/stable/)

[![pipeline status](https://gitlab.com/energyincities/besos/badges/master/pipeline.svg)](https://gitlab.com/energyincities/besos/-/commits/master)
[![Coverage](https://gitlab.com/energyincities/besos/badges/master/coverage.svg)](https://gitlab.com/energyincities/besos/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)

BESOS is a collection of modules for the simulation and optimization of buildings and urban energy systems. BESOS is designed to help researchers and practitioners to design more sustainable, district-integrated buildings. It integrates [EnergyPlus](https://energyplus.net/) and [EnergyHub](https://gitlab.com/energyincities/python-ehub) simulation software with optimization and machine learning functionality. this includes lots of help with 'surrogate modelling', where machine learning models are fitted to data generated by parametric runs of detailed simulation models. BESOS facilitates running large-scale parametric analyses of EnergyPlus or EnergyHub models with output in a pandas DataFrame and using this to train machine learning surrogate models with scikit-learn or TensorFlow. We provide access to commonly used optimization algorithms via existing optimization toolboxes.

Installing BESOS
------------
Ensure that you have Python 3.7+ and the corresponding version of pip.
```pip install besos[complete]```
(If you do not want to run the example notebooks, you can use `pip install besos`, which will
install with less dependencies.)

### Install Dependencies
We use third party software to run building models (`EnergyPlus`), to solve EnergyHub models (a MILP solver), and make use of Rbfopt (via `Bonmin`). To use this functionality you need to install the software for the corresponding the task. GLPK and Bonmin are optional, it is possible to use Besos without them.


#### Install Energyplus
Download EnergyPlus [here](https://energyplus.net/downloads). (`BESOS` is currently supporting versions from 8.8-9.3+).

**For windows**: After downloading the installation file, double click the setup file to start installing.
After setup is complete, navigate to your `System Properties` and in the `Advanced` tab, select `Environment Variables`.
 In either your `User Variables` or `System Variables` (Depending on your permissions), double click on `Path`
 and add the location of your `EnergyPlus` folder to the end of it. Ensure the path is C:\EnergyPlusV{version} for proper integration with Besos.

**For linux**: Run the downloaded script, and accept the prompt to add symlinks. Ensure the path is /usr/local/EnergyPlus-{version} for proper integration with Besos.

#### TensorFlow (only required to use TensorFlow)
TensorFlow is a machine learning library of which we have provided some examples. This package is quite large 300 mb therefore we have not added this to the requirements.

To install TensorFlow use pip install.

```pip install tensorflow```


#### MILP solver (only required to use EnergyHub)
[EnergyHub](https://gitlab.com/energyincities/python-ehub) modelling requires a linear programming solver that is supported by [PuLP](https://pypi.org/project/PuLP/), such as `GLPK`, `CPlex`, or `Gurobi`. To learn about how to setup a custom solver please review the readthedocs page on [Customizing EnergyHub Solver](https://besos.readthedocs.io/en/stable/setting_a_custom_solver.html).

`GLPK` is free and open source. It can be found [here](https://www.gnu.org/software/glpk/).
If you are using a Debian based operating system, you can install GLPK with `sudo apt install glpk-utils`

#### Optional: Bonmin (only required to use RBFopt)
`Bonmin` is required to use the `RBFopt` optimizer.
How to install `Bonmin` can be found [here](https://ampl.com/products/solvers/open-source/#bonmin).


### Running Example Notebooks
Examples of Besos' functionality are provided through example notebooks. The notebooks can be viewed as Python scripts or through a Jupyter notebook.

You can run notebooks from the [Besos platform](https://besos.uvic.ca/), which has the besos library and all dependencies pre-installed, or you can install Jupyter locally.

To run the notebooks you need [Juptyer](https://jupyter.org/) installed. Jupyter can be installed using: `pip install juptyer` and launched from the current directory with `jupyter notebook`.

Contributing and Support
------------
When creating gitlab issues, please search the existing
[gitlab issues](https://gitlab.com/energyincities/besos/-/issues)
to see if someone else has already made the same request.

### Feature Requests
To request a feature open a new issue with your feature request.

### Bug reports/Questions
If you have found a bug, please open a gitlab issue describing the bug.
Make sure to include steps to reproduce the bug. Ideally, include a small
bit of code that causes the bug. If the bug causes an error, please include
the traceback. If the bug causes the wrong behaviour, please mention what
besos should do in this situation.

### Code contributions

If you are interested in contributing to the code please review the readthedocs page on [contributing to the code](https://besos.readthedocs.io/en/stable/contribute_to_the_code.html).


### Example notebooks
A good way to start is using the example notebooks.
They are described in the [examples overview](https://gitlab.com/energyincities/besos-examples/-/blob/master/besos/examples/ExamplesOverview.ipynb)
