You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(pandapower): add topology-aware N-1 and N-2 security assessment - #156
Introduces a topology-aware security assessment capability for pandapower networks, extending the existing contingency analysis from basic single-element outages to structured N-1 and simultaneous N-2 outage assessment.
The implementation evaluates network topology before running power flow, identifies load-bearing islands without an active supply source, and reports security violations with deterministic severity ranking.
Key Changes
Topology-aware N-1 assessment: Evaluates individual line and transformer outages, identifies islanding conditions, and quantifies unsupplied demand.
Simultaneous N-2 assessment: Evaluates unordered pairs of selected in-service elements to identify vulnerabilities caused by concurrent outages.
Island detection: Uses pandapower's switch-aware network topology, accounting for active switches, buses, and supply sources.
Unserved load calculation: Quantifies disconnected demand while avoiding the incorrect treatment of static generation as additional load.
Operational limit assessment: Checks bus voltage limits and line and transformer loading limits, including element-specific overrides.
Severity ranking: Prioritizes contingencies using unserved load, voltage deviations, and thermal overload metrics without combining incompatible engineering units.
Execution safeguards: Adds configurable max_contingencies protection to prevent unexpectedly large N-2 simulations.
MCP integration: Exposes the extended functionality through run_contingency_analysis, retaining N-1 as the default for backward compatibility.
Documentation and tests: Adds implementation documentation and regression coverage for N-1 and N-2 assessment, simultaneous outages, islanding, deterministic results, and candidate limits.
Testing
Adds focused tests covering:
Deterministic N-1 and N-2 results.
Simultaneous outage-pair evaluation.
Load-bearing island detection and unserved demand.
Generation exclusion from unserved-load calculations.
Element-specific thermal loading limits.
N-2 candidate-count safeguards.
Preservation of the original network state.
Scope
This PR focuses on topology-aware static contingency assessment using pandapower AC power flow. It does not introduce dynamic stability assessment or protection coordination analysis.
Thanks — the switch-aware islanding and N-2 that actually runs (the old loop accepted "N-2" but always ran N-1) are a clear improvement. One blocker before merge:
Results contain numpy.int64, which the MCP SDK can't serialize. The bus IDs in base_islands and islands (buses, source_buses) come straight from the graph built by pandapower.topology.create_nxgraph, so they're numpy.int64. Under mcp 2.3, MCPServer converts structured output to JSON with pydantic, which raises PydanticSerializationError: Unable to serialize unknown type: <class 'numpy.int64'>. So every run_contingency_analysis call returns "Error executing tool". I reproduced it on case14 for both N-1 and N-2. The unit tests call the functions directly, so they don't catch it. Converting the IDs to plain ints in _topology_islands fixes it, for example sorted(int(b) for b in component). A test that runs json.dumps(report) would keep it fixed.
Smaller things that don't block the merge:
sorted(..., key=str) puts buses in text order (10 before 2). Once they're ints, a plain numeric sort reads better.
N-1 and N-2 repeat the same input checks, result building and ranking code. N-1 could reuse the same loop with one outage at a time.
Non-convergence ranks below every limit violation, so a possible voltage collapse sorts under a 1% overload. Worth choosing on purpose.
_limits() takes net and table but doesn't use them.
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
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.
Summary
Introduces a topology-aware security assessment capability for pandapower networks, extending the existing contingency analysis from basic single-element outages to structured N-1 and simultaneous N-2 outage assessment.
The implementation evaluates network topology before running power flow, identifies load-bearing islands without an active supply source, and reports security violations with deterministic severity ranking.
Key Changes
max_contingenciesprotection to prevent unexpectedly large N-2 simulations.run_contingency_analysis, retaining N-1 as the default for backward compatibility.Testing
Adds focused tests covering:
Scope
This PR focuses on topology-aware static contingency assessment using pandapower AC power flow. It does not introduce dynamic stability assessment or protection coordination analysis.