How meshwho/powergridreconfig works
Purpose and entry points
PowerGridReconfig is a Python 3.11 research framework for emergency power-grid topology control, centered on case118 simulations. Its integrated workflow is pool-guided, AlphaZero-like self-play: sample fixed scenarios, generate neural-MCTS trajectories, train a graph policy/value model, evaluate on a fixed set, and accept or reject the candidate. Stable CLIs are scripts/self_play/loop.py, scripts/self_play/train_graph_baseline.py, and scripts/evaluation/evaluate_checkpoint.py.
Configuration, planning, and run orchestration
Typed YAML configuration defines pool, generation, replay, training, evaluation, and acceptance contracts. The loop validates bootstrap artifacts, creates an iteration plan, supports fail-closed resume, and writes atomic completion markers. Core paths: grid_topology_ai/config/self_play.py, grid_topology_ai/self_play/plan.py, grid_topology_ai/self_play/pipeline.py, grid_topology_ai/self_play/iteration.py.
Scenario/runtime and physical-state boundary
Raw GridFM-style scenario data is adapted into NumPy/PYPOWER-ready state and stored by scenario ID. State construction produces versioned graph features and validates topology, identifiers, finite values, and physical limits. Environment reset executes no-op AC power flow before classification. Core paths: grid_topology_ai/data_adapter.py, grid_topology_ai/runtime/scenario_store.py, grid_topology_ai/state_builder.py, grid_topology_ai/environment.py.
Power-flow simulation and physical objective
PYPOWER is the authoritative AC power-flow backend, with reusable network/Newton workspaces and warm starts. Physical success is evaluated separately from episode termination: convergence, connectivity, thermal/voltage/generator/angle constraints must all pass. Redispatch is represented as a handoff boundary, not a production optimizer. Core paths: grid_topology_ai/pypower_backend.py, grid_topology_ai/power_flow_problem.py, grid_topology_ai/physical_objective.py, grid_topology_ai/termination.py.
Topology action and search control
The policy uses one stable action slot per branch plus stop/handoff. A branch action opens active branches or closes explicitly allowed inactive branches; legality is state-dependent and masked. MCTS uses neural priors/values, progressive widening, DC screening, and optional diagnostic continuation gating; the gate never rewrites executed actions or policy targets. Alternative beam planners support teacher/debug workflows. Core paths: grid_topology_ai/topology_actions.py, grid_topology_ai/action_space.py, grid_topology_ai/search/mcts.py, grid_topology_ai/search/dc_action_screener.py.
Neural training and replay
Generation records graph-state examples with MCTS visit distributions and required outcome value targets. Replay accumulates across iterations, then scenario-level—not row-level—train/validation splitting feeds checkpoint fine-tuning. Graph policy/value networks and normalization metadata are checkpoint contracts; fine-tuning retains parent normalization. Core paths: grid_topology_ai/self_play/generation.py, grid_topology_ai/self_play/replay.py, grid_topology_ai/models/graph_policy_value_net_v2.py, grid_topology_ai/training/graph_policy_value.py.
Evaluation, acceptance, and artifact integrity
Candidates are evaluated against fixed scenarios in primary ungated mode; constrained continuation results are diagnostic only. Metrics drive checkpoint selection and acceptance, with paired checks and fail-closed validation. State, replay, checkpoint, physics, and topology-action provenance prevent mixing incompatible artifacts. Caches reduce repeated exact/DC power-flow and structural-topology work. Core paths: grid_topology_ai/evaluation/checkpoint.py, grid_topology_ai/self_play/acceptance.py, grid_topology_ai/state_artifact_schema.py, grid_topology_ai/cache/exact_power_flow.py.
Main entry points: mcts.py Neural MCTS · pipeline.py Pipeline runner · environment.py Grid environment · graph_policy_value.py Checkpoint fine-tuning
Components 21
Self-Play Orchestration
- Self-play CLI · Runs the iterative generate-train-evaluate loop.
scripts/self_play/loop.py - Typed configuration · Defines pool, generation, replay, training, evaluation, and acceptance settings.
grid_topology_ai/config/self_play.py - Iteration plan · Creates resumable, fail-closed iteration work plans.
grid_topology_ai/self_play/plan.py - Pipeline runner · Coordinates generation, training, evaluation, and completion markers.
grid_topology_ai/self_play/pipeline.py
Grid Runtime
- Scenario store · Stores adapted fixed scenarios by scenario ID.
grid_topology_ai/runtime/scenario_store.py - Scenario adapter · Converts GridFM-style inputs to NumPy/PYPOWER-ready data.
grid_topology_ai/data_adapter.py - State builder · Builds versioned graph features and validates physical state inputs.
grid_topology_ai/state_builder.py - Grid environment · Resets with no-op AC flow and executes topology episodes.
grid_topology_ai/environment.py - AC power flow · Authoritative warm-started AC solver with reusable workspaces.
grid_topology_ai/pypower_backend.py - Physical objective · Separates physical success from episode termination.
grid_topology_ai/physical_objective.py
Search & Actions
- Topology action space · Maps stable branch slots plus stop/handoff to legal actions.
grid_topology_ai/action_space.py - Neural MCTS · Uses policy/value priors, progressive widening, and DC screening.
grid_topology_ai/search/mcts.py - DC action screener · Screens candidate actions before expensive search expansion.
grid_topology_ai/search/dc_action_screener.py
Learning
- Trajectory generation · Records graph states, MCTS visits, and outcome targets.
grid_topology_ai/self_play/generation.py - Replay store · Accumulates examples and splits train/validation by scenario.
grid_topology_ai/self_play/replay.py - Graph policy/value model · Produces action priors and state values under a checkpoint contract.
grid_topology_ai/models/graph_policy_value_net_v2.py - Checkpoint fine-tuning · Trains candidates while retaining parent normalization metadata.
grid_topology_ai/training/graph_policy_value.py
Evaluation & Integrity
- Checkpoint evaluation · Measures candidates primarily in ungated mode.
grid_topology_ai/evaluation/checkpoint.py - Candidate acceptance · Uses paired metrics and fail-closed validation to promote checkpoints.
grid_topology_ai/self_play/acceptance.py - Artifact provenance · Prevents incompatible state, replay, checkpoint, physics, and action artifacts from mixing.
grid_topology_ai/state_artifact_schema.py - Power-flow cache · Caches exact/DC power-flow and structural topology work.
grid_topology_ai/cache/exact_power_flow.py
Connections 30
- Self-play CLI → Typed configuration: loads
- Self-play CLI → Iteration plan: creates
- Iteration plan → Pipeline runner: drives iteration
- Typed configuration → Pipeline runner: configures
- Scenario adapter → Scenario store: adapts and stores
- Scenario store → Grid environment: supplies scenarios
- Scenario store → State builder: supplies raw state
- State builder → Grid environment: provides graph state
- Grid environment → AC power flow: runs AC flow
- AC power flow → Physical objective: provides solution
- Physical objective → Grid environment: reports physical success
- Topology action space → Grid environment: applies legal topology actions
- State builder → Topology action space: determines legality
- Neural MCTS → Topology action space: selects masked actions
- Neural MCTS → DC action screener: screens expansions
- Neural MCTS → Graph policy/value model: queries priors and values
- Neural MCTS → Grid environment: simulates trajectories
- Pipeline runner → Trajectory generation: runs
- Trajectory generation → Neural MCTS: uses
- Trajectory generation → Replay store: writes examples
- Pipeline runner → Checkpoint fine-tuning: runs
- Replay store → Checkpoint fine-tuning: provides scenario split
- Checkpoint fine-tuning → Graph policy/value model: fine-tunes
- Pipeline runner → Checkpoint evaluation: evaluates candidate
- Checkpoint evaluation → Candidate acceptance: provides paired metrics
- Candidate acceptance → Pipeline runner: promotes or rejects
- Artifact provenance → Replay store: validates provenance
- Artifact provenance → Checkpoint fine-tuning: guards checkpoint compatibility
- Power-flow cache → AC power flow: reuses results
- Power-flow cache → Neural MCTS: avoids repeated screening