Concepts to code¶
Paper ideas → the function that implements them. Pair with DATA_DICTIONARY.md.
Paths are under src/fdia_graph/; se/ and localization/ are under
analysis/src/fdia_analysis/.
One record, start to finish¶

Each frame of a timeline is one record. Its operating state is one frame of the pool. The clean
layer is Measurement.h of that state with no noise (Emitter.exact); the node layer
clean is the state itself. Emitter.emit_from_state adds each meter's bias and the
scan's jitter (NoiseModel), which gives the benign layer. On an attacked frame
AttackFrames.frame_from_state adds the attack vector on the meters it moves, which gives the
observed layer; on a benign frame the observed layer is the benign one. TimelineWriter.store
writes the three layers with the labels y, family and seq_id and the tamper masks.
An episode designed as a vector over the meters (VectorEpisode) uses
AttackFrames.frame_from_vector instead.
Layers and labels says what each layer and label is for.
Every attack is built in engine.attacks, by the parts the generator holds: a local false state
(engine.attacks.false_state) designed per episode (ramp_design for At, am_overload_design for
Am, engine.attacks.episodes) on a support the search or [WU26]'s row reduction chooses
(Minimizer.min_tamper, RrefSupport); AttackFrames.frame_from_state adds the attack vector to the
benign scan.
Modules¶
The paper's math lives in engine/. generation/ drives it in stages (TimelineSource.generate
is the one path of them for both grids, timeline.py its IEEE entry point), data/ turns load series into operating points (data/profiles.py the load profiles, data/ieee_pool.py the solve); se/ and localization/ analyze the
timelines; the rest load and serve data. What every file does, from its docstring, is
MODULES.md (generated by tools/layout.py); FORMULAS.md maps each formula
to its function.
| engine/ file | formula it implements |
|---|---|
core.py |
FdiaGenerator: grid + noise setup (__init__), attack targeting; holds one object of each part (measurement, loads, the attacks) |
measurement.py |
emit_from_state (a scan: Measurement.h, the measurement function h(x), with NoiseModel's noise), clean_flows_from_states, currents_from_states |
physics.py |
true_load, scan_generation: a scan's load and generation from its stored state |
attacks/ |
the false states, the fewest-tamper search, the At ramp and the overload Am |
One column order everywhere: the operating-state pool, node_x, and clean are all
[|V|, P_inj, Q_inj, theta]. Pools saved before 0.12 were P-first; generation.as_v_first detects
and converts them on load.
State estimation¶
| concept | code |
|---|---|
WLS x̂ = argmin (z−h(x))ᵀW(z−h(x)) |
se/base.py SEBase._w_solve (chord-Newton); h(x) is ac_measurement (analysis/src/fdia_analysis/formulas/measurement.py) |
| Robust reweighting (Huber), residual removal, subspace prior | se/methods.py: one class per arm, each overrides one hook |
Bad-data test r_i=(z_i−h_i)/σ_i, J=Σr_i² |
σ_i is the RMS of the benign residuals at the training truth (se/base.py SEBase.fit); residuals in se/base.py SEBase._nres. The stealthy flag marks the families that evade it by construction (Aq/At/Al/Am, constants.families.STEALTHY_FAMILIES) |
| Noise model | FdiaGenerator.SD (accuracy class): reading = true + per-meter bias + per-scan jitter. The estimator does not read it; it calibrates σ_i from data |
| Meter model (hybrid SCADA and PMU) | MeterPlan.from_placement (the angle at the PMU buses only; the generator's masks, a MeterLayers, are its masks) and the kinds IR and II of Measurement.h (the PMU branch currents I_f = Y_f V, I_t = Y_t V, formulas.network.branch_currents, noise formulas.noise.current_sigma); chosen by generate_timeline(..., redundancy={"meter_model": ...}) through models.config.MeterSettings |
PMU pseudo-measurements V_f = (I_n − y_nn V_n)/y_nf [WU26, eq. (3)] |
formulas.estimation.pmu_pseudo_links, pmu_pseudo_voltages (with the propagated variance), used by SEBase(solve=SolveConfig(pmu_pseudo=True)) in _build_pseudo and _z_of |
Walkthrough: ../guides/state_estimation.md. Results: ../analysis/estimation/README.md.
Attack families¶
| family | paper | build | code |
|---|---|---|---|
| At | A_t |
slow ramp, 0.2 percent per frame, a local false state per frame | engine/attacks/episodes.EpisodeDesigns.ramp_design + EpisodeDesigns.ramp_step |
| Am | A_m |
the overload attack of [WU26]: a line's reported flow driven to its rating over the window, the fewest devices tampered | engine/attacks/episodes.EpisodeDesigns.am_overload_design + overload.overload_step |
- At and Am are local false states: the buses around the attack are re-solved with the boundary
voltages held true, inside the case's voltage limits and the region's generator limits, and the
attack vector
h(x') − h(x)is added to the benign scan. The residual test flags them at the benign rate by construction. Both satisfy equations (13)-(23) of [WU26] (the SCADA measurements, the PMU voltage magnitudes, angles and branch currents, and the operating limits).Amalso drives a line's reported flow to its rating, eqs. (24)-(25) (by default 1.25 times its peak pool flow), on the support that tampers the fewest devices, eq. (12);Atis held on that support whenmin_tamper=True(the default), else on the region withinhops(../concepts/attacks.md). The single-snapshot families of older releases (Aq,Al, and the in-placeAd,As,Ar) are read-only: fdia-graph 0.20 generates them. - With
min_tamper=Truean At episode is held on the support that tampers the fewest devices over the episode, the objective of [WU26, eq. 12] (engine/attacks/minimize.Minimizer.min_tamper, called byengine/attacks/episodes.EpisodeDesigns.ramp_design). - The At ramp moves in per-frame steps under the noise floor, by design.
Temporal feature¶
| field | meaning | built in |
|---|---|---|
temporal_delta |
scan-to-scan [ΔP, ΔQ] of the observed frames |
generation.write.TimelineWriter.write_temporal_layers (formulas.temporal.temporal_delta) |
swing |
temporal_delta as a z-score of the recent observed change |
generation.write.TimelineWriter.write_temporal_layers (formulas.temporal.swing_zscore, scale from recent_change_scale) |
Both layers are written after the walk from the observed injections only, so a detector reads what an operator sees.
Any above-noise attack spikes the swing, so localization is per-bus and needs no graph. The slow ramp
At stays inside the swing, so it is the open case.
The papers' per-bus feature vector and localizers¶
| concept | code |
|---|---|
14-dim per-bus vector: [|V|,P,Q,θ] + meter mask + partial KCL residual + temporal_delta + swing |
localization/learned.py full14, kcl_residual |
| standardize all 14 channels on train (sd floored at 1e-3) | LearnedLocalizer._fit_stats |
| 1-D CNN across the bus axis (best localizer) | BusCNN |
| per-bus MLP (lightweight arm) | BusMLP |
| validation-best global threshold on a 0.05..0.95 grid | LearnedLocalizer.tune_threshold |
Metrics¶
| metric | definition | code |
|---|---|---|
| node precision / recall / F1 | micro over every (record, bus) pair | localization/base.py LocalizerBase.score |
| per-sample macro-F1 | F1 per record, averaged | same |
| strict localization accuracy | predicted attacked set equals the truth exactly | same |
| DR with FA | detection rate, always reported next to the benign false-alarm rate | same |
| localization macro-F1 | per-bus F1 averaged over the active buses, those attacked somewhere in the records scored (the papers' headline) | LocalizerBase.score(...)["all"]["macro_f1"]; also EXAMPLES.md macro_f1 |