Skip to content

fix: masking of nan constraints in kvl#1438

Merged
lkstrp merged 3 commits intomasterfrom
fix/kvl-constraint-masking
Nov 12, 2025
Merged

fix: masking of nan constraints in kvl#1438
lkstrp merged 3 commits intomasterfrom
fix/kvl-constraint-masking

Conversation

@FabianHofmann
Copy link
Copy Markdown
Contributor

@FabianHofmann FabianHofmann commented Nov 12, 2025

Changes proposed in this Pull Request

Apply KVL masking and bump linopy version.

@lkstrp @Irieo the "problem" with the new linopy version (and yes it should have been version 0.6.0) is that it checks more rigorously on the constraints sanity. PyPSA's KVL constraint had nan's in the right hand side for a subset of constraints. These result from different sets of active branches across the periods. Having nan rhs values is formally incorrect, so linopy raising an error is what we want here. I have added a mask which filters out the unwanted constraints on the linopy side.

So PyPSA/linopy#520 is not needed and I still need to think about whether we want to have it in.

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.

@FabianHofmann FabianHofmann requested a review from lkstrp November 12, 2025 09:04
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.

Ah, it can be simple as that! thanks a lot @FabianHofmann !

I wasn't sure if we had more nans set, which linopy had previously handled for PyPSA. But you're right, it's better to be strict and fix it here

@FabianHofmann
Copy link
Copy Markdown
Contributor Author

FabianHofmann commented Nov 12, 2025

@lkstrp sure thing! should I also fix the unrelated doc test here which seems to be related to a missing carrier in one example?

@lkstrp
Copy link
Copy Markdown
Member

lkstrp commented Nov 12, 2025

All good, I will fix it. Wanna check if we can unpin xarray with linopy==0.5.8

@lkstrp lkstrp merged commit 5634bb1 into master Nov 12, 2025
20 of 22 checks passed
@lkstrp lkstrp deleted the fix/kvl-constraint-masking branch November 12, 2025 15:00
a-buntjer pushed a commit to a-buntjer/PyPSA that referenced this pull request Nov 27, 2025
Merged changes from PyPSA v1.0.3 and v1.0.4 including:
- Fix busmap clustering for multilinks (PyPSA#1441)
- Fix handling of inactive storage components (PyPSA#1442)
- Fix masking of nan constraints in kvl (PyPSA#1438)
- Fix snapshot selection for operational in multi period (PyPSA#1437)
- Fix ramping-/rolling horizon logic (PyPSA#1428)
- CI improvements and dependency updates

Resolved conflicts in pypsa/optimization/constraints.py:
- Used upstream's c.active_assets approach (cleaner, already handles MultiIndex)
- Preserved our stochastic Store constraint fix (transpose for dimension alignment)
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.

3 participants