Commit 4af7ee4
authored
Feature/rename on off to status (#500)
* Perfect! Here's the **final complete renaming table with Option A**:
## Parameters Class (`OnOffParameters` → `StatusParameters`)
| Current Name | Recommended Name | Rationale |
|--------------|------------------|-----------|
| `OnOffParameters` | **`StatusParameters`** | Aligns with PyPSA, clearer semantics |
| `effects_per_switch_on` | **`effects_per_startup`** | Standard UC terminology |
| `effects_per_running_hour` | **`effects_per_active_hour`** | Clear, concise, matches "active" state |
| `on_hours_total_min` | **`active_hours_min`** | Total (not consecutive) active hours |
| `on_hours_total_max` | **`active_hours_max`** | Total (not consecutive) active hours |
| `consecutive_on_hours_min` | **`min_uptime`** | Standard UC term (consecutive) |
| `consecutive_on_hours_max` | **`max_uptime`** | Standard UC term (consecutive) |
| `consecutive_off_hours_min` | **`min_downtime`** | Standard UC term (consecutive) |
| `consecutive_off_hours_max` | **`max_downtime`** | Standard UC term (consecutive) |
| `switch_on_total_max` | **`startup_limit`** | Clearer intent, matches "startup" |
| `force_switch_on` | **`force_startup_tracking`** | More explicit about what is forced |
## Model Class (`OnOffModel` → `StatusModel`)
### Class Name
| Current Name | Recommended Name |
|--------------|------------------|
| `OnOffModel` | **`StatusModel`** |
### Constructor Parameters
| Current Name | Recommended Name | Rationale |
|--------------|------------------|-----------|
| `on_variable` | **`status`** | Aligns with PyPSA and literature |
| `previous_states` | **`previous_status`** | Consistency with status variable |
### Variables (short_name in add_variables/expression_tracking_variable)
| Current Name | Recommended Name | Type | Notes |
|--------------|------------------|------|-------|
| `self.on` | **`self.status`** | Input variable | Main binary state variable |
| `'off'` | **Remove variable** | Binary variable | Replace with expression `1 - status` |
| `'switch\|on'` | **`'startup'`** | Binary variable | Startup event indicator |
| `'switch\|off'` | **`'shutdown'`** | Binary variable | Shutdown event indicator |
| `'switch\|count'` | **`'startup_count'`** | Integer variable | Number of startups |
| `'on_hours_total'` | **`'active_hours'`** | Continuous variable | Total active duration |
| `'consecutive_on_hours'` | **`'uptime'`** | Continuous variable | Consecutive active hours |
| `'consecutive_off_hours'` | **`'downtime'`** | Continuous variable | Consecutive inactive hours |
### Properties
| Current Name | Recommended Name | Returns | Meaning |
|--------------|------------------|---------|---------|
| `on_hours_total` | **`active_hours`** | `linopy.Variable` | Total active hours |
| `off` | **Remove property** | — | Use `1 - status` expression |
| `switch_on` | **`startup`** | `linopy.Variable \| None` | Startup events |
| `switch_off` | **`shutdown`** | `linopy.Variable \| None` | Shutdown events |
| `switch_on_nr` | **`startup_count`** | `linopy.Variable \| None` | Number of startups |
| `consecutive_on_hours` | **`uptime`** | `linopy.Variable \| None` | Consecutive active hours |
| `consecutive_off_hours` | **`downtime`** | `linopy.Variable \| None` | Consecutive inactive hours |
### Internal Methods
| Current Name | Recommended Name |
|--------------|------------------|
| `_get_previous_on_duration()` | **`_get_previous_uptime()`** |
| `_get_previous_off_duration()` | **`_get_previous_downtime()`** |
### Internal Properties/Flags (in parameters)
| Current Name | Recommended Name |
|--------------|------------------|
| `use_off` | **Remove** (use expression instead) |
| `use_switch_on` | **`use_startup_tracking`** |
| `use_consecutive_on_hours` | **`use_uptime_tracking`** |
| `use_consecutive_off_hours` | **`use_downtime_tracking`** |
## Constraint Names (short_name in add_constraints)
| Current Name | Recommended Name |
|--------------|------------------|
| `'complementary'` | **Remove** (no off variable) |
| `'on_hours_total'` | **`'active_hours'`** |
| `'switch\|on'`, `'switch\|off'` | **`'startup'`, `'shutdown'`** |
| `'switch\|count'` | **`'startup_count'`** |
| `'consecutive_on_hours'` | **`'uptime'`** |
| `'consecutive_off_hours'` | **`'downtime'`** |
## Complete Terminology Summary (Option A)
**State:**
- `status` (binary): 1 = active, 0 = inactive
**Events:**
- `startup` (binary): transition from inactive to active
- `shutdown` (binary): transition from active to inactive
**Durations:**
- `active_hours` (continuous): **total** hours in active state across time horizon
- `uptime` (continuous): **consecutive** hours currently active (UC standard)
- `downtime` (continuous): **consecutive** hours currently inactive (UC standard)
**Parameter Bounds:**
- `active_hours_min/max`: limits on **total** active hours
- `min_uptime/max_uptime`: limits on **consecutive** active hours (UC standard)
- `min_downtime/max_downtime`: limits on **consecutive** inactive hours (UC standard)
- `startup_limit`: maximum number of startup events
**Effects:**
- `effects_per_startup`: costs/impacts per startup event
- `effects_per_active_hour`: costs/impacts per active hour
This aligns perfectly with PyPSA and the unit commitment literature! 🎯
* Refactor tests and examples
* Refactor tests and examples
* Update CHANGELOG.md
* Python Docstrings Updated:
1. interface.py - Module docstring now references "Status decisions"
2. components.py - Updated all docstrings:
- status_parameters parameter descriptions
- Example code updated with new parameter names (effects_per_startup, min_uptime, startup_limit)
- Fixed incorrect "OnOff feature" docstring to "Investment feature"
- Updated TODO comment to reference StatusParameters
3. linear_converters.py - All docstrings updated:
- Import statement updated to StatusParameters
- All parameter descriptions updated
- All example code updated with new terminology
4. flow_system.py - Updated references from "consecutive_on_hours" to "uptime and downtime" and on_off_parameters to status_parameters
5. modeling.py - Updated docstring from "switch-on/off variables" to "state transition constraints for binary switching variables"
Documentation Markdown Files Updated:
1. Flow.md - All references updated:
- Links to StatusParameters
- "on/off state" → "active/inactive state"
- Parameter names updated
2. StatusParameters.md (renamed from OnOffParameters.md) - Comprehensive updates:
- Title changed to "StatusParameters"
- All terminology updated: on/off → active/inactive
- Mathematical notation updated: s^on/s^off → s^startup/s^shutdown
- Duration variables: d^on/d^off → d^uptime/d^downtime
- Parameter names updated in all examples
- All Python code examples updated with new API
3. Other modeling pattern docs - Updated all references to StatusParameters and active/inactive terminology
4. mkdocs.yml - Navigation updated to reference StatusParameters.md
All docstrings and documentation now consistently use the new Status terminology aligned with PyPSA and unit commitment standards!
* Update remaining mentions of old parameters
* ⏺ Perfect! I've addressed all the actionable review comments:
Changes Made:
1. Fixed error message in modeling.py
- Corrected ModelingPrimitives.state_transition_bounds() → BoundingPatterns.state_transition_bounds() in error message (flixopt/modeling.py:591)
2. Fixed Transmission type hint (flixopt/components.py:667)
- Changed status_parameters: StatusParameters = None → status_parameters: StatusParameters | None = None
3. Fixed absolute_losses=0 edge case (flixopt/components.py:768)
- Added np.any(self.element.absolute_losses != 0) check in create_transmission_equation to match the initialization logic
- This prevents AttributeError when absolute_losses is explicitly set to 0
4. Updated test assertion messages (tests/test_component.py)
- Changed "On does not work properly" → "Status does not work properly"
5. Fixed effects_per_startup type (examples/02_Complex/complex_example.py)
- Changed scalar effects_per_startup=0.01 → dict effects_per_startup={Costs.label: 0.01} in all 3 occurrences
- Now consistent with the StatusParameters API which expects a dict mapping effect names to values
6. Updated test_functional.py docstring
- Removed reference to non-existent TestStatus class
- Updated to accurately describe the status-related test functions
7. Consistent unbounded upper bounds (flixopt/features.py:191)
- Changed np.inf → None for unbounded active_hours_max
- Now consistent with FlowModel's total_flow_hours pattern
All changes maintain backward compatibility and align with the codebase's existing patterns. The documentation in index.md was already correct (BoundingPatterns is
the right class for state_transition_bounds).
* Changes Made:
1. CHANGELOG.md - Fixed parameter rename documentation (lines 89-90)
- Changed incorrect status_parameters → status_parameters
- To correct: on_off_parameters → status_parameters
2. CHANGELOG.md - Removed duplicate logger warning (line 803 in v2.1.0)
- Removed duplicate entry that was already documented in v2.0.1
- Fixed v2.0.1 entry to say on_off_parameters (the name at that time)
3. StatusParameters.md - Aligned flow bounds formulation (line 229)
- Updated summary to include max(ε, rel_lower) like the main text
- Now consistent: s(t) · P · max(ε, rel_lower) ≤ p(t) ≤ s(t) · P · rel_upper
4. features.py - Narrowed previous_status type hint (line 155)
- Changed from Numeric_TPS | None to xr.DataArray | None
- Added import xarray as xr (line 12)
- This accurately reflects that _get_previous_uptime() and _get_previous_downtime() use xarray APIs
All changes are verified to compile correctly and maintain consistency with the codebase patterns!
* Fixed Issues
1. Constraint naming in tests (tests/test_component.py:126-127, 158, 168,
338, 348):
- Updated test expectations from 'TestComponent|on|lb' and
'TestComponent|on|ub' to 'TestComponent|status|lb' and
'TestComponent|status|ub' to match the actual constraint names
2. Added 'off' property to StatusModel (flixopt/features.py:284-287):
- Added a new property that returns 1 - self.status for backward
compatibility with tests expecting an off attribute
3. Fixed deprecated parameter name (tests/test_functional.py:435):
- Changed force_switch_on=True to force_startup_tracking=True in
StatusParameters
4. Fixed property name (tests/test_functional.py:466):
- Changed switch_off to shutdown to match the actual property name in
StatusModel
* Delete mistakingly added files
* Delete mistakingly added files
* Final touches
* Final touches
* Replace off with inactive
* Rename low level parameetrs as well:
switch_on -> activate
switch_off -> deactivate
* Rename low level parameetrs as well:
switch_on -> activate
switch_off -> deactivate
state_variable -> state
* Rename low level parameetrs as well:
switch_on -> activate
switch_off -> deactivate
state_variable -> state
* Docstring Improvements Summary
✅ All Parameters Now Documented
Each primitive now has complete parameter documentation with:
- Clear description of what each parameter does
- Type expectations
- Default values where applicable
✅ Focused on Math & Parameters
Removed:
- Excessive examples at low level
- Use case lists that belong at higher levels
Enhanced:
- Mathematical formulations (using proper · symbol for multiplication)
- Clear behavior descriptions
- Precise return value documentation
Updated Functions:
ModelingPrimitives:
1. expression_tracking_variable
- All 6 parameters documented
- Clear math formulation
2. consecutive_duration_tracking
- All 9 parameters documented
- Explained Big-M value
- Clear what constraints are returned
3. mutual_exclusivity_constraint
- All 4 parameters documented
- Simplified, focused on math
BoundingPatterns:
4. basic_bounds
- All 4 parameters documented
- Concise formulation
5. bounds_with_state
- All 5 parameters documented
- Explained epsilon (ε) usage
6. scaled_bounds
- All 5 parameters documented
- Clear scaling relationship
7. scaled_bounds_with_state
- All 7 parameters documented
- Explained Big-M formulation
8. state_transition_bounds
- All 7 parameters documented
- Removed verbose examples, kept math focus
9. continuous_transition_bounds
- All 8 parameters documented
- Clear Big-M constraint explanation
Result
✅ All parameters documented
✅ Math-focused docstrings
✅ Consistent format across all primitives
✅ Tests still passing
The modeling primitives now have professional, complete documentation!
* Update docs
* Add missing type hints
* Fix bullet points
* Fix bullet points
* Re-apply changes from main
* Bugfix: Usage of old on_off_parameters
* Update CHANGELOG.md
* Update CHANGELOG.md
* Update CHANGELOG.md
* Fix typos
* Improve flagging of wether to create inactive varaible
* Improve default upper bound of active_hours
* Bugfix self._model.hours_per_step.sum('time').item() with scenarios/periods
* Fix test
* FIx names
* pdate the test assertions to expect upper=total_hours instead of upper=inf when active_hours_max is not
specified
* Empty
* Trigger CI
* Fix test
* Triggger CI
* Summary of Fixes
1. Return type annotation for consecutive_duration_tracking (flixopt/modeling.py:255):
- Changed from tuple[linopy.Variable, tuple[linopy.Constraint, linopy.Constraint, linopy.Constraint]]
- To tuple[dict[str, linopy.Variable], dict[str, linopy.Constraint]] to match the actual return value
2. Clarified inactive property docstring (flixopt/features.py:284-291):
- Replaced the confusing "deprecated" note with a clear explanation that:
- The variable is only created when downtime tracking is enabled
- Users should prefer 1 - status expression for general use
3. Fixed _get_previous_uptime docstring (flixopt/features.py:318-322):
- Clarified that it returns 0 when no previous status is provided (assumes previously inactive)
4. Fixed _get_previous_downtime docstring (flixopt/features.py:329-333):
- Clarified that it returns one timestep duration when no previous status is provided (assumes previously inactive)
5. No action needed for effects_per_startup without use_startup_tracking:
- Verified that use_startup_tracking already returns True when effects_per_startup has values (line 1258 in interface.py), so this is already
handled correctly
6. Test fixes (tests/test_flow.py):
- Updated three test assertions to use model.hours_per_step.sum('time') as the expected upper bound for active_hours when active_hours_max is
not specified
* Trigger CI1 parent 658d410 commit 4af7ee4
37 files changed
Lines changed: 1413 additions & 1261 deletions
File tree
- .github/workflows
- docs/user-guide
- mathematical-notation
- elements
- features
- modeling-patterns
- recipes
- examples
- 02_Complex
- 03_Optimization_modes
- 04_Scenarios
- 05_Two-stage-optimization
- flixopt
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
56 | | - | |
| 54 | + | |
57 | 55 | | |
58 | 56 | | |
59 | 57 | | |
60 | 58 | | |
61 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
62 | 124 | | |
63 | 125 | | |
64 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
260 | 261 | | |
261 | 262 | | |
262 | 263 | | |
| 264 | + | |
263 | 265 | | |
264 | 266 | | |
265 | 267 | | |
| |||
280 | 282 | | |
281 | 283 | | |
282 | 284 | | |
| 285 | + | |
283 | 286 | | |
284 | 287 | | |
285 | 288 | | |
| |||
295 | 298 | | |
296 | 299 | | |
297 | 300 | | |
| 301 | + | |
298 | 302 | | |
299 | 303 | | |
300 | 304 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | | - | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
59 | | - | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
| 85 | + | |
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
| |||
99 | 102 | | |
100 | 103 | | |
101 | 104 | | |
| 105 | + | |
102 | 106 | | |
103 | 107 | | |
104 | 108 | | |
| |||
123 | 127 | | |
124 | 128 | | |
125 | 129 | | |
| 130 | + | |
126 | 131 | | |
127 | 132 | | |
128 | 133 | | |
| |||
146 | 151 | | |
147 | 152 | | |
148 | 153 | | |
| 154 | + | |
149 | 155 | | |
150 | 156 | | |
151 | 157 | | |
| |||
210 | 216 | | |
211 | 217 | | |
212 | 218 | | |
| 219 | + | |
213 | 220 | | |
214 | 221 | | |
215 | 222 | | |
| |||
226 | 233 | | |
227 | 234 | | |
228 | 235 | | |
| 236 | + | |
229 | 237 | | |
230 | 238 | | |
231 | 239 | | |
| |||
0 commit comments