0

N1 Contingency Dispatch

Fresh

N-1 security-constrained DC-OPF RL environment: the dispatch must survive every non-islanding single-line outage at emergency ratings. The plain OP...

Type
RL Env
Publisher
Jwilksbooth
Runtime
single-turn
License
mit
Size
v0.1.0
Published
Jul 2026

Cite

Notes

Only stored in your browser.

n1-contingency-dispatch

N-1 security-constrained DC-OPF RL environment. Fourth rung of a power-systems vertical (economic-dispatchdcopf-grid-verifiersmultiperiod-dispatch → this). The skill axis is security: the dispatch must survive the outage of any single non-islanding transmission line, with post-contingency flows within emergency ratings. The naive answer this environment defeats is precisely the previous congestion environment's correct answer — the ordinary DC-OPF optimum, which leans on fully-loaded corridors that have no margin left when a parallel line trips. Measured: 68% of instances make the plain OPF optimum insecure.

Task

Given a meshed network (lines with reactance, normal rating, emergency rating), generators, and loads: output {"dispatch_mw": [...]} minimizing cost such that (1) the base case is feasible at normal ratings, and (2) for every single-line outage that leaves the network connected, the same dispatch remains feasible after DC power flow reroutes — every surviving line within its emergency rating (preventive SCOPF).

Ground truth validation

Two independently formulated solvers must agree — different variable spaces and different algorithms:

  • Primary: monolithic security-constrained LP in angle space — variables [P, θ⁰, θ¹…θᴷ], one angle block per contingency state (scipy/HiGHS).
  • Cross-check: injection-space solver using per-contingency PTDF matrices and iterative constraint generation (solve, find violated contingency constraints, add as cuts, repeat), written from scratch with no shared assembly code.
Metric (200 instances, seeds 0–199)Result
Objective mismatches (>0.1% rel and >$1/h abs)0 / 200
Worst relative objective gap1.4e-14
Constraint-generation non-convergence0 (test fails if >2%)
Plain N-0 OPF optimum insecure (violates ≥1 contingency)135 / 200 (68%)
Median security premium (binding subset)5.2%
Mean non-islanding contingencies per instance~9

Rewards (weighted rubric)

RewardWeightDescription
reward_format0.10Parseable JSON, correct arity, finite values only
reward_base_feasibility0.20Positive-proof: balance, gen bounds, base flows at normal ratings
reward_security0.25Fraction of contingencies survived at emergency ratings (gated on base feasibility)
reward_optimality0.45`exp(−5·

Anti-reward-hacking, factory standard (6 regression-tested attack gates): the insecure-cheap attack (submitting the plain OPF optimum — cheaper and base-feasible — earns optimality 0.0), NaN/Infinity literals, >4300-digit integers and bracket bombs (rejected, never crash), and tolerance-rent (violations inside the ±0.5 MW grading tolerance settled at 2× the highest offer, below-optimum cost penalized symmetrically).

Usage

pip install -e .
N_INSTANCES=200 python tests/test_validation.py   # dual-formulation cross-check + attack gates
python calibration/measure.py --n 300             # difficulty distribution sweep

# give frontier models room to reason; -r 1 matches published baselines
vf-eval n1-contingency-dispatch -p anthropic -m <model> -n 50 -r 1 --max-tokens 16000
import verifiers as vf
env = vf.load_environment("n1-contingency-dispatch", num_examples=300)
# disjoint train/eval: load_environment(1000) + load_environment(200, seed_offset=1000)

Instance generation

Meshed random networks (spanning tree + loops, 4–8 buses, extra-edge probability 0.35 — N-1 only bites where parallel paths exist), tiered baseload/mid/peaker costs, ~9 non-islanding contingencies per instance. Line ratings are anchored to duty: normal ratings to each line's flow under a nominal proportional dispatch (tight draws at 1.05–1.35×, loose at 1.8–3×), emergency ratings to the line's worst N-1 duty (tight 1.02–1.20×) — so ratings correlate with usage the way real thermal ratings track expected duty, and the nominal dispatch is N-1 secure by construction (draw rejection 7.7%, no survivor bias; see CALIBRATION.md for the two rating constructions the metrics rejected). Non-islanding screening only, as in real N-1 practice for radial taps. Fully deterministic per seed.

The vertical

merit order → congestion (space) → ramps (time) → N-1 security (uncertainty). Next: LMP/nodal pricing verified against LP duals.