Skip to content

fix: resolve constant-constant constraint crashes and document H2 limits config - #190

Open
omari91 wants to merge 5 commits into
PyPSA:mainfrom
omari91:main
Open

fix: resolve constant-constant constraint crashes and document H2 limits config#190
omari91 wants to merge 5 commits into
PyPSA:mainfrom
omari91:main

Conversation

@omari91

@omari91 omari91 commented Sep 7, 2026

Copy link
Copy Markdown

Before asking for a review for this PR make sure to complete the following checklist:

Changes proposed in this Pull Request

  • Fixes solver crashes due to constant constraints: Replaced direct n.model.add_constraints(...) calls with a new safe_add_constraint(...) wrapper function in scripts/pypsa-de/additional_functionality.py. This safely bypasses adding inequality constraints where both the left-hand side and right-hand side resolve to 0 (which previously caused solvers like Highs/Gurobi to crash with ValueError: Both sides of the constraint are constant).
  • Refactored constraint logic: Applied safe_add_constraint systematically across functions such as h2_import_limits, h2_production_limits, capacity_limits, limit_co2, and auxiliary_flow_limits.
  • Cleaned up redundant code: Removed an obsolete duplicate code block within h2_import_limits() that manually checked for empty links, as the new wrapper handles this automatically.
  • Improved configuration visibility: Explicitly documented the pypsa-de.h2_import_limits.enable configuration toggle in config.de.yaml.
  • Updated CHANGELOG.md to reflect the changes.

Checklist

Required:

  • Changes are tested locally and behave as expected.
  • Code and workflow changes are documented.
  • A brief description of the changes has been added to Changelog.md.
    If applicable:
  • Changes in configuration options are reflected in scripts/lib/validation. (N/A: no pypsa-de schemas were found)
  • For new data sources or versions, these instructions have been followed. (N/A)
  • New rules are documented in the appropriate doc/*.rst files. (N/A)

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.

1 participant