Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
87820e8
Rename Calcualtion to optimization.py
FBumann Nov 20, 2025
01c8a2b
Rename new classes slightly
FBumann Nov 20, 2025
82e2295
Also rename results classes
FBumann Nov 20, 2025
9a7a962
FInalize port to new names
FBumann Nov 20, 2025
f80dad4
Add old methods
FBumann Nov 20, 2025
613148e
Udpate CHANGELOG.md
FBumann Nov 20, 2025
0cd3cd6
Temp
FBumann Nov 20, 2025
589c6a5
I've successfully renamed all aggregation-related classes and modul…
FBumann Nov 21, 2025
8be0c11
Bugfixes
FBumann Nov 21, 2025
14073a3
Use correct deprecation version removal
FBumann Nov 21, 2025
e32b637
Import fix
FBumann Nov 21, 2025
5a2c9f4
Improve docstrings and remove duplicate check
FBumann Nov 21, 2025
4fa73f5
Remove loguru usage
FBumann Nov 21, 2025
7488d56
Bugfix
FBumann Nov 22, 2025
6a41872
Move solve to Optimization class
FBumann Nov 22, 2025
9c217e1
1. ✅ Added validation for nr_of_previous_values in SegmentedOptimiz…
FBumann Nov 22, 2025
558f355
Update CHANGELOG.md
FBumann Nov 22, 2025
c458495
Update tests
FBumann Nov 22, 2025
3224e88
Update tests
FBumann Nov 22, 2025
091ee0b
Add setting logger level to SUCCESS directly
FBumann Nov 22, 2025
8635dd4
Remove warnings from examples
FBumann Nov 22, 2025
dac8412
Remove warnings from examples
FBumann Nov 22, 2025
dd3a485
Fix SUCCESS Level setting
FBumann Nov 22, 2025
90af29a
1. Exported SUCCESS_LEVEL Constant ✓
FBumann Nov 22, 2025
956bb63
Removed:
FBumann Nov 22, 2025
0a925f8
Fix singel line coloring
FBumann Nov 22, 2025
ad586fc
FIx single and multiline coloring
FBumann Nov 22, 2025
437b5a6
Add proper .modeled, .main_results and .summary to SegmentedOptimization
FBumann Nov 22, 2025
74a922f
Updaet CHANGELOG.md
FBumann Nov 22, 2025
4392c79
Implement Protocol
FBumann Nov 22, 2025
28d3a11
Add proper type hints
FBumann Nov 22, 2025
2f31189
Remove not needed hints
FBumann Nov 22, 2025
3babf6e
rename methods
FBumann Nov 22, 2025
ad92e52
rename calculation variables to optimization
FBumann Nov 22, 2025
b74a672
Fixed the _initialize_optimization_common call in SegmentedOptimizati…
FBumann Nov 22, 2025
44942cd
Make init more explicit
FBumann Nov 22, 2025
50c9a13
1. Fixed outdated docstring in SegmentedResults.setup_colors
FBumann Nov 22, 2025
be2ef11
Change assertions to proper Exceptions
FBumann Nov 22, 2025
02fc285
Updated Terminology in docs:
FBumann Nov 22, 2025
ff74f71
Add missing type hints and rename files mentioning claculation
FBumann Nov 22, 2025
c802563
renamed all the "aggregation" attributes and methods to "clustering" …
FBumann Nov 23, 2025
955d485
Improve naming in example
FBumann Nov 23, 2025
47fa938
Fix remaining mentions of Calculation
FBumann Nov 23, 2025
9d37d47
Imrpove docstring
FBumann Nov 23, 2025
68f722c
Improve conftest.py
FBumann Nov 23, 2025
7f55f56
Merge remote-tracking branch 'origin/main' into feature/rename-calcul…
FBumann Nov 23, 2025
5b5646f
Changed x-axis label from "Calculation type" to "Optimization type" for
FBumann Nov 23, 2025
936eae3
Fixed xarray boolean comparisons by adding .item() to convert DataAr…
FBumann Nov 23, 2025
d118f31
Updated TimeSeriesData class docstring from "with aggregation metadat…
FBumann Nov 23, 2025
2d8f217
Fix tests
FBumann Nov 23, 2025
55c59f1
removed the unused hours_per_timestep attribute from SegmentedResults…
FBumann Nov 23, 2025
2c4e169
Add early validation
FBumann Nov 23, 2025
8dac934
Remove not needed type hint
FBumann Nov 23, 2025
66615e9
Add guards against results accessing before modeling
FBumann Nov 23, 2025
c17b16c
Backward compatibility for legacy JSON key (lines 2128-2133):
FBumann Nov 23, 2025
8a93a7c
Guard against empty segment_results
FBumann Nov 23, 2025
6ed6dcd
Fix deprecation of flow_system parameter in results.py
FBumann Nov 23, 2025
d2c598f
Reuse SUCCESS_LEVEL constant
FBumann Nov 23, 2025
0f449c1
Typo
FBumann Nov 23, 2025
721a2bd
Typo
FBumann Nov 23, 2025
445e598
Revert docstring changes
FBumann Nov 23, 2025
562f965
Revert docstring changes
FBumann Nov 24, 2025
1532da5
Improve docstring
FBumann Nov 24, 2025
9563b39
Update CHANGELOG.md
FBumann Nov 24, 2025
056ecba
updated results.py to use the new naming scheme
FBumann Nov 24, 2025
4e4afb1
Further renamings
FBumann Nov 24, 2025
a6b8e31
Further renamings
FBumann Nov 24, 2025
10029b0
Rename CalculationResultsPaths to ResultsPaths
FBumann Nov 24, 2025
ba93cf7
Rename CalculationResultsPaths to ResultsPaths
FBumann Nov 24, 2025
1c2a6cf
Change folder.mkdir(parents=False to True
FBumann Nov 25, 2025
681b444
Temp
FBumann Nov 25, 2025
bbdbfcc
Synchronized folder creation across codebase to always use parents=Tr…
FBumann Nov 25, 2025
949fa3e
added overwrite protection to prevent accidentally overwriting Resul…
FBumann Nov 25, 2025
d39cdf6
Use unique names in tests
FBumann Nov 25, 2025
4b668f5
Improve logging message
FBumann Nov 25, 2025
ff858e6
Improve CHANGELOG.md
FBumann Nov 25, 2025
1105454
Improve CHANGELOG.md
FBumann Nov 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,46 @@ If upgrading from v2.x, see the [v3.0.0 release notes](https://github.com/flixOp
If upgrading from v2.x, see the [v3.0.0 release notes](https://github.com/flixOpt/flixOpt/releases/tag/v3.0.0) and [Migration Guide](https://flixopt.github.io/flixopt/latest/user-guide/migration-guide-v3/).

### ✨ Added
- `overwrite` parameter when saving results to file. If True, overwrite existing files.

### 💥 Breaking Changes

### ♻️ Changed

- Now creates the Results folder even i fparents didnt exist

### 🗑️ Deprecated

**Class and module renaming:**
- `FullCalculation` → `Optimization`
- `AggregatedCalculation` → `ClusteredOptimization`
- `SegmentedCalculation` → `SegmentedOptimization`
- `CalculationResults` → `Results`
- `SegmentedCalculationResults` → `SegmentedResults`
- `Aggregation` → `Clustering`
- `AggregationParameters` → `ClusteringParameters`
- `AggregationModel` → `ClusteringModel`
- Module: `calculation.py` → `optimization.py`
- Module: `aggregation.py` → `clustering.py`

Old names remain available with deprecation warnings (removed in v5.0.0).

### 🔥 Removed

### 🐛 Fixed

- Fixed `fix_sizes()` docstring/implementation inconsistency for optional `ds` parameter

### 🔒 Security

### 📦 Dependencies

### 📝 Docs

### 👷 Development
- Fixed `active_timesteps` type annotation to include `None`
- Fixed xarray truth-value ambiguity in `main_results` buses with excess filter
- Added validation for `nr_of_previous_values` in `SegmentedOptimization` to prevent silent indexing bugs

### 🚧 Known Issues

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ flow_system = fx.FlowSystem(timesteps)
flow_system.add_elements(buses, components, effects)

# 2. Create and solve
calculation = fx.FullCalculation("MyModel", flow_system)
calculation.solve()
optimization = fx.Optimization("MyModel", flow_system)
optimization.solve(fx.solvers.HighsSolver())

# 3. Analyze results
calculation.results.solution
optimization.results.solution
```

**Get started with real examples:**
Expand Down Expand Up @@ -90,8 +90,8 @@ boiler = fx.Boiler("Boiler", eta=0.9, ...)
**Multi-criteria optimization:** Model costs, emissions, resource use - any custom metric. Optimize single objectives or use weighted combinations and ε-constraints.
→ [Effects documentation](https://flixopt.github.io/flixopt/latest/user-guide/mathematical-notation/effects-penalty-objective/)

**Performance at any scale:** Choose calculation modes without changing your model - Full, Segmented, or Aggregated (using [TSAM](https://github.com/FZJ-IEK3-VSA/tsam)).
→ [Calculation modes](https://flixopt.github.io/flixopt/latest/api-reference/calculation/)
**Performance at any scale:** Choose optimization modes without changing your model - Optimization, SegmentedOptimization, or ClusteredOptimization (using [TSAM](https://github.com/FZJ-IEK3-VSA/tsam)).
→ [Optimization modes](https://flixopt.github.io/flixopt/latest/api-reference/optimization/)

**Built for reproducibility:** Self-contained NetCDF result files with complete model information. Load results months later - everything is preserved.
→ [Results documentation](https://flixopt.github.io/flixopt/latest/api-reference/results/)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Calculation Mode comparison
# Optimization Modes Comparison
**Note:** This example relies on time series data. You can find it in the `examples` folder of the FlixOpt repository.
```python
{! ../examples/03_Calculation_types/example_calculation_types.py !}
{! ../examples/03_Optimization_modes/example_optimization_modes.py !}
```
2 changes: 1 addition & 1 deletion docs/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ We work on improving this gallery. If you have something to share, please contac
1. [Minimal Example](00-Minimal Example.md) - The simplest possible FlixOpt model
2. [Simple Example](01-Basic Example.md) - A basic example with more features
3. [Complex Example](02-Complex Example.md) - A comprehensive example with result saving and loading
4. [Calculation Modes](03-Calculation Modes.md) - Comparison of different calculation modes
4. [Optimization Modes](03-Optimization Modes.md) - Comparison of different optimization modes
5. [Scenarios](04-Scenarios.md) - Working with scenarios in FlixOpt
6. [Two-stage Optimization](05-Two-stage-optimization.md) - Two-stage optimization approach
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Working with FlixOpt follows a general pattern:
2. **Define [`Effects`][flixopt.effects.Effect]** (costs, emissions, etc.)
3. **Define [`Buses`][flixopt.elements.Bus]** as connection points in your system
4. **Add [`Components`][flixopt.components]** like converters, storage, sources/sinks with their Flows
5. **Run [`Calculations`][flixopt.calculation]** to optimize your system
5. **Run [`Optimizations`][flixopt.optimization]** to optimize your system
6. **Analyze [`Results`][flixopt.results]** using built-in or external visualization tools

## Next Steps
Expand Down
30 changes: 15 additions & 15 deletions docs/user-guide/core-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,23 @@ This approach allows for multi-criteria optimization using both:
- **Weighted Sum Method**: Optimize a theoretical Effect which other Effects crosslink to
- **ε-constraint method**: Constrain effects to specific limits

### Calculation
### Optimization

A [`FlowSystem`][flixopt.flow_system.FlowSystem] can be converted to a Model and optimized by creating a [`Calculation`][flixopt.calculation.Calculation] from it.
A [`FlowSystem`][flixopt.flow_system.FlowSystem] can be converted to a Model and optimized by creating an [`Optimization`][flixopt.optimization.Optimization] from it.

FlixOpt offers different calculation modes:
FlixOpt offers different optimization modes:

- [`FullCalculation`][flixopt.calculation.FullCalculation] - Solves the entire problem at once
- [`SegmentedCalculation`][flixopt.calculation.SegmentedCalculation] - Solves the problem in segments (with optioinal overlap), improving performance for large problems
- [`AggregatedCalculation`][flixopt.calculation.AggregatedCalculation] - Uses typical periods to reduce computational requirements
- [`Optimization`][flixopt.optimization.Optimization] - Solves the entire problem at once
- [`SegmentedOptimization`][flixopt.optimization.SegmentedOptimization] - Solves the problem in segments (with optional overlap), improving performance for large problems
- [`ClusteredOptimization`][flixopt.optimization.ClusteredOptimization] - Uses typical periods to reduce computational requirements

### Results

The results of a calculation are stored in a [`CalculationResults`][flixopt.results.CalculationResults] object.
This object contains the solutions of the optimization as well as all information about the [`Calculation`][flixopt.calculation.Calculation] and the [`FlowSystem`][flixopt.flow_system.FlowSystem] it was created from.
The solution is stored as an `xarray.Dataset`, but can be accessed through their assotiated Component, Bus or Effect.
The results of an optimization are stored in a [`Results`][flixopt.results.Results] object.
This object contains the solutions of the optimization as well as all information about the [`Optimization`][flixopt.optimization.Optimization] and the [`FlowSystem`][flixopt.flow_system.FlowSystem] it was created from.
The solution is stored as an `xarray.Dataset`, but can be accessed through their associated Component, Bus or Effect.

This [`CalculationResults`][flixopt.results.CalculationResults] object can be saved to file and reloaded from file, allowing you to analyze the results anytime after the solve.
This [`Results`][flixopt.results.Results] object can be saved to file and reloaded from file, allowing you to analyze the results anytime after the solve.

## How These Concepts Work Together

Expand All @@ -128,12 +128,12 @@ The process of working with FlixOpt can be divided into 3 steps:
- Add
- [`FlowSystems`][flixopt.flow_system.FlowSystem] can also be loaded from a netCDF file*
2. Translate the model to a mathematical optimization problem
- Create a [`Calculation`][flixopt.calculation.Calculation] from your FlowSystem and choose a Solver
- ...The Calculation is translated internally to a mathematical optimization problem...
- Create an [`Optimization`][flixopt.optimization.Optimization] from your FlowSystem and choose a Solver
- ...The Optimization is translated internally to a mathematical optimization problem...
- ...and solved by the chosen solver.
3. Analyze the results
- The results are stored in a [`CalculationResults`][flixopt.results.CalculationResults] object
- This object can be saved to file and reloaded from file, retaining all information about the calculation
- The results are stored in a [`Results`][flixopt.results.Results] object
- This object can be saved to file and reloaded from file, retaining all information about the optimization
- As it contains the used [`FlowSystem`][flixopt.flow_system.FlowSystem], it fully documents all assumptions taken to create the results.

<figure markdown>
Expand All @@ -152,4 +152,4 @@ This allows to adjust your model to very specific requirements without loosing t
<!--- [FlowSystem](api/flow_system.md) - Time series and system organization-->
<!--- [Components](api/components.md) - Available component types and how to use them-->
<!--- [Effects](apieffects.md) - Costs, emissions, and other impacts-->
<!--- [Calculation Modes](api/calculation.md) - Different approaches to solving your model-->
<!--- [Optimization Modes](api/optimization.md) - Different approaches to solving your model-->
2 changes: 1 addition & 1 deletion docs/user-guide/mathematical-notation/dimensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ flow_system = fx.FlowSystem(
# [6.0, 4.0]] # 2040: 10 × [0.6, 0.4]
```

**Normalization:** Set `normalize_weights=False` in `Calculation` to turn of the normalization.
**Normalization:** Set `normalize_weights=False` in `Optimization` to turn off the normalization.

---

Expand Down
12 changes: 6 additions & 6 deletions docs/user-guide/migration-guide-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ Terminology changed and sharing system inverted: effects now "pull" shares.

---

### FlowSystem & Calculation
### FlowSystem & Optimization

| Change | Description |
|--------|-------------|
| **FlowSystem copying** | Each `Calculation` gets its own copy (independent) |
| **do_modeling() return** | Returns `Calculation` object (access model via `.model` property) |
| **FlowSystem copying** | Each `Optimization` gets its own copy (independent) |
| **do_modeling() return** | Returns `Optimization` object (access model via `.model` property) |
| **Storage arrays** | Arrays match timestep count (no extra element) |
| **Final charge state** | Use `relative_minimum_final_charge_state` / `relative_maximum_final_charge_state` |

Expand Down Expand Up @@ -135,7 +135,7 @@ Terminology changed and sharing system inverted: effects now "pull" shares.
| `agg_group` | `aggregation_group` |
| `agg_weight` | `aggregation_weight` |

??? abstract "Calculation"
??? abstract "Optimization"

| Old (v2.x) | New (v3.0.0) |
|------------|--------------|
Expand Down Expand Up @@ -207,7 +207,7 @@ Terminology changed and sharing system inverted: effects now "pull" shares.
| Issue | Solution |
|-------|----------|
| Effect shares not working | See [Effect System Redesign](#effect-system-redesign) |
| Storage dimensions wrong | See [FlowSystem & Calculation](#flowsystem-calculation) |
| Storage dimensions wrong | See [FlowSystem & Optimization](#flowsystem-optimization) |
| Bus assignment error | See [String Labels](#string-labels) |
| KeyError in results | See [Variable Names](#variable-names) |
| `AttributeError: model` | Rename `.model` → `.submodel` |
Expand All @@ -220,7 +220,7 @@ Terminology changed and sharing system inverted: effects now "pull" shares.
| Category | Tasks |
|----------|-------|
| **Install** | • `pip install --upgrade flixopt` |
| **Breaking changes** | • Update [effect sharing](#effect-system-redesign)<br>• Update [variable names](#variable-names)<br>• Update [string labels](#string-labels)<br>• Fix [storage arrays](#flowsystem-calculation)<br>• Update [Calculation API](#flowsystem-calculation)<br>• Update [class names](#other-changes) |
| **Breaking changes** | • Update [effect sharing](#effect-system-redesign)<br>• Update [variable names](#variable-names)<br>• Update [string labels](#string-labels)<br>• Fix [storage arrays](#flowsystem-optimization)<br>• Update [Optimization API](#flowsystem-optimization)<br>• Update [class names](#other-changes) |
| **Configuration** | • Enable [logging](#other-changes) if needed |
| **Deprecated** | • Update [deprecated parameters](#deprecated-parameters) (recommended) |
| **Testing** | • Test thoroughly<br>• Validate results match v2.x |
Expand Down
4 changes: 2 additions & 2 deletions examples/00_Minmal/minimal_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
),
)

calculation = fx.FullCalculation('Simulation1', flow_system).do_modeling().solve(fx.solvers.HighsSolver(0.01, 60))
calculation.results['Heat'].plot_node_balance()
optimization = fx.Optimization('Simulation1', flow_system).solve(fx.solvers.HighsSolver(0.01, 60))
optimization.results['Heat'].plot_node_balance()
20 changes: 10 additions & 10 deletions examples/01_Simple/simple_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,24 @@

# --- Define and Run Calculation ---
# Create a calculation object to model the Flow System
calculation = fx.FullCalculation(name='Sim1', flow_system=flow_system)
calculation.do_modeling() # Translate the model to a solvable form, creating equations and Variables
optimization = fx.Optimization(name='Sim1', flow_system=flow_system)
optimization.do_modeling() # Translate the model to a solvable form, creating equations and Variables

# --- Solve the Calculation and Save Results ---
calculation.solve(fx.solvers.HighsSolver(mip_gap=0, time_limit_seconds=30))
optimization.solve(fx.solvers.HighsSolver(mip_gap=0, time_limit_seconds=30))

# --- Analyze Results ---
# Colors are automatically assigned using default colormap
# Optional: Configure custom colors with
calculation.results.setup_colors()
calculation.results['Fernwärme'].plot_node_balance_pie()
calculation.results['Fernwärme'].plot_node_balance()
calculation.results['Storage'].plot_charge_state()
calculation.results.plot_heatmap('CHP(Q_th)|flow_rate')
optimization.results.setup_colors()
optimization.results['Fernwärme'].plot_node_balance_pie()
optimization.results['Fernwärme'].plot_node_balance()
optimization.results['Storage'].plot_charge_state()
optimization.results.plot_heatmap('CHP(Q_th)|flow_rate')

# Convert the results for the storage component to a dataframe and display
df = calculation.results['Storage'].node_balance_with_charge_state()
df = optimization.results['Storage'].node_balance_with_charge_state()
print(df)

# Save results to file for later usage
calculation.results.to_file()
optimization.results.to_file()
18 changes: 9 additions & 9 deletions examples/02_Complex/complex_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
check_penalty = False
excess_penalty = 1e5
use_chp_with_piecewise_conversion = True
time_indices = None # Define specific time steps for custom calculations, or use the entire series
time_indices = None # Define specific time steps for custom optimizations, or use the entire series

# --- Define Demand and Price Profiles ---
# Input data for electricity and heat demands, as well as electricity price
Expand Down Expand Up @@ -194,17 +194,17 @@
print(f'Network app requires extra dependencies: {e}')

# --- Solve FlowSystem ---
calculation = fx.FullCalculation('complex example', flow_system, time_indices)
calculation.do_modeling()
optimization = fx.Optimization('complex example', flow_system, time_indices)
optimization.do_modeling()

calculation.solve(fx.solvers.HighsSolver(0.01, 60))
optimization.solve(fx.solvers.HighsSolver(0.01, 60))

# --- Results ---
# You can analyze results directly or save them to file and reload them later.
calculation.results.to_file()
optimization.results.to_file()

# But let's plot some results anyway
calculation.results.plot_heatmap('BHKW2(Q_th)|flow_rate')
calculation.results['BHKW2'].plot_node_balance()
calculation.results['Speicher'].plot_charge_state()
calculation.results['Fernwärme'].plot_node_balance_pie()
optimization.results.plot_heatmap('BHKW2(Q_th)|flow_rate')
optimization.results['BHKW2'].plot_node_balance()
optimization.results['Speicher'].plot_charge_state()
optimization.results['Fernwärme'].plot_node_balance_pie()
2 changes: 1 addition & 1 deletion examples/02_Complex/complex_example_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# --- Load Results ---
try:
results = fx.results.CalculationResults.from_file('results', 'complex example')
results = fx.results.Results.from_file('results', 'complex example')
except FileNotFoundError as e:
raise FileNotFoundError(
f"Results file not found in the specified directory ('results'). "
Expand Down
Loading