You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add weight_of_last_period to flowsystem
* Add weights per effect and move normalization
* Weighted Sum Constraints Over All Periods have been fully implemented for both Effects and Flows:
Effects
- Renamed parameters: minimum_total → minimum_total_per_period, maximum_total → maximum_total_per_period
- New parameters: minimum and maximum for weighted sum across ALL periods
- Effect-specific weights: Effects can override FlowSystem weights (e.g., for discounting in costs vs equal weighting for CO2)
- Backward compatibility: Deprecation wrappers ensure existing code continues to work
Flows
- Renamed parameters: flow_hours_total_min/max → flow_hours_per_period_min/max
- New parameters: total_flow_hours_min/max for weighted sum across ALL periods
- Uses FlowSystem period weights for weighting
- Backward compatibility: Deprecation wrappers for old parameter names
Test Results
- 616/616 tests passing - no regressions introduced
- All existing functionality preserved
- Weighted sums respect period weights (auto-derived from period index or user-specified)
The implementation is production-ready and maintains full backward compatibility with existing code.
* Fixed a critical bug in /Users/felix/PycharmProjects/flixopt_719231/flixopt/structure.py:218-228 where the FlowSystemModel.weights property
wasn't normalizing weights despite its docstring claiming it would. The property now correctly normalizes weights to sum to 1 when
normalize_weights=True.
* Successfully refactored 11 parameter names across the codebase using the _over_periods suffix for weighted sums across all periods:
Effects (4 parameters):
- minimum_total_per_period → minimum_total
- maximum_total_per_period → maximum_total
- minimum → minimum_over_periods
- maximum → maximum_over_periods
Flows (4 parameters):
- flow_hours_per_period_max → flow_hours_max
- flow_hours_per_period_min → flow_hours_min
- total_flow_hours_max → flow_hours_max_over_periods
- total_flow_hours_min → flow_hours_min_over_periods
OnOffParameters (3 parameters):
- on_hours_total_min → on_hours_min
- on_hours_total_max → on_hours_max
- switch_on_total_max → switch_on_max
* Cahneglog
* Fix CHANGELOG.md
* 1. Critical Bug Fix - structure.py:219-229
- Fixed weights property normalization to handle scalars/lists properly
- Added zero-sum guard to prevent division by zero
- Now always aligns weights to model coords before normalizing
2. Documentation - flow_system.py
- Added documentation for the weight_of_last_period parameter in the FlowSystem class docstring
3. Code Quality - interface.py
- Refactored deprecated kwargs handling to use instance method instead of awkward static call pattern
- Removed unnecessary import and cleaner implementation
4. Parameter Name Updates - Test Files
Updated deprecated parameter names in all test files:
- tests/test_scenarios.py
- tests/test_functional.py
- tests/conftest.py
- tests/test_flow.py
- tests/test_linear_converter.py
5. Parameter Name Updates - Documentation
Updated parameter names in:
- docs/user-guide/mathematical-notation/features/OnOffParameters.md
6. Parameter Name Updates - Examples
Updated parameter names in:
- examples/02_Complex/complex_example.py
7. Enhanced CHANGELOG.md
Added comprehensive migration guidance including:
- Clear explanation of weighting behavior for _over_periods constraints
- Concrete example showing per-period vs over-periods differences
- Removal timeline (version 4.0.0) for deprecated parameters
- Simple migration instructions
All deprecated parameters:
- on_hours_total_min → on_hours_min
- on_hours_total_max → on_hours_max
- switch_on_total_max → switch_on_max
- flow_hours_total_min → flow_hours_min
- flow_hours_total_max → flow_hours_max
The codebase is now fully updated with consistent naming, proper documentation, and backward compatibility maintained through deprecation warnings!
* 1. Critical Bug Fix - structure.py:219-229
- Fixed weights property normalization to handle scalars/lists properly
- Added zero-sum guard to prevent division by zero
- Now always aligns weights to model coords before normalizing
2. Documentation - flow_system.py
- Added documentation for the weight_of_last_period parameter in the FlowSystem class docstring
3. Code Quality - interface.py
- Refactored deprecated kwargs handling to use instance method instead of awkward static call pattern
- Removed unnecessary import and cleaner implementation
4. Parameter Name Updates - Test Files
Updated deprecated parameter names in all test files:
- tests/test_scenarios.py
- tests/test_functional.py
- tests/conftest.py
- tests/test_flow.py
- tests/test_linear_converter.py
5. Parameter Name Updates - Documentation
Updated parameter names in:
- docs/user-guide/mathematical-notation/features/OnOffParameters.md
6. Parameter Name Updates - Examples
Updated parameter names in:
- examples/02_Complex/complex_example.py
7. Enhanced CHANGELOG.md
Added comprehensive migration guidance including:
- Clear explanation of weighting behavior for _over_periods constraints
- Concrete example showing per-period vs over-periods differences
- Removal timeline (version 4.0.0) for deprecated parameters
- Simple migration instructions
All deprecated parameters:
- on_hours_total_min → on_hours_min
- on_hours_total_max → on_hours_max
- switch_on_total_max → switch_on_max
- flow_hours_total_min → flow_hours_min
- flow_hours_total_max → flow_hours_max
The codebase is now fully updated with consistent naming, proper documentation, and backward compatibility maintained through deprecation warnings!
* Added single-period validation in _create_periods_with_extra():
* Added dimension validation for flow_hours constraints
* Fixed the DataArray boolean context
* Remove intermediate parameters that need no deprecation
* Remove intermediate parameters that need no deprecation
* Update CHANGELOG.md
* Fix weighting per period in Flows
* Add type hints and fallback for weights = None
* Imrove weight computation in Effects
* Improve objectove weight handling
* Add tests
* Typos
* Add zero-sum guard to objective_weights property to prevent silent NaN/inf corruption
* Guard over‑periods constraint when no period dimension is present.
* Fit fallback weight to dims
* Improve weight handling.
* Typos and updates
* Update CHANGELOG.md
* Update tests
* Improve handling of scenario weights
* Improve docs
* Typos
* Rename in tests
* Fix tests
* Use setter for scenario_weights
* Revert test changes
Copy file name to clipboardExpand all lines: CHANGELOG.md
+89-7Lines changed: 89 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,18 +51,67 @@ If upgrading from v2.x, see the [v3.0.0 release notes](https://github.com/flixOp
51
51
52
52
## [Unreleased] - ????-??-??
53
53
54
-
**Summary**: Renaming parameters in Linear Transformers for readability & Internal architecture improvements to simplify FlowSystem-Element coupling and eliminate circular dependencies. Old parameters till work but emmit warnings.
54
+
**Summary**: Renaming parameters in Linear Transformers for readability (old parameters still work but emit warnings), new bounds for weighted sums over all periods for effects and flow hours, and refactored weights handling to fix `.sel()` issues with periods.
55
55
56
56
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/).
57
57
58
58
### ✨ Added
59
+
- **Internal period weight computation**: `FlowSystem` now automatically computes `period_weights` from the period index (similar to `hours_per_timestep` for time dimension), ensuring weights are always consistent with the actual periods
60
+
61
+
- **New constraint parameters for sum across all periods**:
62
+
- `Effect`: Added `minimum_over_periods` and `maximum_over_periods` for weighted sum constraints across all periods (complements existing per-period `minimum_total`/`maximum_total`)
63
+
- `Flow`: Added `flow_hours_max_over_periods` and `flow_hours_min_over_periods` for weighted sum constraints across all periods
64
+
65
+
**Important**:
66
+
- Constraints with the `_over_periods` suffix compute weighted sums across all periods using the **raw** weights from period durations (or user-specified weights). These constraints always use unnormalized weights.
67
+
- The `normalize_weights` parameter (in `Calculation` or `FlowSystem.create_model()`) only affects the objective function, not the `_over_periods` constraints.
68
+
- Per-period constraints (without the suffix) apply separately to each individual period.
69
+
70
+
**Example**:
71
+
```python
72
+
# Per-period constraint: limits apply to EACH period individually
73
+
# With periods=[2020, 2030, 2040], this creates 3 separate constraints
74
+
effect = fx.Effect('costs', maximum_total=1000) # ≤1000 in 2020 AND ≤1000 in 2030 AND ≤1000 in 2040
75
+
76
+
# Over-periods constraint: limits apply to WEIGHTED SUM across ALL periods
77
+
# With periods=[2020, 2030, 2040] (auto-derived weights: [10, 10, 10] from 10-year intervals)
# Note: If normalize_weights=True, the objective uses normalized weights [0.33, 0.33, 0.33],
81
+
# but the constraint above still uses raw weights [10, 10, 10]
82
+
```
83
+
59
84
- **Auto-modeling**: `Calculation.solve()` now automatically calls `do_modeling()` if not already done, making the explicit `do_modeling()` call optional for simpler workflows
60
-
- **System validation**: Added `_validate_system_integrity()` to validate cross-element references (e.g., Flow.bus) immediately after transformation, providing clearer error messages
61
-
- **Element registration validation**: Added checks to prevent elements from being assigned to multiple FlowSystems simultaneously
62
-
- **Helper methods in Interface base class**: Added `_fit_coords()` and `_fit_effect_coords()` convenience wrappers for cleaner data transformation code
63
-
- **FlowSystem property in Interface**: Added `flow_system` property to access the linked FlowSystem with clear error messages if not yet linked
85
+
86
+
### 💥 Breaking Changes
87
+
- **FlowSystem weights parameter renamed**: The `weights` parameter in `FlowSystem.__init__()` has been renamed to `scenario_weights` to clarify that it only accepts scenario dimension weights (not period × scenario)
88
+
- Period weights are now **always computed internally** from the period index (similar to `hours_per_timestep` for time)
89
+
- The combined `weights` (period × scenario) are computed automatically by multiplying `period_weights × scenario_weights`
90
+
- only scenario_weights are normalized in the objective function
**Note**: If you were previously passing period × scenario weights to `weights`, you now need to:
105
+
1. Pass only scenario weights to `scenario_weights`
106
+
2. Period weights will be computed automatically from your `periods` index
64
107
65
108
### ♻️ Changed
109
+
- **Period weights now computed from period index**: FlowSystem now computes `period_weights` automatically from the period index (using period intervals/differences), making weight handling consistent with `hours_per_timestep` for time dimension
110
+
- Added `_update_period_metadata()` method (analogous to `_update_time_metadata()`) to recalculate weights when periods are selected
111
+
- Period weights are stored separately in `FlowSystem.period_weights` (1D array with 'period' dimension)
112
+
- Scenario weights are stored in `FlowSystem.scenario_weights` (1D array with 'scenario' dimension)
113
+
- Combined weights `FlowSystem.weights` (2D array with 'period' and 'scenario' dimensions) are computed via `_compute_weights()` method
114
+
66
115
- **Refactored FlowSystem-Element coupling**:
67
116
- Introduced `_set_flow_system()` method in Interface base class to propagate FlowSystem reference to nested Interface objects
68
117
- Each Interface subclass now explicitly propagates the reference to its nested interfaces (e.g., Component → OnOffParameters, Flow → InvestParameters)
@@ -83,19 +132,48 @@ If upgrading from v2.x, see the [v3.0.0 release notes](https://github.com/flixOp
- **Old parameter names in `linear_converters.py`**: The following parameter names are now deprecated and accessible as properties/kwargs that emit `DeprecationWarning`. They will be removed in v4.0.0:
**Migration**: Simply rename parameters by removing `_total` from the middle:
165
+
- `flow_hours_total_max` → `flow_hours_max`
166
+
- `on_hours_total_min` → `on_hours_min`
167
+
- `switch_on_total_max` → `switch_on_max`
168
+
169
+
All deprecated parameter names continue to work with deprecation warnings for backward compatibility. **Deprecated names will be removed in version 4.0.0.** Please update your code to use the new parameter names. Additional property aliases have been added internally to handle various naming variations that may have been used.
170
+
171
+
98
172
### 🐛 Fixed
173
+
- **Fixed weights not recalculating when using `.sel()` on periods**: `FlowSystem.sel()` and `FlowSystem.isel()` now correctly recalculate `period_weights` and `weights` when selecting a subset of periods (previously weights would be incorrectly sliced instead of recomputed from the new period index)
174
+
- Added `_update_period_metadata()` call in `_dataset_sel()` and `_dataset_isel()` to ensure weights stay consistent with selected periods
175
+
- This matches the existing behavior for time dimension where `hours_per_timestep` is recalculated on selection
176
+
99
177
- Fixed inconsistent argument passing in `_fit_effect_coords()` - standardized all calls to use named arguments (`prefix=`, `effect_values=`, `suffix=`) instead of mix of positional and named arguments
100
178
- Fixed `check_bounds` function in `linear_converters.py` to normalize array inputs before comparisons, ensuring correct boundary checks with DataFrames, Series, and other array-like types
101
179
@@ -104,6 +182,10 @@ If upgrading from v2.x, see the [v3.0.0 release notes](https://github.com/flixOp
104
182
- Added comprehensive docstrings to `_do_modeling()` methods explaining the pattern: "Create variables, constraints, and nested submodels"
105
183
- Added missing type hints throughout the codebase
106
184
- Improved code organization by making FlowSystem reference propagation explicit and traceable
185
+
- **System validation**: Added `_validate_system_integrity()` to validate cross-element references (e.g., Flow.bus) immediately after transformation, providing clearer error messages
186
+
- **Element registration validation**: Added checks to prevent elements from being assigned to multiple FlowSystems simultaneously
187
+
- **Helper methods in Interface base class**: Added `_fit_coords()` and `_fit_effect_coords()` convenience wrappers for cleaner data transformation code
188
+
- **FlowSystem property in Interface**: Added `flow_system` property to access the linked FlowSystem with clear error messages if not yet linked
0 commit comments