Fix global constraint bug for myopic pathway#1390
Merged
Conversation
lkstrp
approved these changes
Oct 10, 2025
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR solves bug in global constraint for primary energy when applied to myopic pathway (thus
docs/examples/myopic-pathway.ipynbfailing)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_periodto 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
typeandcarrier_attribute. The original notebook omits this, and it still works, but it works becausetypedefaults to "primary_energy" andcarrier_attributedefaults 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. ANaNdefault would make sense. However, it is not the problem we're solving here, and I just patch the notebook to make it explicit.