Skip to content

Fix pandapower contingency analysis and Egret OPF on unrated branches - #137

Merged
qian-harvard merged 2 commits into
mainfrom
fix/issues-127-128
Oct 22, 2026
Merged

qian-harvard merged 2 commits into
mainfrom
fix/issues-127-128

Conversation

@qian-harvard

Copy link
Copy Markdown
Contributor

Summary

Fixes two bugs reported by @ibrahim-siali. Both reproduced on main before the fix.

#127: pandapower run_contingency_analysis always failed. It called net.deepcopy(), but pandapowerNet has no such method, so every call returned 'pandapowerNet' instance has no attribute 'deepcopy'. It now uses copy.deepcopy.

#128: Egret solve_dc_opf failed on branches with no rating. MATPOWER marks an unlimited branch with rateA = 0. powerio leaves Egret's rating keys out for those branches (0.11.5 omits them; the issue saw null on 0.11.4). Egret's OPF models read branches[k]['rating_long_term'] directly, so the solve raised KeyError: 'rating_long_term'. The three solver tools now read cases through _read_model_data, which fills a missing rating_long_term / rating_short_term / rating_emergency with None. Egret's own MATPOWER parser writes None for these branches, and its models treat it as no thermal limit, so the case solves with those branches unconstrained.

Testing

  • tests/test_pandapower_contingency.py: N-1 on case14. On main it fails with the issue's exact error. With the fix it passes, and the stored network is left unchanged.
  • tests/test_egret_unrated_branches.py: IEEE 14-bus with alternate branches unrated, loaded with load_model_from_any and solved with solve_dc_opf (HiGHS). On main it fails with 'rating_long_term'. With the fix it solves, and the 10 unrated branches come back unlimited. This test skips in CI, which doesn't install the egret extra; I ran it locally with gridx-egret 0.6.2.
  • Full CI suite locally (Python 3.12): 780 passed, 19 skipped.

Closes #127
Closes #128

🤖 Generated with Claude Code

qian-harvard and others added 2 commits October 22, 2026 17:20
pandapowerNet has no deepcopy() method, so run_contingency_analysis failed
on every call with "'pandapowerNet' instance has no attribute 'deepcopy'".

Closes #127

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rror

MATPOWER marks an unlimited branch with rateA = 0. powerio leaves Egret's
rating keys out for those branches, and Egret's OPF models index
branches[k]['rating_long_term'] directly, so solve_dc_opf failed with
KeyError: 'rating_long_term' on case5, case14 and similar cases.

The solver tools now fill a missing rating_long_term / rating_short_term /
rating_emergency with None before solving. That is what Egret's own MATPOWER
parser writes, and its models treat None as no thermal limit.

The new test skips in CI, which doesn't install the egret extra.

Closes #128

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@qian-harvard
qian-harvard merged commit c9ab4dc into main Oct 22, 2026
5 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.

egret: solve_dc_opf fails on cases with unrated branches ('rating_long_term') pandapower run_contingency_analysis fails: no attribute 'deepcopy'

1 participant