Skip to content

Commit 83bba92

Browse files
authored
Feature/docs (#189)
* Add docs * Change docs type to numpy * Automate docs * Only deploy docs on release * ruff check
1 parent 0b6e257 commit 83bba92

17 files changed

Lines changed: 663 additions & 0 deletions

.github/workflows/python-app.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ jobs:
5656
- name: Run tests
5757
run: pytest -v -p no:warnings
5858

59+
deploy-docs:
60+
runs-on: ubuntu-latest
61+
if: github.event_name == 'release' && github.event.action == 'created' # Only on release creation
62+
steps:
63+
- uses: actions/checkout@v4
64+
- name: Configure Git Credentials
65+
run: |
66+
git config user.name github-actions[bot]
67+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
68+
- uses: actions/setup-python@v5
69+
with:
70+
python-version: 3.11
71+
- name: Install dependencies
72+
run: |
73+
pip install -e .[docs]
74+
- name: Deploy documentation
75+
run: mkdocs gh-deploy --force
76+
5977
publish-testpypi:
6078
name: Publish to TestPyPI
6179
runs-on: ubuntu-22.04

docs/SUMMARY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- [Home](index.md)
2+
- [Getting Started](getting-started.md)
3+
- [Concepts & Math](concepts-and-math/)
4+
- [Examples](examples/)
5+
- [API-Reference](api-reference/)
6+
- [Contribute](contribute.md)
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
2+
# Mathematical Notation
3+
4+
## Naming Conventions
5+
6+
flixOpt uses the following naming conventions:
7+
8+
- All optimization variables are denoted by italic letters (e.g., $x$, $y$, $z$)
9+
- All parameters and constants are denoted by non italic small letters (e.g., $\text{a}$, $\text{b}$, $\text{c}$)
10+
- All Sets are denoted by greek capital letters (e.g., $\mathcal{F}$, $\mathcal{E}$)
11+
- All units of a set are denoted by greek small letters (e.g., $\mathcal{f}$, $\mathcal{e}$)
12+
- The letter $i$ is used to denote an index (e.g., $i=1,\dots,\text n$)
13+
- All time steps are denoted by the letter $\text{t}$ (e.g., $\text{t}_0$, $\text{t}_1$, $\text{t}_i$)
14+
15+
## Buses
16+
17+
The balance equation for a bus is:
18+
19+
$$ \label{eq:bus_balance}
20+
\sum_{f_\text{in} \in \mathcal{F}_\text{in}} p_{f_\text{in}}(\text{t}_i) =
21+
\sum_{f_\text{out} \in \mathcal{F}_\text{out}} p_{f_\text{out}}(\text{t}_i)
22+
$$
23+
24+
Optionally, a Bus can have a `excess_penalty_per_flow_hour` parameter, which allows to penalize the balance for missing or excess flow-rates.
25+
This is usefull as it handles a possible ifeasiblity gently.
26+
27+
This changes the balance to
28+
29+
$$ \label{eq:bus_balance-excess}
30+
\sum_{f_\text{in} \in \mathcal{F}_\text{in}} p_{f_ \text{in}}(\text{t}_i) + \phi_\text{in}(\text{t}_i) =
31+
\sum_{f_\text{out} \in \mathcal{F}_\text{out}} p_{f_\text{out}}(\text{t}_i) + \phi_\text{out}(\text{t}_i)
32+
$$
33+
34+
The penalty term is defined as
35+
36+
$$ \label{eq:bus_penalty}
37+
s_{b \rightarrow \Phi}(\text{t}_i) =
38+
\text a_{b \rightarrow \Phi}(\text{t}_i) \cdot \Delta \text{t}_i
39+
\cdot [ \phi_\text{in}(\text{t}_i) + \phi_\text{out}(\text{t}_i) ]
40+
$$
41+
42+
With:
43+
44+
- $\mathcal{F}_\text{in}$ and $\mathcal{F}_\text{out}$ being the set of all incoming and outgoing flows
45+
- $p_{f_\text{in}}(\text{t}_i)$ and $p_{f_\text{out}}(\text{t}_i)$ being the flow-rate at time $\text{t}_i$ for flow $f_\text{in}$ and $f_\text{out}$, respectively
46+
- $\phi_\text{in}(\text{t}_i)$ and $\phi_\text{out}(\text{t}_i)$ being the missing or excess flow-rate at time $\text{t}_i$, respectively
47+
- $\text{t}_i$ being the time step
48+
- $s_{b \rightarrow \Phi}(\text{t}_i)$ being the penalty term
49+
- $\text a_{b \rightarrow \Phi}(\text{t}_i)$ being the penalty coefficient (`excess_penalty_per_flow_hour`)
50+
51+
## Flows
52+
53+
The flow-rate is the main optimization variable of the Flow. It's limited by the size of the Flow and relative bounds \eqref{eq:flow_rate}.
54+
55+
$$ \label{eq:flow_rate}
56+
\text P \cdot \text p^{\text{L}}_{\text{rel}}(\text{t}_{i})
57+
\leq p(\text{t}_{i}) \leq
58+
\text P \cdot \text p^{\text{U}}_{\text{rel}}(\text{t}_{i})
59+
$$
60+
61+
With:
62+
63+
- $\text P$ being the size of the Flow
64+
- $p(\text{t}_{i})$ being the flow-rate at time $\text{t}_{i}$
65+
- $\text p^{\text{L}}_{\text{rel}}(\text{t}_{i})$ being the relative lower bound (typically 0)
66+
- $\text p^{\text{U}}_{\text{rel}}(\text{t}_{i})$ being the relative upper bound (typically 1)
67+
68+
With $\text p^{\text{L}}_{\text{rel}}(\text{t}_{i}) = 0$ and $\text p^{\text{U}}_{\text{rel}}(\text{t}_{i}) = 1$,
69+
equation \eqref{eq:flow_rate} simplifies to
70+
71+
$$
72+
0 \leq p(\text{t}_{i}) \leq \text P
73+
$$
74+
75+
76+
This mathematical Formulation can be extended or changed when using [OnOffParameters](#omoffparameters)
77+
to define the On/Off state of the Flow, or [InvestParameters](#investments),
78+
which changes the size of the Flow from a constant to an optimization variable.
79+
80+
## LinearConverters
81+
[`LinearConverters`][flixOpt.components.LinearConverter] define a ratio between incoming and outgoing [Flows](#flows).
82+
83+
$$ \label{eq:Linear-Transformer-Ratio}
84+
\sum_{f_{\text{in}} \in \mathcal F_{in}} \text a_{f_{\text{in}}}(\text{t}_i) \cdot p_{f_\text{in}}(\text{t}_i) = \sum_{f_{\text{out}} \in \mathcal F_{out}} \text b_{f_\text{out}}(\text{t}_i) \cdot p_{f_\text{out}}(\text{t}_i)
85+
$$
86+
87+
With:
88+
89+
- $\mathcal F_{in}$ and $\mathcal F_{out}$ being the set of all incoming and outgoing flows
90+
- $p_{f_\text{in}}(\text{t}_i)$ and $p_{f_\text{out}}(\text{t}_i)$ being the flow-rate at time $\text{t}_i$ for flow $f_\text{in}$ and $f_\text{out}$, respectively
91+
- $\text a_{f_\text{in}}(\text{t}_i)$ and $\text b_{f_\text{out}}(\text{t}_i)$ being the ratio of the flow-rate at time $\text{t}_i$ for flow $f_\text{in}$ and $f_\text{out}$, respectively
92+
93+
With one incoming **Flow** and one outgoing **Flow**, this can be simplified to:
94+
95+
$$ \label{eq:Linear-Transformer-Ratio-simple}
96+
\text a(\text{t}_i) \cdot p_{f_\text{in}}(\text{t}_i) = p_{f_\text{out}}(\text{t}_i)
97+
$$
98+
99+
where $\text a$ can be interpreted as the conversion efficiency of the **LinearTransformer**.
100+
#### Piecewise Concersion factors
101+
The conversion efficiency can be defined as a piecewise function.
102+
103+
## Effects
104+
## Features
105+
### InvestParameters
106+
### OnOffParameters
107+
108+
## Calculation Modes

docs/concepts-and-math/index.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# flixOpt Concepts & Mathematical Description
2+
3+
flixOpt is built around a set of core concepts that work together to represent and optimize energy and material flow systems. This page provides a high-level overview of these concepts and how they interact.
4+
5+
## Core Concepts
6+
7+
### FlowSystem
8+
9+
The [`FlowSystem`][flixOpt.flow_system.FlowSystem] is the central organizing unit in flixOpt.
10+
Every flixOpt model starts with creating a FlowSystem. It:
11+
12+
- Defines the timesteps for the optimization
13+
- Contains and connects [components](#components), [buses](#buses), and [flows](#flows)
14+
- Manages the [effects](#effects) (objectives and constraints)
15+
16+
### Timesteps
17+
Time steps are defined as a sequence of discrete time steps $\text{t}_i \in \mathcal{T} \quad \text{for} \quad i \in \{1, 2, \dots, \text{n}\}$ (left-aligned in its timespan).
18+
From this sequence, the corresponding time intervals $\Delta \text{t}_i \in \Delta \mathcal{T}$ are derived as
19+
20+
$$\Delta \text{t}_i = \text{t}_{i+1} - \text{t}_i \quad \text{for} \quad i \in \{1, 2, \dots, \text{n}-1\}$$
21+
22+
The final time interval $\Delta \text{t}_\text n$ defaults to $\Delta \text{t}_\text n = \Delta \text{t}_{\text n-1}$, but is of course customizable.
23+
Non-equidistant time steps are also supported.
24+
25+
### Buses
26+
27+
[`Bus`][flixOpt.elements.Bus] objects represent nodes or connection points in a FlowSystem. They:
28+
29+
- Balance incoming and outgoing flows
30+
- Can represent physical networks like heat, electricity, or gas
31+
- Handle infeasible balances gently by allowing the balance to be closed in return for a big Penalty (optional)
32+
33+
### Flows
34+
35+
[`Flow`][flixOpt.elements.Flow] objects represent the movement of energy or material between a [Bus](#buses) and a [Component](#components) in a predefined direction.
36+
37+
- Have a `flow_rate`, which is the main optimization variable of a Flow
38+
- Have a `size` which defines how much energy or material can be moved (fixed or part of an investment decision)
39+
- Have constraints to limit the flow-rate (min/max, total flow hours, on/off etc.)
40+
- Can have fixed profiles (for demands or renewable generation)
41+
- Can have [Effects](#effects) associated by their use (operation, investment, on/off, ...)
42+
43+
### Components
44+
45+
[`Component`][flixOpt.elements.Component] objects usually represent physical entities in your system that interact with [`Flows`][flixOpt.elements.Flow]. They include:
46+
47+
- [`LinearConverters`][flixOpt.components.LinearConverter] - Converts input flows to output flows with (piecewise) linear relationships
48+
- [`Storages`][flixOpt.components.Storage] - Stores energy or material over time
49+
- [`Sources`][flixOpt.components.Source] / [`Sinks`][flixOpt.components.Sink] / [`SourceAndSinks`][flixOpt.components.SourceAndSink] - Produce or consume flows. They are usually used to model external demands or supplies.
50+
- [`Transmissions`][flixOpt.components.Transmission] - Moves flows between locations with possible losses
51+
- Specialized [`LinearConverters`][flixOpt.components.LinearConverter] like [`Boilers`][flixOpt.linear_converters.Boiler], [`HeatPumps`][flixOpt.linear_converters.HeatPump], [`CHPs`][flixOpt.linear_converters.CHP], etc. These simplify the usage of the `LinearConverter` class and can also be used as blueprint on how to define custom classes or parameterize existing ones.
52+
53+
### Effects
54+
55+
[`Effect`][flixOpt.effects.Effect] objects represent impacts or metrics related to your system, such as:
56+
57+
- Costs (investment, operation)
58+
- Emissions (CO₂, NOx, etc.)
59+
- Resource consumption
60+
61+
These can be freely defined and crosslink to each other (`CO₂` ──[specific CO₂-costs]─→ `Costs`).
62+
One effect is designated as the **optimization objective** (typically Costs), while others can have constraints.
63+
This effect can incorporate several other effects, which woul result in a weighted objective from multiple effects.
64+
65+
### Calculation Modes
66+
67+
flixOpt offers different calculation approaches:
68+
69+
- [`FullCalculation`][flixOpt.calculation.FullCalculation] - Solves the entire problem at once
70+
- [`SegmentedCalculation`][flixOpt.calculation.SegmentedCalculation] - Solves the problem in segments (with optioinal overlap), improving performance for large problems
71+
- [`AggregatedCalculation`][flixOpt.calculation.AggregatedCalculation] - Uses typical periods to reduce computational requirements
72+
73+
## How These Concepts Work Together
74+
75+
1. You create a `FlowSystem` with a specified time series
76+
2. You add elements to the FLowSystem:
77+
- `Bus` objects as connection points
78+
- `Component` objects like Boilers, Storages, etc.. They include `Flow` which define the connection to a Bus.
79+
- `Effect` objects to represent costs, emissions, etc.
80+
3.You choose a calculation mode and solver
81+
4.flixOpt converts your model into a mathematical optimization problem
82+
5.The solver finds the optimal solution
83+
6.You analyze the results with built-in or external tools
84+
85+
## Advanced Usage
86+
flixOpt uses [linopy](https://github.com/PyPSA/linopy) to model the mathematical optimization problem.
87+
Any model created with flixOpt can be extended or modified using the great [linopy API](https://linopy.readthedocs.io/en/latest/api.html).
88+
This allows to adjust your model to very specific requirements without loosing the convenience of flixOpt.
89+
90+
91+
92+
## Architechture (outdated)
93+
![Architecture](../images/architecture_flixOpt.png)
94+
95+
96+
<!--## Next Steps-->
97+
<!---->
98+
<!--Now that you understand the basic concepts, learn more about each one:-->
99+
<!---->
100+
<!--- [FlowSystem](api/flow_system.md) - Time series and system organization-->
101+
<!--- [Components](api/components.md) - Available component types and how to use them-->
102+
<!--- [Effects](apieffects.md) - Costs, emissions, and other impacts-->
103+
<!--- [Calculation Modes](api/calculation.md) - Different approaches to solving your model-->

docs/contribute.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Contributing to the Project
2+
3+
We warmly welcome contributions from the community! This guide will help you get started with contributing to our project.
4+
5+
## Development Setup
6+
1. Clone the repository `git clone https://github.com/flixOpt/flixopt.git`
7+
2. Install the development dependencies `pip install -editable .[dev, docs]`
8+
3. Run `pytest` and `ruff check .` to ensure your code passes all tests
9+
10+
## Documentation
11+
flixOpt uses [mkdocs](https://www.mkdocs.org/) to generate documentation. To preview the documentation locally, run `mkdocs serve` in the root directory.
12+
13+
## Helpful Commands
14+
- `mkdocs serve` to preview the documentation locally. Navigate to `http://127.0.0.1:8000/` to view the documentation.
15+
- `pytest` to run the test suite (You can also run the provided python script `run_all_test.py`)
16+
- `ruff check .` to run the linter
17+
- `ruff check . --fix` to automatically fix linting issues
18+
19+
---
20+
# Best practices
21+
22+
## Coding Guidelines
23+
24+
- Follow PEP 8 style guidelines
25+
- Write clear, commented code
26+
- Include type hints
27+
- Create or update tests for new functionality
28+
- Ensure 100% test coverage for new code
29+
30+
## Branches
31+
As we start to think flixOpt in **Releases**, we decided to introduce multiple **dev**-branches instead of only one:
32+
Following the **Semantic Versioning** guidelines, we introduced:
33+
- `next/patch`: This is where all pull requests for the next patch release (1.0.x) go.
34+
- `next/minor`: This is where all pull requests for the next minor release (1.x.0) go.
35+
- `next/major`: This is where all pull requests for the next major release (x.0.0) go.
36+
37+
Everything else remains in `feature/...`-branches.
38+
39+
## Pull requests
40+
Every feature or bugfix should be merged into one of the 3 [release branches](#branches), using **Squash and merge** or a regular **single commit**.
41+
At some point, `next/minor` or `next/major` will get merged into `main` using a regular **Merge** (not squash).
42+
*This ensures that Features are kept separate, and the `next/...`branches stay in synch with ``main`.*
43+
44+
## Releases
45+
As stated, we follow **Semantic Versioning**.
46+
Right after one of the 3 [release branches](#branches) is merged into main, a **Tag** should be added to the merge commit and pushed to the main branch. The tag has the form `v1.2.3`.
47+
With this tag, a release with **Release Notes** must be created.
48+
49+
*This is our current best practice*
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Minimal Example
2+
3+
```python
4+
{! ../examples/00_Minmal/minimal_example.py !}
5+
```

docs/examples/01-Basic Example.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Simple example
2+
3+
```python
4+
{! ../examples/01_Simple/simple_example.py !}
5+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Complex example
2+
This saves the results of a calculation to file and reloads them to analyze the results
3+
## Build the Model
4+
```python
5+
{! ../examples/02_Complex/complex_example.py !}
6+
```
7+
## Load the Results from file
8+
```python
9+
{! ../examples/02_Complex/complex_example_results.py !}
10+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Calculation Mode comparison
2+
**Note:** This example relies on time series data. You can find it in the `examples` folder of the flixOpt repository.
3+
```python
4+
{! ../examples/03_Calculation_types/example_calculation_types.py !}
5+
```

docs/getting-started.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Getting Started with flixOpt
2+
3+
This guide will help you install flixOpt, understand its basic concepts, and run your first optimization model.
4+
5+
## Installation
6+
7+
### Basic Installation
8+
9+
Install flixOpt directly into your environment using pip:
10+
11+
```bash
12+
pip install git+https://github.com/flixOpt/flixOpt.git
13+
```
14+
15+
This provides the core functionality with the HiGHS solver included.
16+
17+
### Full Installation
18+
19+
For all features including interactive network visualizations and time series aggregation:
20+
21+
```bash
22+
pip install "flixOpt[full] @ git+https://github.com/flixOpt/flixOpt.git"
23+
```
24+
25+
## Basic Workflow
26+
27+
Working with flixOpt follows a general pattern:
28+
29+
1. **Create a [`FlowSystem`][flixOpt.flow_system.FlowSystem]** with a time series
30+
2. **Define [`Effects`][flixOpt.effects.Effect]** (costs, emissions, etc.)
31+
3. **Define [`Buses`][flixOpt.elements.Bus]** as connection points in your system
32+
4. **Add [`Components`][flixOpt.components]** like converters, storage, sources/sinks with their Flows
33+
5. **Run [`Calculations`][flixOpt.calculation]** to optimize your system
34+
6. **Analyze [`Results`][flixOpt.results]** using built-in or external visualization tools
35+
36+
## Next Steps
37+
38+
Now that you've installed flixOpt and understand the basic workflow, you can:
39+
40+
- Learn about the [core concepts of flixOpt](concepts-and-math/index.md)
41+
- Explore some [examples](examples/index.md)
42+
- Check the [API reference](api-reference/index.md) for detailed documentation

0 commit comments

Comments
 (0)