Skip to content

chihsingwu/CSD-Grid-Dual-Engine

Repository files navigation

CSD-Dual-Engine: Physics-Driven Dynamic Boundary Verification for Power Grid Foundation Models

The CSD-dual-engine is an open-source, zero-topology Dynamic Verification Framework designed to evaluate, benchmark, and provide real-time physical constraints for continuous data-driven control, time-series forecasting, and foundation models operating within high-penetration, lower-inertia electrical power networks. Instability precursors often reside in high-frequency spectral structure that tokenization-based models tend to smooth away; spectral entropy recovers this by measuring the full eigenvalue distribution.

🎯 The Core Rationale: A Non-Invasive Physics Guardrail for AI Controls

As advanced deep learning architectures and foundation models become increasingly integrated into operational grid optimization—whether through native power system spatial modeling or cross-domain policy transfer—they inherently operate as probabilistic text/action generators. In complex, low-inertia networks, any out-of-distribution neural prediction risks inducing catastrophic, un-damped electromechanical oscillations or triggering hidden bifurcations.

To bridge the gap between deep learning outputs and critical infrastructure safety, this framework provides a zero-topology, physics-driven Evaluation & Guardrail Layer:

  • The Predictive Layer: Executes advanced policy inference, predictive tracking, and multi-variable optimization trajectories (applicable to all native or transferred network AI models).
  • The Physics Guardrail (CSD-Dual-Engine): Continuously benchmarks the AI-generated trajectories against fundamental physical invariants in near real-time. By tracking the exact state-space proximity to critical transitions via parallel time-domain and spectral-domain metrics, it isolates dynamic stability failure modes before actual system hardware thresholds are violated.

Scope, Technical Boundaries & Numerical Rigor

To satisfy the rigorous verification requirements of joint critical infrastructure deployments, this release establishes explicit operational boundaries:

  1. High-Fidelity Numerical Simulation Environment (Sim2Real Boundary): We ground our baseline empirical validation within industrialized ANDES-equivalent platforms across multi-machine benchmark networks (e.g., IEEE 39-bus and Kundur 4-machine systems). We explicitly address the Sim2Real gap: while these deterministic numerical environments provide the exact clean mathematical reference required to track bifurcation boundaries, practical live deployment requires subsequent stages to filter stochastic noise and complex multi-time-scale converter control interactions.
  2. Modal Damping Constraints: Our Spectral Engine (Engine B) is highly optimized to track localized and inter-area oscillation modes near critical boundaries (e.g., the 0.6 Hz mode under progressive excitation gain degradation). It serves as a dedicated primary indicator for weak-damping tracking, and is systematically coupled in parallel with our Time-Domain Jacobian Proxy (Engine A) to eliminate blind spots across fast saddle-node bifurcations and voltage collapse regimes.

🚀 Empirical Validation Results

⚡ The Core Breakthrough: Weak Damping & Dynamic Small-Signal Instability

Traditional grid monitoring relies heavily on Voltage Deviation ($V_{dev}$). However, as power systems integrate massive renewable energy sources, a catastrophic vulnerability emerges: dynamic small-signal instability under weak-damping conditions. In these scenarios, excitation controls artificially maintain nominal voltage, masking the severe degradation of the system's underlying dynamic structure. $V_{dev}$ fails completely here, while CSD-EWS thrives.

engine_ab_compare

📊 Experiment 1: IEEE 39-Bus Transient Stability

Validated using ANDES v2.0.0 on the New England 39-bus system across 116 multi-fault scenarios (77 stable, 39 unstable) with a 60 Hz PMU-equivalent sampling rate.

📈 Boundary Discovery & Performance

  • Critical Clearing Time (CCT) Discovery: Systematically identified the exact physical bifurcation boundary for a Bus 16 fault between 1.3s (Stable) and 1.4s (Unstable).
  • Pure Data-Driven Inference: Operating without any network topology, power flow models, or pre-trained classifiers, Engine A achieved an exceptional AUC-ROC of 0.8795 using rolling window metrics.
