Apply the new-format custom constraints in pypsa_build - #148
Open
nick-gorman wants to merge 3 commits into
Open
nick-gorman wants to merge 3 commits into
nick-gorman wants to merge 3 commits into
Conversation
The translator's new-format custom constraints are scoped by investment period and timeslice, which the existing pypsa_build path can't express. Adds the pypsa_build step that turns each RHS row into a linopy constraint at the snapshots its period and timeslice select, with blank timeslices as a per-constraint fallback and load terms as a per-snapshot RHS offset. Also declares the contract for its input tables as schemas, splitting the schema folder into ispypsa_tables (translator input) and pypsa_friendly_tables (pypsa_build input). Not yet wired into build_pypsa_network, so no production behaviour changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
On its own, "period" reads as a snapshot or time window, which is easy to confuse with the timeslice scoping these constraints also carry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bare "period" kept reading as a snapshot or time window in the custom constraint docs, so the convention is written down for future changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
The new-format custom constraints from the translator (#139) are scoped by
investment period and timeslice, e.g. a flow limit that only applies at QLD
peak demand in 2030. The existing
_add_custom_constraintssums every termover every snapshot, so it can't express that. This change adds
_add_custom_constraints_with_temporal_scope, which turns each RHS row intoone linopy constraint at the snapshots its investment period and timeslice
select.
It isn't wired into
build_pypsa_networkyet; that comes with the finalwiring PR, so there's no change in behaviour.
Design choices worth a look:
in its investment period that none of the same constraint's named
timeslices cover.
RHS rows with its exact investment_period, not every investment period. The
translator resolves all dated inputs to explicit investment periods, so
blank only appears on the expansion limits.
coefficient × p_setis added as aper-snapshot constant, which linopy moves to the RHS.
pis net dispatch (p_dispatch − p_store), matching PLEXOS'spaired battery Generation/Load coefficients.
terms and constraints with no variable terms raise, rather than silently
weakening the constraint.
ispypsa_tables(translatorinput) and
pypsa_friendly_tables(pypsa_build input). Only the threetables this step reads are declared so far. Nothing loads the schemas yet,
so the move is paths only.
🤖 Generated with Claude Code