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
Fix clustering expansion bugs and add ExtremeConfig validation (#590)
* Summary of Fixes
1. Fixed _interpolate_charge_state_segmented Bug (Critical)
File: flixopt/transform_accessor.py:1965-2043
The function was incorrectly decoding timestep_mapping using timesteps_per_cluster. For segmented systems, timestep_mapping encodes cluster * n_segments + segment_idx, so
this produced wrong cluster indices.
Fix: Compute original period index and position directly from timestep indices instead of decoding from timestep_mapping.
2. Implemented EXPAND_FIRST_TIMESTEP for Segmented Systems Only
File: flixopt/transform_accessor.py:2045-2100
Added _expand_first_timestep_only() method that places startup/shutdown events at the first timestep of each segment (not cluster).
Key design decisions:
- Segmented systems: Events placed at first timestep of each segment (timing within segment is lost)
- Non-segmented systems: Normal expansion preserves timing within cluster (no special handling needed)
3. Added Tests
- test_startup_shutdown_first_timestep_only: Verifies segmented systems place events at segment boundaries
- test_startup_timing_preserved_non_segmented: Verifies non-segmented systems preserve timing within clusters
4. Updated Docstrings
Clarified in expand() docstring that:
- Binary events in segmented systems go to first timestep of each segment
- Non-segmented systems preserve timing via normal expansion
* Summary of Fixes
1. Fixed _interpolate_charge_state_segmented Bug (Critical)
File: flixopt/transform_accessor.py:1965-2043
The function was incorrectly decoding timestep_mapping using timesteps_per_cluster. For segmented systems, timestep_mapping encodes cluster * n_segments + segment_idx, so
this produced wrong cluster indices.
Fix: Compute original period index and position directly from timestep indices instead of decoding from timestep_mapping.
2. Implemented EXPAND_FIRST_TIMESTEP for Segmented Systems Only
File: flixopt/transform_accessor.py:2045-2100
Added _expand_first_timestep_only() method that places startup/shutdown events at the first timestep of each segment (not cluster).
Key design decisions:
- Segmented systems: Events placed at first timestep of each segment (timing within segment is lost)
- Non-segmented systems: Normal expansion preserves timing within cluster (no special handling needed)
3. Added Tests
- test_startup_shutdown_first_timestep_only: Verifies segmented systems place events at segment boundaries
- test_startup_timing_preserved_non_segmented: Verifies non-segmented systems preserve timing within clusters
4. Updated Docstrings
Clarified in expand() docstring that:
- Binary events in segmented systems go to first timestep of each segment
- Non-segmented systems preserve timing via normal expansion
* Validate extremeconfig method to be "replace"
* The fix now properly handles variables with both time and period (or scenario) dimensions:
1. For each missing (period_label, scenario_label) key, it selects the specific period/scenario slice from the original variable using .sel(..., drop=True)
2. Then it slices and reshapes that specific slice
3. All slices in filled_slices now have consistent dimensions ['cluster', 'time'] + other_dims without 'period' or 'scenario' coordinates
This ensures all DataArrays being concatenated have the same structure. Can you try running your clustering code again?
* Update tsam dep
0 commit comments