Skip to content

Conversation

@FBumann
Copy link
Member

@FBumann FBumann commented Dec 27, 2025

Description

Improve the handling of Status in clustered Models

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Code refactoring

Related Issues

Closes #(issue number)

Testing

  • I have tested my changes
  • Existing tests still pass

Checklist

  • My code follows the project style
  • I have updated documentation if needed
  • I have added tests for new functionality (if applicable)

Summary by CodeRabbit

  • New Features

    • Added cluster_mode parameter with 'relaxed' and 'cyclic' options for clustered system modeling.
  • Enhancements

    • Improved startup/shutdown handling with relaxed mode for systems without previous status data.
    • Added cyclic constraint enforcement to maintain consistent system status at cycle boundaries.

✏️ Tip: You can customize this high-level summary in your review settings.

  Summary of simplification:

  1. Added clusters: pd.Index | None = None parameter to constructor (like periods, scenarios)
  2. Simplified coords property - just adds cluster if self.clusters is not None
  3. Simplified _use_true_cluster_dims → return self.clusters is not None
  4. Simplified _cluster_n_clusters → return len(self.clusters)
  5. Simplified _cluster_timesteps_per_cluster → return len(self.timesteps)
  6. Simplified _cluster_time_coords → return self.timesteps
  7. Simplified from_dataset - just uses ds.indexes.get('cluster') and ds.indexes['time']
  8. Simplified to_dataset - uses self.clusters directly
  9. Removed all _cluster_info and _clustered_data handling

  The cluster dimension is now treated just like period and scenario - simply another dimension in the coordinate system. The code is much cleaner and more consistent.
  Final Design

  StatusParameters.cluster_mode with two options:
  - 'relaxed' (default): No constraint at t=0, no cyclic constraint. Prevents phantom startups.
  - 'cyclic': No constraint at t=0, but status[0] == status[-1]. For daily cycling patterns.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 27, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The changes introduce a new cluster_mode parameter to StatusParameters and InvestParameters with values 'relaxed' or 'cyclic', enabling relaxed mode where previous state and duration values can be None. Modeling logic now conditionally applies constraints based on this mode, and a cyclic constraint enforcement method is introduced for clustered systems.

Changes

Cohort / File(s) Summary
Cluster Mode Parameter Addition
flixopt/interface.py
Added cluster_mode: Literal['relaxed', 'cyclic'] = 'relaxed' parameter to StatusParameters and InvestParameters constructors; updated typing imports to include Literal.
Relaxed Mode Support in Modeling Primitives
flixopt/modeling.py
Updated consecutive_duration_tracking() to accept previous_duration: None, with initial duration constraint now conditional on non-None value. Updated BoundingPatterns.state_transition_bounds() to accept previous_state: None, returning optional initial constraint (None in relaxed mode). Big-M computation treats None previous values as 0.
Constraint Application and Cyclic Logic
flixopt/features.py
Introduced _add_cluster_cyclic_constraint() to enforce equality of status at time 0 and final step for cyclic mode. Modified startup/shutdown handling to compute previous_state from _previous_status with None fallback. Updated _get_previous_uptime() and _get_previous_downtime() to return None in relaxed mode instead of default values.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • Feature/rename on off to status #500 — Modifies the same StatusParameters/StatusModel surface and updates shared modeling functions (consecutive_duration_tracking and BoundingPatterns.state_transition_bounds).

Suggested labels

v3.0.0

Poem

🐰 A cluster hops in two new ways,
Relaxed or cyclic through the days,
With states that bloom and durations dance,
Constraints now flow with gentle stance! 🌀

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete; it only provides a brief one-line summary ('Improve the handling of Status in clustered Models') and leaves all template sections (Type of Change, Related Issues, Testing) largely unfilled or unchecked. Complete the description by selecting the appropriate Type of Change (appears to be New feature), specifying the issue number, and confirming whether testing was performed and tests still pass.
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title is vague and does not clearly convey the main change; 'Feature/aggregate rework v2+status' uses non-descriptive terms and branch naming conventions rather than explaining what was improved. Revise the title to clearly describe the feature, e.g., 'Add cluster mode support for status modeling in aggregated systems' or 'Support relaxed and cyclic status modes for clustered models'.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@FBumann
Copy link
Member Author

FBumann commented Dec 27, 2025

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 27, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

  1. flixopt/components.py - InterclusterStorageModel fixes

  _add_linking_constraints (line 1470-1476):
  - Added decay factor (1-loss)^N to link SOC between periods per Blanke et al. (2022) Eq. 5
  - Changed from scalar float() conversion to keeping rel_loss.mean('time') as DataArray to respect period/scenario dimensions

  _add_combined_bound_constraints (line 1514-1528):
  - Added decay factor (1-loss)^t to the combined bounds check per Blanke et al. (2022) Eq. 9
  - Changed from scalar float() conversion to keeping rel_loss.mean('time') as DataArray

  2. flixopt/transform_accessor.py - expand_solution fix

  Lines 1206-1220:
  - Fixed self-discharge decay calculation to use xarray DataArrays properly
  - Created time_within_period_da as a DataArray with 'time' dimension
  - Compute decay as (1 - loss_value) ** time_within_period_da to properly broadcast across period/scenario dimensions

  Key Technical Details

  - All parameters use xr.DataArray to respect per-period/scenario values
  - Decay factors use mean loss rate over time (period-level linking doesn't use per-timestep loss)
  - xarray broadcasting handles alignment across dimensions automatically
* Add realsitic data to notbeooks

* Add local catch warnings to solution of model

* Add local catch warnings to solution of model

* Remove solving from generate_example_systems.py script

* Remove new system

* Remove new system
@FBumann FBumann changed the base branch from feature/aggregate-rework-v2 to main January 6, 2026 15:55
@FBumann FBumann closed this Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants