Skip to content

Fix masking of ramp constraints for assets with NaN ramp limits#1494

Merged
lkstrp merged 4 commits intoPyPSA:masterfrom
sasa821:bugfix/fix-ramp-constraints
Dec 16, 2025
Merged

Fix masking of ramp constraints for assets with NaN ramp limits#1494
lkstrp merged 4 commits intoPyPSA:masterfrom
sasa821:bugfix/fix-ramp-constraints

Conversation

@sasa821
Copy link
Copy Markdown
Contributor

@sasa821 sasa821 commented Dec 15, 2025

Closes #1493

Changes proposed in this Pull Request

This PR fixes a bug in PyPSA ≥ 1.0 where ramp constraints were applied to fixed generators and links with NaN ramp_limit_up/down once ramping was enabled for any other asset of the same component.

In the define_ramp_limit_constraints function, the masking logic for fixed components currently uses:

~ramp_limit_up_fix.isnull().all()

Calling .all() collapses the array across all dimensions and produces a scalar boolean. As a result, once any fixed asset has a ramp limit defined, the ramp constraint is applied to all fixed assets, including those with NaN ramp limits.

Consequently, assets without specified ramp limits can receive ramp constraints equal to zero, leading to unintended infeasibilities (e.g. for load-shedding or slack generators).

This PR replaces the scalar check with element-wise masking, so that ramp constraints are only created for assets (and snapshots) where ramp limits are explicitly defined.

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in docs.
  • Unit tests for new features were added (if applicable).
  • A note for the release notes docs/release-notes.md of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

Copy link
Copy Markdown
Member

@lkstrp lkstrp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sasa821 !

Could you also add a release note and a quick test?

@sasa821
Copy link
Copy Markdown
Contributor Author

sasa821 commented Dec 15, 2025

Hi @lkstrp,
I’ve updated the release notes and added some small tests for checking ramp limits on generators and links. Could you take another look at the PR?

@sasa821 sasa821 requested a review from lkstrp December 15, 2025 21:57
Copy link
Copy Markdown
Member

@lkstrp lkstrp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sasa821 !

@lkstrp lkstrp enabled auto-merge (squash) December 16, 2025 08:01
@lkstrp lkstrp merged commit 608a336 into PyPSA:master Dec 16, 2025
19 of 20 checks passed
@sasa821 sasa821 deleted the bugfix/fix-ramp-constraints branch December 16, 2025 10:06
@Irieo
Copy link
Copy Markdown
Contributor

Irieo commented Dec 16, 2025

Thanks @sasa821 for spotting and fixing it!

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.

Ramp constraints incorrectly applied to fixed components

3 participants