Skip to content

Add schemas for the custom-constraint tables#120

Merged
nick-gorman merged 2 commits into
mainfrom
add-custom-constraint-schemas
Jun 24, 2026
Merged

Add schemas for the custom-constraint tables#120
nick-gorman merged 2 commits into
mainfrom
add-custom-constraint-schemas

Conversation

@nick-gorman

@nick-gorman nick-gorman commented Jun 18, 2026

Copy link
Copy Markdown
Member

Adds validation schemas for the custom-constraint tables, updates unique row validation logic, and timeslice NaN logic.

src/ispypsa/validation/schemas/
  custom_constraints.yaml                → constraint senses (<=, >=, =)
  custom_constraints_lhs.yaml            → LHS terms: term types (incl. load), coefficients
  custom_constraints_rhs.yaml            → RHS limits: timeslice + date_from semantics
  network_expansion_options.yaml         → fix expansion_id cross-ref (constraints_rhs → custom_constraints_rhs)
  network_transmission_path_limits.yaml  → unique: key; NaN-timeslice fallback semantics

Broader changes than just adding the custom constraint schemas

1. Uniqueness is now plain unique:, replacing bespoke custom_validation.
The three tables whose uniqueness key includes a nullable column —

  • custom_constraints_lhs[constraint_id, term_type, variable_name, date_from]
  • custom_constraints_rhs[constraint_id, timeslice, date_from]
  • network_transmission_path_limits[path_id, direction, timeslice]

— previously carried hand-written custom_validation rules whose only job was
to spell out the NaN handling. They are now plain unique: declarations. This
relies on a decision to have unique: treat NaN as equal to NaN (pandas
duplicated() semantics), so at most one otherwise-identical NaN row is
permitted per group — standard SQL UNIQUE would treat NULLs as distinct and
let duplicates through. The contract is recorded in #122, which
also tracks where to document it centrally.

2. A NaN timeslice now means "fallback", not "all conditions".
Previously a no-timeslice row in custom_constraints_rhs and
network_transmission_path_limits was read as a static limit applying to all
demand conditions, effectively mutually exclusive with per-timeslice rows. It
is now a fallback: it applies only at snapshots not covered by any
per-timeslice row for the same group, with per-timeslice rows taking precedence
where they overlap — so the two forms may co-exist. Documented under the
timeslice column in both tables.

This second change is a behavioural contract for whatever applies these limits
downstream: the fallback/precedence logic still needs to be implemented there.

The templater has emitted custom_constraints, custom_constraints_lhs and
custom_constraints_rhs since the PLEXOS templater landed, but the tables
had no schemas, so user-supplied versions of them had no documented
contract. The schemas pin the vocabulary the translator now relies on:
direction senses (<=, >=, =), term types (including load, which
the 7.5 PLEXOS extract emits for Node Load Coefficient terms), the
timeslice cross-reference, and date_from semantics (the value active at
the start of an investment period applies for that whole period).

Also fixes network_expansion_options cross-referencing the non-existent
constraints_rhs table.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The custom_validation rules on these schemas only existed to express
"uniqueness with NaN counted as a single value". Pinning down unique: to
treat NaN as equal (#122) lets a plain unique: carry that
guarantee, so the three rules become unique: declarations.

For network_transmission_path_limits and custom_constraints_rhs this also
revises what a NaN timeslice means: rather than a static limit applying to
all conditions (mutually exclusive with per-timeslice rows), it is now a
fallback applying only where no per-timeslice row covers, so both forms may
co-exist. Documented under the timeslice column.

Also adds generator_capacity to the lhs term_type allowed values.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nick-gorman nick-gorman merged commit 5717818 into main Jun 24, 2026
15 checks passed
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