Home

Awesome

<div align="center"> <img width="300" src="https://github.com/rebase-energy/enerflow/blob/main/assets/enerflow-logo.png?raw=true" alt="enerflow"> <h2 style="margin-top: 0px;"> โšก Open-source Python framework for modelling sequential decision problems in the energy sector </h2> </div>

License: MIT PyPI version All Contributors Join us on Slack GitHub Repo stars

enerflow is an open-source Python framework that enables energy data scientists and modellers to write modular and reproducible energy models that solves sequential decision problems. It is based on both OpenAI Gym (now Gymnasium) and Warran Powell's universal sequential decision framework. enerflow lets you:

โฌ‡๏ธ Installation โ€‚|โ€‚ ๐Ÿ“– Documentation โ€‚|โ€‚ ๐Ÿš€ Try out now in Colab โ€‚|โ€‚ ๐Ÿ‘‹ Join Community Slack

The Sequential Decision Loop

enerflow allows to model sequential decison problems, where state information $S_t$ is provided, an action $a_t=A^{\pi}(S_t)$ is taken, exogenous information $W_{t+1}$ is revealed, whereby a new state $S_{t+1} = S^M(S_t, a_t, W_{t+1})$ is encountered and a cost/contribution $C(S_t,a_t,W_{t+1})$ can be calculated. The sequential decision loop then repeats until the end of the evaluation/problem time.

Sequential decision loop

The goal is to find an agent policy $\pi$ that maximizes the contribution (or minimizes the cost) over the full time horizon $t \in [0, T]$. Mathematically formulated as:

$$ \begin{equation*} \begin{aligned} \max_{\pi \in \Pi} \quad & \mathbb{E}^{\pi} \bigg[ \sum_{t=0}^T C(S_t,A^{\pi}(S_t),W_{t+1}) \bigg| S_0 \bigg] \ \textrm{s.t.} \quad & S_{t+1} = S^M(S_t,a_t,W_{t+1})\ \end{aligned} \end{equation*} $$

Modules and Components

enerflow consists of a set of components that serve as building blocks to create modular and reusable energy models. One of the main dependencies is EnergyDataModel that provides functionality to represent energy systems. The table below gives a summary of the available modules and concepts.

ModuleComponents
๐Ÿ”‹ย energysystemAll energy asset and concept components defined by EnergyDataModel
๐Ÿ“ฆย spacesBaseSpace, InputSpace, OutputSpace StateSpace ActionSpace
๐Ÿงฉย problemsDataset, Environment, Objective
๐Ÿค–ย modelsModel, Simulator, Predictor, Optimizer, Agent
โžก๏ธย experimentExperiment

Below is a diagram of the components' relation to each other and how they together enable creation of reproducible results from energy models.

enerflow Framework Structure

Framework 6-Step Approach

enerflow is about adopting a problem-centric, stepwise approach that follows the "model first, then solve"-mantra. The idea is to first gain a deep problem understanding before rushing to the solution. Or as Albert Einstien expressed it:

"If I had an hour to solve a problem I'd spend 55 minutes thinking about the problem and five minutes thinking about solutions."

Concretely, this means that problems are solved through the following steps:

  1. Define the considered energy system;
  2. Define state, action and exogenous variables;
  3. Create the environment and the transition function;
  4. Define the objective (cost or contribution);
  5. Create the model (simulator, predictor, optimizer and/or agent) to operate in environment; and
  6. Run the sequential decision loop and evaluate performance.

Steps 1-4 are about understanding the problem and steps 5-6 are about creating and evaluating the solution.

Basic Usage

In enerflow, a reproducible experiment is represented by the following 4 components:

Given a defined dataset, env (environment), agent (model) and obj (objective), the sequential decision loop is given by:

# Create the env, agent and obj. Your code goes in defining these classes. 
env = Environment(dataset=dataset)
agent = Agent(dataset=dataset)
obj = Objective(dataset=dataset)

state = env.reset()
done = False
while done is not True:
    action = agent.act(state)
    state, exogeneous, done, info = env.step(action)
    cost = obj.calculate(state, action, exogeneous)

env.close()

For a full walkthrough go to the documentation or open in Colab.

Installation

Install the stable release:

pip install enerflow

Install the latest release:

pip install git+https://github.com/rebase-energy/enerflow

Install in editable mode for development:

git clone https://github.com/rebase-energy/enerflow.git
cd enerflow
pip install -e . 

Ways to Contribute

We welcome contributions from anyone interested in this project! Here are some ways to contribute to enerflow:

If you are interested in contributing, then feel free to join our Community Slack so that we can discuss it.

Contributors

This project uses allcontributors.org to recognize all contributors, including those that don't push code.

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tbody> <tr> <td align="center" valign="top" width="14.28%"><a href="https://github.com/sebaheg"><img src="https://avatars.githubusercontent.com/u/26311427?v=4?s=100" width="100px;" alt="Sebastian Haglund"/><br /><sub><b>Sebastian Haglund</b></sub></a><br /><a href="#code-sebaheg" title="Code">๐Ÿ’ป</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/dimili"><img src="https://avatars.githubusercontent.com/u/13037448?v=4?s=100" width="100px;" alt="dimili"/><br /><sub><b>dimili</b></sub></a><br /><a href="#code-dimili" title="Code">๐Ÿ’ป</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/rocipher"><img src="https://avatars.githubusercontent.com/u/4830171?v=4?s=100" width="100px;" alt="Mihai Chiru"/><br /><sub><b>Mihai Chiru</b></sub></a><br /><a href="#code-rocipher" title="Code">๐Ÿ’ป</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/nelson-sommerfeldt"><img src="https://avatars.githubusercontent.com/u/95913116?v=4?s=100" width="100px;" alt="Nelson"/><br /><sub><b>Nelson</b></sub></a><br /><a href="#ideas-nelson-sommerfeldt" title="Ideas, Planning, & Feedback">๐Ÿค”</a></td> </tr> </tbody> </table> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->

Licence

This project uses the MIT Licence.