Skip to content

Fix global constraint bug for myopic pathway#1390

Merged
lkstrp merged 2 commits intov1-docsfrom
v1-docs-fix-myopic
Oct 10, 2025
Merged

Fix global constraint bug for myopic pathway#1390
lkstrp merged 2 commits intov1-docsfrom
v1-docs-fix-myopic

Conversation

@Irieo
Copy link
Copy Markdown
Contributor

@Irieo Irieo commented Oct 10, 2025

This PR solves bug in global constraint for primary energy when applied to myopic pathway (thus docs/examples/myopic-pathway.ipynb failing)

The notebook was added here #1308 before new-opt PR #1154 where the constraint code was patched/refactored. The problem here is that when optimizing a subset of investment periods, the code iterates over all constraints and filters them by investment_period to cast the right constraint for a specific period. We should add a skip clause for constraint creation when no expressions (ie not constraints) are collected.

In the notebook, I also added an explicit declaration of the GlobalConstraint type and carrier_attribute. The original notebook omits this, and it still works, but it works because type defaults to "primary_energy" and carrier_attribute defaults to "co2_emissions" (set in data/component_attrs/global_constraints.csv). IMHO this is unintuitive: if the user doesn’t specify what the constraint applies to, it silently defaults to constraining co2_emissions. A NaN default would make sense. However, it is not the problem we're solving here, and I just patch the notebook to make it explicit.

  • I consent to the release of this PR's code under the MIT license.

@lkstrp lkstrp changed the base branch from master to v1-docs October 10, 2025 08:33
@lkstrp lkstrp merged commit 663e6e4 into v1-docs Oct 10, 2025
20 of 22 checks passed
@lkstrp lkstrp deleted the v1-docs-fix-myopic branch October 10, 2025 08:48
lkstrp added a commit that referenced this pull request Oct 13, 2025
* fix: gc for primary energy in myopic pathway

* Disable allow_errors for mkdocs-jupyter

---------

Co-authored-by: Lukas Trippe <[email protected]>
lkstrp added a commit that referenced this pull request Oct 13, 2025
* fix: gc for primary energy in myopic pathway

* Disable allow_errors for mkdocs-jupyter

---------

Co-authored-by: Lukas Trippe <[email protected]>
lkstrp added a commit that referenced this pull request Oct 14, 2025
* fix: gc for primary energy in myopic pathway

* Disable allow_errors for mkdocs-jupyter

---------

Co-authored-by: Lukas Trippe <[email protected]>
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