Metric Evaluation (Post-Fault Window) AUC-ROC
score_J (Mean $\log \max \lambda(J)
score_trend (Rolling trend statistic slope) 0.8025
combo (Weighted Composite Score) 0.8768
  • Clean Binary Separation: In single-scenario validation, the rolling trend slope provides an instantaneous binary indicator—a positive slope triggers immediate critical alert routing, while a negative slope robustly tracks system post-fault recovery.

📉 Experiment 2: Kundur 4-Machine 19-Point $K_A$ Sweep (The Ultimate Proof)

To simulate the absolute blind spot of conventional AI models, we executed an intensive 19-point excitation gain ($K_A$) sweep ($K_A = 5$ to $500$) to induce progressive inter-area oscillation damping degradation near the 0.6 Hz mode.

🚨 Complete Dual-Engine Benchmark vs. Baseline

As the excitation system works harder to maintain voltage setpoints, traditional indicators point in the perfect opposite direction ($\rho = -0.977$), signaling "improved safety" while the grid's dynamic structure is actually fracturing. Engine B completely reverses this failure with near-perfect correlation ($\rho = +0.993$).

Method / Indicator Domain Spearman Correlation ($\rho$) $p$-value Physical Verdict
Engine B LFPR (This Work) Spectral +0.993 < 0.0001 Near-Perfect Primary Indicator
Combo (A+B, $0.5+0.5$) Dual-Domain +0.974 < 0.0001 Excellent Robust Combination
Engine B -Entropy Spectral -0.930 < 0.0001 Strong (Entropy decays as danger rises)
Engine A score_J Time +0.730 0.0004 Significant Complementary Role
Vdev (Traditional Baseline) Voltage -0.977 < 0.0001 Complete Systematic Failure

🎯 Why Engine B Achieves Mathematical Supremacy ($\rho = +0.993$)

Rooted in Critical Slowing Down (CSD) theory (Scheffer et al., Nature 2009; Podolsky & Turitsyn, 2013), as a dynamical system approaches bifurcation, energy systematically concentrates into low-frequency modes.

Our spectral engine continuously extracts the Low-Frequency Power Ratio (LFPR) within a fixed $[0, 2.0\text{ Hz}]$ boundary via an optimized 120-sample FFT window:

$$\text{LFPR} = \frac{\sum |F(f)|^2 \text{ for } 0 < f \le 2.0\text{ Hz}}{\sum |F(f)|^2 \text{ for all } f}$$

As $K_A$ scales up and damping ratio drops to negative regimes, the 0.6 Hz inter-area oscillation energy grows monotonically relative to total signal energy. Engine B captures this physical redistribution with absolute precision, providing a zero-topology, PMU-only early warning system long before physical threshold violations manifest.


🔄 The Power of the Dual-Engine Architecture

Our framework does not rely on a single analytical domain. Instead, it deploys Engine A and Engine B in parallel to achieve comprehensive, multi-domain physics validation near the critical stability boundary, eliminating blind spots across all primary power system instability modes.

🤝 Cross-Domain Physical Complementarity

Instability Type Physical Mechanism Best Indicator Rationale
Transient Stability (Large Disturbance) Nonlinear angle divergence Engine A (score_J) Jacobian captures rapid, highly nonlinear state transitions
Small-Signal Stability (Weak Damping) Low-freq oscillation growth Engine B (LFPR) Fourier directly measures energy redistribution into target modes
Voltage Collapse Saddle-node bifurcation Engine A ($\min|\lambda|$) Dynamic Jacobian singularity detection
Inter-Area Oscillation (0.1–2 Hz) Mode undamping Engine B (LFPR) Direct spectral measurement of target frequency

🎯 Dual-Engine Synergy: Engine A and Engine B serve as independent physical implementations of Critical Slowing Down (CSD) theory. By cross-checking time-domain eigenvalue trajectories against frequency-domain damping rates simultaneously, the system eliminates false positives and robustly flags anomalies before they physically manifest in the grid.


Core idea

Modern grid AI methods can be evaluated not only by classification accuracy or OPF feasibility, but also by whether their outputs remain consistent with physical stability margins near dynamic boundaries.

This package frames that validation in three layers:

Layer 1 — Physical scenario generation

Inspired by recent LLM-driven transient stability assessment workflows, complex power-system scenarios can be generated through simulation tools such as ANDES.

Examples include:

  • clearing-time sweeps,
  • excitation-gain sweeps,
  • weak-damping regimes,
  • renewable-penetration stress cases,
  • line, bus, or generator disturbance scenarios.

In this package, the reference demo uses a Kundur 4-machine KA sweep as a controlled physical boundary case.

Layer 2 — CSD-EWS dynamic safety margin

The package computes interpretable early-warning indicators that quantify whether a system is approaching dynamic instability.

The current dual-engine implementation includes:

  • Engine A — Time-domain Jacobian proxy
    Estimates a local linear transition operator from multichannel PMU-like trajectories and summarizes the eigenvalue trajectory.
  • Engine B — Spectral CSD indicator
    Computes low-frequency power ratio (LFPR) and spectral entropy from sliding FFT windows.

These indicators act as a damping-aware physical scale for weak-damping and low-frequency oscillation regimes.

Layer 3 — AI prediction cross-validation interface

The intended next step is a standardized interface where any AI system can submit predictions for the same physical scenarios.

Examples of candidate AI systems include:

  • grid-native models such as GridSFM-style approaches,
  • cross-domain physical foundation models such as TokaMind-style approaches,
  • LLM-generated TSA classifiers,
  • conventional CNN/LSTM/Transformer stability classifiers.

Their predictions can then be cross-checked against CSD-EWS indicators, damping trends, LFPR, and instability ground truth.

The goal is not to claim that CSD-EWS replaces these models. The goal is to provide a physics-informed validation layer:

Does the AI prediction remain consistent with damping-aware stability evidence near the physical boundary? By establishing this cross-validation interface, we enable rigorous benchmarking of diverse AI architectures—ranging from grid-native foundation models like GridSFM to cross-domain models like TokaMind—against the immutable physical laws governing dynamic stability.

Complementary Approaches in Grid Stability Monitoring

Current power grid stability assessment often relies on static AC-OPF feasibility tools (such as Microsoft GridSFM) to evaluate network topology and static voltage bounds. While highly effective for steady-state analysis, these tools can be complemented by dynamic time-domain monitoring to address transient instabilities.

The CSD-dual-engine introduces a dynamic precursor detection framework, designed to integrate with existing static analysis ecosystems. By continuously evaluating the damping ratio of critical system poles from PMU time-series data, it provides real-time visibility into dynamic phenomena, such as critical slowing down (CSD), prior to apparent voltage collapse.

1. Dynamic vs. Static Monitoring Scenarios

gridsfm-csd-ews-dynamic-stability-comparison *Figure 1: Illustration of system behavior under varying damping conditions. In scenarios with weak or negative damping, dynamic instability (captured via LFPR) can escalate even while voltage deviations remain within nominal static bounds.*

2. The Role of Low-Frequency Power Ratio (LFPR)

voltage-collapse-lfpr-dynamic-monitoring *Figure 2: The LFPR metric serves as an early warning indicator for dynamic instability, functioning independently of network topology by analyzing sliding windows of local PMU measurements.*

3. Time-Domain Damping Ratio Extraction

pmu-time-series-damping-ratio-extraction *Figure 3: Representation of the underlying physical constraints. Engine B extracts dynamic damping properties directly from time-series oscillations, establishing temporal constraints suitable for robust AI control applications.*

Interactive Pole & Damping Simulator

To illustrate the relationship between the system's dominant poles (eigenvalues) and the resulting time-domain response, we provide an interactive simulator based on the standard damping ratio formula: ζ = -σ / √(σ² + ω²).

👉 Launch Interactive Simulator (This simulator visually maps the real (σ) and imaginary (ω) components of the extracted Jacobian proxy to the corresponding dynamic behavior, demonstrating the transition from a strongly damped state to sustained oscillations.)

What this package currently provides

This v0.1 release provides the CSD-EWS reference layer only:

  • Engine A: data-driven Jacobian proxy score.
  • Engine B: LFPR and spectral entropy score.
  • Kundur KA sweep demo using ANDES.
  • Spearman correlation analysis against inter-area oscillation amplitude.
  • Reproducible figure and data export.

It is intentionally small. It does not include a database, web service, Docker stack, CI pipeline, or full AI benchmark server.

Installation

python -m venv .venv
source .venv/bin/activate  # Windows: .venv\\Scripts\\activate
pip install -e .

Core engine dependencies:

pip install numpy scipy matplotlib

For the Kundur simulation demo, install ANDES:

pip install andes openpyxl

Quick smoke test

pytest -q

Run Kundur KA sweep

Small sweep:

csd-dual-engine --ka-values 10,50,200,500 --output-dir results\_demo

Full default 19-point sweep:

csd-dual-engine --output-dir results

Expected outputs:

results/
├─ kundur\_engine\_ab\_summary.csv
├─ kundur\_engine\_ab.npy
└─ engine\_ab\_compare.png

Programmatic use

import numpy as np
from csd\_dual\_engine import engine\_a\_jacobian, engine\_b\_spectral

t = np.arange(0, 15, 1/60)
y = np.column\_stack(\[
    np.sin(2\*np.pi\*0.5\*t),
    np.cos(2\*np.pi\*0.8\*t),
])

a = engine\_a\_jacobian(t, y, n\_vars=2)
b = engine\_b\_spectral(t, y, fs=60.0)

print(a.log\_max\_eigenvalue\_score)
print(b.lfpr\_score, b.spectral\_entropy\_score)

Example interpretation

In a weak-damping KA sweep, voltage deviation may decrease because excitation control keeps voltage regulated, even as inter-area oscillation damping deteriorates.

CSD-EWS is designed to catch this type of mismatch:

  • voltage can look acceptable,
  • damping can still worsen,
  • LFPR or Jacobian-proxy indicators can expose the dynamic boundary.

This makes the package useful as a validation reference for AI models that claim to understand grid stability.

Intended research use

Use this package to:

  • generate or analyze controlled physical-boundary cases,
  • compute damping-aware CSD indicators,
  • compare AI predictions against interpretable physical evidence,
  • build small benchmark notes for grid AI evaluation,
  • support technical discussions around physical AI reliability.

Do not overinterpret this release as:

  • a complete PMU production system,
  • a certified protection relay,
  • a replacement for full power-system studies,
  • a complete benchmark for all grid AI models.

Notes

  • The Kundur demo requires ANDES and its bundled kundur\_full.xlsx case.
  • Engine A uses a PCA-reduced local linear transition operator, then summarizes the final post-fault eigenvalue trajectory.
  • Engine B computes LFPR and spectral entropy over sliding windows.
  • The package intentionally stays small: no database, no web server, no Docker, no CI by default.

🌐 Alignment with State-of-the-Art (AI4Science Frameworks)

Our CSD-dual-engine architecture serves as a critical, physics-informed verification layer that perfectly complements current agentic workflows in power system analysis:

  • Chongqing-Imperial TSA Framework (Hu, Wang, & Pal, 2026): Their outstanding LLM-driven simulation and NAS pipeline achieves high accuracy outcome.

Citation / attribution

TaiScience Research Group — Open Source Reference Implementation.

If you use this package, please cite or acknowledge:

TaiScience Research Group. Physical Boundary Validation for Grid AI: CSD-EWS Dual-Engine Reference Implementation, 2026.

About

A compact open-source reference package for physics-boundary validation of AI systems in electric power grids. This project does not present a full grid product or a replacement for existing grid AI models. I

Topics

Resources

License

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages