Skip to content

fix: CVaR optimization fails if components have no marginal costs#1457

Merged
lkstrp merged 8 commits intomasterfrom
cvar-fix
Dec 1, 2025
Merged

fix: CVaR optimization fails if components have no marginal costs#1457
lkstrp merged 8 commits intomasterfrom
cvar-fix

Conversation

@Irieo
Copy link
Copy Markdown
Contributor

@Irieo Irieo commented Dec 1, 2025

Closes #1456 and adds related tests.

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.

@Irieo Irieo requested a review from lkstrp December 1, 2025 13:00
@Irieo
Copy link
Copy Markdown
Contributor Author

Irieo commented Dec 1, 2025

To document here: from mathematical perspective the fix is strictly interpretable. When OPEX=0, CVaR correctly evaluates to 0, meaning there's no operational cost risk to hedge against. The optimization then reduces to just minimizing CAPEX (the deterministic investment costs).

a(s) >= 0 - thetaa(s) + theta >= 0
if a(s) = 0 for all scenarios, then theta = 0, and then CVaR = 0

for s in n.scenarios:
lhs = a.sel(scenario=s) - scen_opex_exprs[s] + theta
m.add_constraints(lhs, ">=", 0, name=f"CVaR-excess-{s}")

And e.g. a case of load shedding modelled via a "virtual generator" brings CVaR optimization back to standard formulation, i.e. model would evaluate and hedge by trading off upfront CAPEX for load shedding costs.

@lkstrp lkstrp enabled auto-merge (squash) December 1, 2025 14:22
@Irieo
Copy link
Copy Markdown
Contributor Author

Irieo commented Dec 1, 2025

pypsa-eur CI fails because of unrelated test environment issue

@lkstrp
Copy link
Copy Markdown
Member

lkstrp commented Dec 1, 2025

pypsa-eur CI fails because of unrelated test environment issue

Grrrg

@lkstrp lkstrp disabled auto-merge December 1, 2025 15:08
@lkstrp lkstrp merged commit 00a348d into master Dec 1, 2025
21 of 22 checks passed
@lkstrp lkstrp deleted the cvar-fix branch December 1, 2025 15:08
a-buntjer pushed a commit to a-buntjer/PyPSA that referenced this pull request Dec 4, 2025
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.

CVaR optimization fails if components have no marginal costs

2 participants