Skip to content

feat(pandapower): add topology-aware N-1 and N-2 security assessment - #156

Merged
qian-harvard merged 15 commits into
Power-Agent:mainfrom
BurhanAbdullah:feat/pandapower-n2-security-assessment
Nov 23, 2026
Merged

qian-harvard merged 15 commits into
Power-Agent:mainfrom
BurhanAbdullah:feat/pandapower-n2-security-assessment

Conversation

@BurhanAbdullah

Copy link
Copy Markdown
Contributor

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

  • 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.

@qian-harvard

Copy link
Copy Markdown
Contributor

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.

@BurhanAbdullah

Copy link
Copy Markdown
Contributor Author

@qian-harvard Done,

@qian-harvard
qian-harvard merged commit 10dbd9a into Power-Agent:main Nov 23, 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.

2 participants