Modules¶
What every folder of the repository holds, then what every Python file does, in one line: the first paragraph of its docstring. Generated by tools/layout.py; edit the docstring (or REPO and DOCS in the tool), not this page. A toolkit's section names each file by its module under the toolkit's package: dataset.base is src/fdia_graph/dataset/base.py, se.base is analysis/src/fdia_analysis/se/base.py.
The repository¶
| folder | what it holds |
|---|---|
src/ |
the generation toolkit, the package fdia_graph (the distribution fdia-graph): generating a timeline and loading it |
analysis/ |
the analysis toolkit, the package fdia_analysis (the distribution fdia-analysis, which depends on fdia-graph): state estimation, localization, federated training, trust selection and the results store's code, with its own pyproject.toml, src/ and tests/ |
tests/ |
the generation toolkit's test suite, and the helpers both suites share (their shared fixtures are in the root conftest.py) |
examples/ |
scripts a user copies: the quickstart, the training examples, the New York extension points |
results/ |
the results store: data only (one CSV per experiment and runs.csv), with the queries the docs read it through |
pipelines/ |
the builds of released data: the New York pool and timeline, and the MATLAB reference they are checked against |
tools/ |
repository tooling only: the gates, the generated docs, pull requests and releases |
docs/ |
the documentation, one folder per kind of page |
docs/getting-started/ |
tutorials: load a dataset, generate one, analyse one, each start to finish |
docs/guides/ |
how to do one task |
docs/concepts/ |
explanations: how a part is built and why |
docs/analysis/ |
one page per study with its figures: what was measured, on what, and the result |
docs/reference/ |
facts to look up: the file map, the data dictionary, the glossary, the formulas, the references |
docs/figures/ |
the images pages share, each with its data or its diagram source |
docs/stylesheets/ |
the docs site's stylesheet: the display width of the phone diagrams |
.github/ |
the CI workflows and the dependency updates |
The generation toolkit, fdia_graph¶
| file | what it does |
|---|---|
fdia_graph |
fdia-graph: load and generate datasets for locating false data injection attacks on a power grid. |
constants |
The toolkit's constants, one module per subject: facts only, each with its unit and its source. |
constants.channels |
The column of each quantity on the last axis of a measurement array: node_x[..., NodeChannel.P_INJ]. |
constants.families |
The attack families: the code a file's data/family column carries for each, and the named subsets. |
constants.files |
The names and layouts of the files around a timeline: the unfinished file, the index of local datasets, and an operator's load export. A timeline file's own names are in schema.py. |
constants.grid |
The power systems: the IEEE cases the toolkit builds, the bus types and the "no limit" ratings. |
constants.meters |
The meters: their kinds, their accuracy classes and noise floors, and where each kind's reading sits in a timeline file. |
constants.newyork |
The New York grid: NYISO's zones and neighbors, the fields of the case file, the pinned inputs and their addresses, NYgrid's dispatch numbers, the fitted load model and the operating rules. |
constants.numerics |
The fixed numerical tolerances and finite-difference steps of the algorithms. |
constants.records |
The fields of a record, by group: the names a record, a batch and an export carry, in their order. |
constants.releases |
The data releases: where the built-in datasets are published, which release is pinned, and the sha256 of every asset of the releases the registry verifies. |
constants.streams |
The keys of the random streams a timeline draws from. Each stream is seeded with the timeline's seed, a key below and a position, so a draw of one kind never shifts a draw of another. The keys are arbitrary and fixed: a different key gives a different file. |
constants.time |
Time: the calendar, the New York frame, and how a load profile is correlated from scan to scan. |
data |
Where the load data and the operating points come from, for every test system. |
data.config |
Build settings and the one place random generators are made. |
data.dispatch |
Hourly unit dispatch, NYgrid's allocation of the NYISO fuel mix to the fixed unit list. |
data.ieee_pool |
The pool of an IEEE case: one AC operating state per step of a load profile. |
data.inputs |
Historical inputs: NYgrid's hourly 2019 tables and NYISO's 5-minute zonal load, and fetch_inputs, which downloads everything the build reads at its pinned version. |
data.ipopt |
The optimization solver every OPF of the New York grid runs on, found and checked in one place. |
data.ipopt_solver |
The package's own OPF engine: one polar AC-OPF model of a Case in Pyomo, solved by Ipopt. |
data.load_sources |
Where the bottom-up load profiles come from ([LI21]), each downloaded once into a cache: the NREL ResStock and ComStock county profiles, each utility's EIA-861 sector sales, the census county centroids and the IAC industrial plants, with the clock rules the plants run on. LoadModel (loads.py) builds the bus profiles from these. |
data.loads |
Per-bus load profiles by the bottom-up method of [LI21], scaled to the real zone load. |
data.pandapower_solver |
pandapower as a solve engine of a Case: its Newton AC power flow and its interior-point AC OPF. |
data.pool |
The pool: one AC operating state per 5-minute frame, from a ramp-constrained real-time dispatch, and the pool file of the build, HDF5. A timeline is written by the writer every grid uses (fdia_graph.generation.write) and read through fdia_graph.dataset. |
data.profiles |
Load profiles: a real load time series as a load-scaling vector, read from a file or fetched from an operator's feed. |
data.solver |
The AC solves of a Case, behind one interface with two engines. |
dataset |
FdiaGraph: a PyTorch-ready dataset over one HDF5 file, a timeline (one row per frame in time order, kind="timeline"). |
dataset.base |
The loader's shared state and the constants its concerns read. |
dataset.clients |
The timeline as federated clients: each utility sees only its own meters, buses and labels. |
dataset.export |
A whole split at once: summary, and the arrays/tensors/frames of every kept record. |
dataset.graph |
The static graph of a shard: connectivity and the per-branch and per-bus physics, as tensors. |
dataset.physics |
The admittance matrices built from the static graph, and the clean power flow on every branch derived from the clean state through them. |
dataset.records |
One record at a time: unit conversion, __getitem__ in dict/PyG form, collate, and a ready DataLoader. |
dataset.sequence |
The timeline as sequences: sliding windows over a time-ordered view, and the episode table. |
download |
Fetch the built-in datasets from the GitHub Release and cache them under ~/.cache/fdia_graph. |
engine |
The generation engine — the math/physics/theory half of the SDK, behind fg.generate(). |
engine.attacks |
Every attack the generator builds, one line per file. |
engine.attacks.area |
Given seed buses, the attacker's area and the boundary of any set of buses. |
engine.attacks.blas |
One BLAS thread for the length of a search (one_blas_thread). |
engine.attacks.episodes |
The design of one episode (EpisodeDesigns): At's drawn at its onset, Am's from its window. |
engine.attacks.false_state |
Given a true state, a support and a goal, the false state: the support's voltages re-solved with every other voltage true, inside the limits. |
engine.attacks.family |
What the timeline asks of any family, and the base of a family of your own. |
engine.attacks.frames |
Given a true and a false state, the attack vector a = h(x_false) - h(x_true) and the frame that adds it to the true scan. |
engine.attacks.minimize |
The search: the area first, then supports grown from the goal's buses, smallest first, the cheapest of at most min_budget [WU26 eq. 12]. |
engine.attacks.overload |
Am's inputs and frames: ratings, eligible lines, the flow schedule of [WU26 eqs. 24-25], one frame. |
engine.attacks.ramp_frames |
One At frame: the false state of the frame's AttackDesign, written as a frame. |
engine.attacks.rref |
The other way to choose a support: [WU26]'s row reduction of the transposed area Jacobian. |
engine.attacks.search |
At and Am as families: how EpisodeDesigns, RampFrames and Overload are called frame by frame. |
engine.attacks.window |
What one candidate support costs over a window (AttackWindow.cost). |
engine.base |
A part of the generator: one job (emitting scans, choosing an area, solving a false state, ...) as one class that holds the generator it belongs to. |
engine.core |
The generator: the grid, the meter plan, the load table, the case limits, and one object per part. |
engine.measurement |
The readings of a stored state: exact, then with bias and jitter, laid out per bus and per branch. |
engine.physics |
How a stored load-positive injection divides into load and generation. |
errors |
Every error the package raises on purpose, defined in this one module. |
formulas |
The mathematics of the generation toolkit as named, pure functions: numpy in, numpy out, no files, no dataset objects, no torch. Each function carries its equation and a source key from docs/reference/REFERENCES.md; docs/reference/FORMULAS.md is the catalogue. Import a formula from its module (formulas.network, formulas.noise, formulas.attacks, formulas.temporal, formulas.trust). The formulas of estimation, localization, federated training and trust selection are the analysis toolkit's (fdia_analysis.formulas). |
formulas.attacks |
Attack shapes defined by the dataset [DAT26] that are pure functions of their parameters. |
formulas.network |
The AC network model: branch admittances, bus injections and branch flows [AE04, ch. 2], [MP19]. |
formulas.noise |
The meter error model: the standard deviation an accuracy class gives a reading [ASP14]. sensing.noise.NoiseModel splits a class into a constant per-meter bias and a per-scan jitter (ours) and draws both. |
formulas.temporal |
The temporal features of a scan [FED26]: the one-step injection change and its z-score against the bus's typical recent change, and the recent-change scale itself. |
formulas.trust |
Row reduction for stealthy attacks under trusted meters [WU26]: the reduced row echelon form of a matrix, and the sparsest rows of a row space, which the attack generator searches for an attack vector the trusted meters leave open. |
generation |
generate(system, name, **knobs) — build a custom dataset and register it as name. |
generation.design |
The design stage of a timeline: every placed episode of a split gets its design before the split is walked, from its family (engine.attacks.family.EpisodeFamily.designed). |
generation.emit |
The emit stage of a timeline: every frame in time order, benign or under its episode's design. |
generation.ieee |
An IEEE case by its name as the source of a timeline: the original generator (generation.search.SearchSource) on the case's network and its pool of operating points. |
generation.plan |
The plan stage of a timeline: where its splits are cut and where each split's episodes go. |
generation.search |
A test system as the source of a timeline, the original generator: coverage meters and the search-based designs, on any grid. |
generation.source |
The one source of a timeline: a grid, its pool of operating points, and the path that generates it. |
generation.write |
The one writer of a timeline file, for every grid: TimelineWriter owns the open HDF5 file. |
models |
Every data model of the generation toolkit, one module per subject; import a model from its module. |
models.assets |
How files are found: where a dataset comes from and where its bytes are fetched from. |
models.base |
Bundle: a typed record that is also a dict. |
models.choices |
Every argument that takes one value from a fixed set, in one place. |
models.config |
The settings every consumer accepts, one model each, checked when built (models.validation). |
models.data |
What a user gets back: one record, a batch, a whole split, a summary and the episode table. Each is a Bundle, so it is also a dict. |
models.fields |
The fields the record bundles share, each one's meaning written once. |
models.frames |
The records the attack code passes around: a scan, a frame, an attack vector, a goal, a design, the operating limits, a search result. |
models.grid |
The static description of a system (the per-branch pi model and the admittance matrices built from it, which never change from one scan to the next) and one solved operating point of it. |
models.inputs |
What the formulas and the parsers accept, one model each, checked when built (models.validation). |
models.plan |
The records of a timeline's plan and design stages: a placed episode (Slot), a split and its frames (SplitSpan), a placed episode on its way through the design stage (Planned), the attack as it is written (Episode, EpisodeRecord), what the placement asked for and got (Placement), and what a design worker rebuilds its generator from (GeneratorSpec). |
models.validation |
The one place inputs are checked (CONTRIBUTING.md, "an input is checked in one place"). |
ratings |
Branch thermal ratings for the overload attack of [WU26] (eqs. 24-25), stored with the package. |
registry |
The dataset registry: the built-in (downloadable) datasets and the locally generated ones. |
schema |
The file protocol: every group, dataset and attribute name an fdia-graph HDF5 file carries, defined once. The writer (generation) and the readers (dataset) agree through these names; tools/readability.py refuses a path-shaped literal ("data/...", "graph/...") in any other module. Field names (node_x, clean, ...) stay as words in the code; FIELD_PATH maps them to paths. |
sensing |
The meters: what each client measures, and how wrong each meter is. |
sensing.measure |
The measurement function: the meter readings a grid state gives, and their derivatives. |
sensing.meters |
The meter plan: every meter of a grid as one row of a table, with its owner and accuracy class. |
sensing.noise |
Meter noise: the accuracy class of each meter split into a constant bias and a per-scan jitter. |
systems |
The test systems: a grid as a Case with its Network, whichever grid it is. |
systems.case |
The grid as one frozen record of arrays, read from a MATPOWER case file or from a pandapower net. |
systems.fixes |
Two variants of a case, applied when one is asked for: the external areas held at the base load, and NYgrid's HVDC links in place of the AC branch 81-125. The changes every build has (zone J's split, the 765 kV line) are in the case file itself (case.py reads it). |
systems.network |
Admittances of a Case, built once, and the AC quantities they give for any state, from the SDK's network formulas (formulas.network). |
systems.ownership |
Federated clients: each NY bus belongs to the electric utility whose service territory holds it. |
systems.pandapower_types |
The pandapower objects the package reads, as types. |
systems.states |
The pool of operating points a timeline walks, one frame per point: an array [T, N, 4] in memory, or PoolStates, which keeps a year of solved voltages as they are and gives a frame's state when it is asked for. |
systems.tables |
The CSV tables of the inputs, read whole and closed: the NYgrid checkout's bus, unit and renewable tables and the bus locations. One reader, so no input file is left open. |
timeline |
One continuous attacked timeline per system, written as one HDF5 file. |
The analysis toolkit, fdia_analysis¶
| file | what it does |
|---|---|
fdia_analysis |
fdia-analysis: what is measured on an fdia-graph timeline: state estimation, attack localization, federated training, trusted-meter selection, and the store the measured results are kept in. |
federated |
Federated training over K clients (utilities) that never pool their records [FED26]. |
federated.aggregate |
Averaging torch state dicts across clients with formulas.federated.fedavg [MCM17]. |
federated.localizer |
Federated per-bus localizers: the paper's BusMLP and BusCNN trained by FedAvg over K clients [MCM17], [FED26], with records never leaving a client. |
federated.partition |
The split of a system's buses into K clients (utilities) for federated training [FED26]. |
federated.se |
Federated fitting of the state estimator's learned part [EST26], [FED26]. |
formulas |
The mathematics of the analysis toolkit as named, pure functions: numpy in, numpy out, no files, no dataset objects, no torch. Each function carries its equation and a source key from docs/reference/REFERENCES.md; docs/reference/FORMULAS.md is the catalogue. The network model, the meter noise and the attack shapes are the generation toolkit's (fdia_graph.formulas). Import a formula from its module (formulas.estimation, formulas.federated, formulas.linalg, formulas.measurement, formulas.metrics, formulas.projection, formulas.trust). |
formulas.estimation |
Weighted least squares state estimation and its robust variants, one function per equation [SCH70], [HAN75], [HUB64], [EST26]. |
formulas.federated |
Statistics that combine across federated clients without moving their records [FED26]. |
formulas.linalg |
Numerical linear algebra the estimators lean on: a guarded inverse of a normal matrix, its condition number without an eigen-decomposition, and per-record normal matrices in sub-batches. |
formulas.measurement |
The estimator's AC measurement function h(x) and its closed-form Jacobian [AE04, ch. 2], [MP19], assembled from the network model the generator and the loader use (fdia_graph.formulas.network: bus_injections, branch_flows). The estimator's torch twin (se.base.SEBase._h_t) is kept for callers that differentiate through it; analysis/tests/test_formulas.py pins it to the functions here. |
formulas.metrics |
Per-bus localization metrics from confusion counts, so they can be summed across clients or thresholds before any ratio is taken [KEC25]. |
formulas.projection |
Projections through the measurement Jacobian: the explained and unexplained parts of a measurement change, leverage, the weak directions, and the meter-to-bus aggregation of the Jacobian-informed features [JAC26], [HAN75]. |
formulas.trust |
Trusted-meter selection against stealthy attacks [WU26]: the attack subspace a secured set leaves open, the cost of the cheapest attack in it, and the greedy selection that closes it. |
localization |
Per-bus FDIA localization on fdia-graph datasets, sklearn style. |
localization.base |
Per-bus FDIA localization on fdia-graph datasets — the shared machinery behind every method class. |
localization.learned |
Learned per-bus localizers: the graph-free encoders that gave the best localization numbers in the federated localization paper, on that paper's 14-dim per-bus feature vector. |
localization.methods |
The localizer method classes. Each changes exactly one thing about LocalizerBase — the per-bus score — so a difference between two arms is a difference between detection signals, not between calibration or metrics code. |
models |
Every data model of the analysis toolkit in one place: the ones only the estimators, the localizers, the federated trainers, the trust selectors and the results store use. A model the generation toolkit also uses is in fdia_graph.models, and is imported from there. |
models.choices |
The fixed sets the analysis settings choose from, beside fdia_graph.models.choices (its Choice is their base): a member is its string value, and a settings model declares a field's set as Annotated[str, OneOf(Features)]. |
models.config |
The settings the estimators, the localizers, the trust selectors and the federated trainers accept, one model each, checked when built by the validation engine of fdia_graph.models.validation. |
models.data |
What the analysis packages hand back that is neither a score table nor a setting: the truth an estimator is scored against. |
models.federated |
What the federated layer passes around: how the buses split into clients. |
models.grid |
The pseudo-measurement records of the estimator's PMU current channels [WU26 eq. 3]: where a pseudo voltage phasor can be placed, and the phasors with their propagated noise. |
models.inputs |
What the analysis formulas accept, one model each, checked when built by the validation engine of fdia_graph.models.validation. |
models.results |
The models of a results table: the metric registry, a Record (one measured value with the keys that say what it is) and a Provenance (which run made it), plus the parsers that read loose input (a nested score report, a filter value, a run's settings) by its type. Every check lives here, per the validation rule, so a store never holds an unknown metric, a non-finite value or a malformed key; fdia_analysis.results builds these models and never checks its input itself. |
models.scores |
The result tables: an estimator's error pair per record class, a localizer's metric rows per class, and the Jacobian feature outputs. Each is a Bundle, indexable by family name as before. |
models.training |
What the learned localizers pass between their fitting pieces (a centralized fit and a federated client share them). |
results |
Measured results as data: typed records with their provenance, one tidy store, and the renderers that put the numbers into docs and figures, so no measured number is typed by hand. |
results.docs |
Measured numbers in markdown come from the store, never from a keyboard. |
results.render |
Turning records into what a reader sees: a formatted cell, a markdown table, a pivot of records by two keys, and the CSV sidecar a figure is drawn from. Nothing here measures or stores anything. |
results.run |
How a harness records what it measured: open a Run, add values, and the run writes them to the store with its provenance when it closes. |
results.store |
The results store: one tidy CSV per experiment plus one table of runs, in a folder kept in git. |
se |
State estimation on fdia-graph datasets, sklearn style. |
se.base |
State estimation on fdia-graph datasets — the shared machinery behind every method class. |
se.detect |
Detection: when a detector alarms, as a building block. |
se.detect.rules |
When a detector alarms: the rule that turns a statistic per scan into a first alarm. |
se.jacobian |
Jacobian-informed features (Abdulin & Narimani): the measurement Jacobian as a physics transform of the scan-to-scan measurement change, not as raw model input. |
se.methods |
The estimator method classes. Each changes exactly one thing about SEBase, so a difference between two arms is a difference between estimators rather than between implementations. |
trust |
Which meters to trust so that stealthy attacks stop being stealthy [WU26], sklearn style. |
trust.base |
The shared machinery of the trusted-meter selectors: the measurement Jacobian at the benign mean (from a WLS estimator of fdia_analysis.se), the attack-cost kernel, and the scoring that pins the secured meters and asks the residual test whether the attack shows. |
trust.meter_dqn |
The trusted-meter selection as a Markov decision process solved by a deep Q-network (the learned selection of [WU26]). |
trust.secured |
A copy of a timeline with a set of meters secured: the attacker locked out of them, so on every frame their observed reading is the benign one, and the stored temporal features recomputed from the pinned observed frames (generation.write.TimelineWriter.write_temporal_layers). The estimators and the localizers then read the copy like any timeline, which is how a trusted-meter selection is measured on state estimation and localization rather than on the residual test alone (TrustSelector.score). The copy is rewritten in blocks of frames, so a 72,000-frame timeline of any ladder system fits in bounded memory. |
Tools¶
| file | what it does |
|---|---|
tools/bench.py |
Time the estimators and the generator on the tiny timeline, and store the timings as a run of the bench experiment in the results store (results/bench.csv), where docs/reference/BENCHMARKS.md renders them from (a results block). |
tools/class_diagrams.py |
Write the class and module diagrams of the two toolkits (fdia_graph and fdia_analysis) from their source, as Mermaid sources under docs/figures/diagrams/, so the pictures in docs/reference/CLASS_MAP.md never drift from the code. |
tools/count_lines.py |
Count the lines of the two toolkits: all lines, code lines (no docstring, comment or blank line), and the code inside and outside the homes of constants (constants/ and schema.py). |
tools/layout.py |
The repository's layout rules, and the file map they keep current (docs/reference/MODULES.md). |
tools/models_doc.py |
Render the public data models into docs/reference/DATA_DICTIONARY.md. |
tools/pr.py |
Pull requests from the command line, without the gh CLI (CONTRIBUTING.md, "The pull request"). |
tools/prereview.py |
Every check a pull request must pass, for both toolkits of the repository (fdia_graph and fdia_analysis, sources.PACKAGES), run locally in one command before the review is requested (CONTRIBUTING.md, "The pull request"). |
tools/readability.py |
Readability measures for the two packages (fdia_graph and fdia_analysis, sources.PACKAGES), the limits below (LIMITS), and the file-protocol rule: a dataset path ("data/...", "graph/...", any group of schema.Group) or a group name used as one (f.create_group("data"), f["attack"], "episodes" in f) may be spelled only in src/fdia_graph/schema.py; every other module goes through schema. And the validation rule (CONTRIBUTING.md, "an input is checked in one place"): raise ValueError / raise TypeError and isinstance(...) only inside a models package (fdia_graph.models, fdia_analysis.models), where the one engine checks every input and the parser models read loose input by its type; everywhere else an input is checked or parsed by building its model, and a condition only the data reveals raises a named error from errors. And the typing rule: an annotation says Any only where ANY_ALLOWED lists it with the reason the value can be anything; every other annotation carries its real type. |
tools/release.py |
Cut a package release after the version-bump PR has merged (CONTRIBUTING.md, "Releasing"). |
tools/render_mermaid.py |
Render a Mermaid source file to a standalone SVG and a PNG next to it. Every diagram in the docs is such a rendered image, because the README is also the PyPI page and the docs are read in the GitHub mobile app, and neither renders a Mermaid block. |
tools/results_docs.py |
Fill and check the results blocks of the docs from the results store (results/). |
tools/site_index.py |
Stage the three root pages of the repository for the docs site: README.md becomes docs/index.md, CONTRIBUTING.md docs/contributing.md and CHANGELOG.md docs/changelog.md. The README is the single source for the landing page; its links carry a docs/ prefix that is wrong once the file lives inside docs_dir, so the prefix is stripped on copy, and links between the three root pages are rewritten to their staged names. The README's leading <picture> (the logo, switched by the reader's system theme) is left out of the landing page: the site's header carries the logo, and the site's own light and dark switch would not move the picture. Runs in the Vercel build (vercel.json) and in the versioned deploy (.github/workflows/docs.yml); the three staged files are generated output and stay untracked. |
tools/sources.py |
Where the repository's two toolkits live, said once for every tool: the generation toolkit fdia_graph and the analysis toolkit fdia_analysis, each a package under its own source root. |
tools/upload_assets.py |
Publish data-release assets to a GitHub release (CONTRIBUTING.md, "Releasing", data releases). |
The generation toolkit's tests¶
| file | what it does |
|---|---|
tests/case_studies.py |
[WU26]'s case studies as test inputs: the lines each scenario overloads, its PMU buses and the attacker's area, in MATPOWER bus numbers, their positions in a generator's grid, and the paper's own measurement noise. |
tests/digests.py |
Whole-file digests of a generated HDF5 file: the proof that a refactor did not move a number. |
tests/helpers.py |
The plain helpers the two test trees share (tests/ and analysis/tests/): where the checkout's parts are, the tiny timeline's recipe, the old releases' files, and the checks both toolkits hold their own package to. The fixtures are in the repository root's conftest.py. |
tests/nygrid/inputs.py |
The inputs of the nygrid tests in one place, and which tests each one lets run. |
tests/nygrid/test_any_case.py |
The New York grid is a test case of the original generator like any IEEE case: coverage meters and the search-based designs on the packaged case file and the checked-in days' pool (no solver, no NYgrid data), through SearchSource.for_pool. tests/test_any_case.py has the IEEE side. |
tests/nygrid/test_case_file.py |
Case.from_matpower on a three-bus case file written here: what it reads and what it refuses. Needs no input data. |
tests/nygrid/test_dataset.py |
A timeline read back as clients (dataset.clients): with the Ownership of the buses the source gives each meter to the client of its bus, and the file reads as one view per client and one for the operator. On the packaged New York case with made-up clients and the checked-in days' pool: no NYgrid data, no solver. |
tests/nygrid/test_examples.py |
The extension examples of docs/guides/extending.md run as published, so the guide never shows code that broke (no data needed). |
tests/nygrid/test_grid.py |
The New York grid's case file: what it holds, its exact round trip through the MATPOWER reader and writer, the recipe that made it from NYgrid, the two case variants and the utility of each bus. |
tests/nygrid/test_public.py |
The public surface of the New York code: every module of its packages imports, a package exports no name of its own, and reading a dataset stays light (no data needed). |
tests/nygrid/test_scenario.py |
The hourly operating points against NYgrid's own MATLAB output: the inputs, the dispatch, the AC projection and the pool, and the bottom-up load profiles with their within-hour calibration. |
tests/nygrid/test_sensing.py |
The meter plan on the New York case and its readings: each meter owned by the client of its bus, the measurement Jacobian against finite differences, observability and the meter noise. On the packaged case file with made-up clients: no NYgrid data. |
tests/nygrid/test_solve_engines.py |
The two OPF engines against each other: the package's (Pyomo and Ipopt) and pandapower's, on the same case, loads and costs. Also the choices the New York pool refuses. The comparisons read no NYgrid data and are skipped where Ipopt cannot start. |
tests/nygrid/test_solvers.py |
The checked Ipopt every OPF of the New York grid runs on: a solver that is missing, or found but unable to start, raises SolverUnavailable with the fix, instead of reading as an infeasible model downstream. |
tests/nygrid/test_tables.py |
The input tables are read whole and closed: no ResourceWarning, a byte-order mark dropped (no data needed). |
tests/test_any_case.py |
The per-case choices are settings of the one source: each works on any case whose data allows it, and is refused with the reason where the data is missing. The New York grid's side of these tests is in tests/nygrid/test_any_case.py. |
tests/test_attack_area.py |
The attacker's area [WU26] Sec. III-A and the window ratings of the overload attack: the paper's own area where it states one, the area its four principles pick otherwise (rules 1 and 2 as checks, 3 and 4 as a score of ours), the "delta" ratings matched to its Fig. 4 magnitudes, and the validity of every attack the search returns (the goal met, every untampered channel within its noise, trusted buses true). |
tests/test_edges.py |
The public edges: wrong arguments fail early with a message naming what is allowed, and the filters mean what the docs say. The other test files prove the happy path; this file is the rest. |
tests/test_formulas.py |
The generation toolkit's formulas: each function on a case small enough to check by hand. The analysis toolkit's formulas, and the estimator's torch measurement function pinned to the numpy kernel here, are checked in analysis/tests/test_formulas.py. |
tests/test_ieee_case.py |
An IEEE case as a Case: Case.from_pandapower against the pandapower net it reads, what it refuses, and the Network admittances against pandapower's makeYbus on the same net. |
tests/test_loader_timeline.py |
fg.load on a timeline file: the record table and the timeline from one file, order, the benign layer on records, batches and exports, ds.windows and ds.episodes. Uses the timeline fixture of conftest. |
tests/test_malformed_inputs.py |
A malformed setting or argument is a ConfigError, never a raw TypeError, KeyError, ValueError or IndexError from deeper in the code (docs/reference/REVIEW_CHECKLIST.md, item 4). |
tests/test_minimize.py |
The fewest-tamper support search [WU26 eq. 12]: exact against brute force on IEEE-14, a lower bound that never exceeds a cost, the two sigmas (the emitter's per-scan jitter, the meters' accuracy class the search counts against), and a continuous reweighted-l1 cross-check the search is never beaten by. |
tests/test_models.py |
Bundle, the dual-access base of the typed records: every dict use the package's callers rely on must keep working, and the attribute view must agree with it. |
tests/test_models_doc.py |
The models section of the data dictionary is generated from the dataclasses; this keeps it so. |
tests/test_models_package.py |
Every data model of a toolkit lives in its models package: they are defined nowhere else, each is imported from the module that defines it, and the package's own modules depend on nothing but numpy, the standard library, the named errors (fdia_graph.errors) and the constants (fdia_graph.constants, which imports nothing of the package). The checks are functions of the package (tests/helpers.py), so the analysis toolkit holds its own fdia_analysis.models to them (analysis/tests/test_models_package.py). |
tests/test_namespace.py |
The package namespace: the heavy helpers resolve lazily to the real functions, so their docstrings and signatures cannot drift from a wrapper's, and import fdia_graph stays light. |
tests/test_old_releases.py |
The pinned data releases stay readable. The generator makes only At and Am, but a timeline of each of v0.8.0, v0.8.1 and v0.8.3 loads, splits, filters by family name and scores per family as before; the record shards and stream files of the releases before v0.8.0 are refused. Each fixture under tests/data was written by the SDK that built its release, or is a slice of the published file (tests/data/README.md). |
tests/test_one_path.py |
The one path that generates a timeline (TimelineSource.generate), checked on the parts both grids share: how far the walk may run once a split is planned, where an episode fits in a split that lists its frames, the worker pool the designs run on, and what a run leaves on disk when it fails. |
tests/test_overload.py |
Am as the overload attack of [WU26]: the PGLib-OPF line ratings, the flow-goal false state, the eligible target branches, the fewest-tamper search on a flow goal, and new generation's families. |
tests/test_overload_case_studies.py |
[WU26]'s case studies on our overload attack: the paper's PMU placement, its two lines overloaded at once, the ratings 1.2 times each line's peak true flow over the window (the level at which our device counts matched the paper's in the S_max sensitivity study), and the load and generator bounds. The paper states no line limits, so the ratings are ours and the comparison is of kind, not of value: the attack is feasible, reaches both ratings, tampers the paper's devices on IEEE-14, and its largest per-device change is of the paper's order (0.22 and 0.17 pu there). |
tests/test_package_equivalence.py |
Hand-written loops and formulas replaced by library calls or array operations: each test pins the replacement to the code it replaced (identical, or to tolerance where the arithmetic order changes), so the simplification cannot drift. |
tests/test_pmu_channels.py |
The hybrid meter model: angles at the PMU buses only, the PMU branch-current phasors [WU26 eqs. 19-20] emitted, stored, loaded and attacked, and the eq. (3) pseudo-measurements an estimator can derive from them. The v0.8.3 meter model stays the default and writes none of it. |
tests/test_power_floor.py |
The floor under the power meters' class as a setting: the plan carries it, the noise and every count follow it, the file records it, and the readers of both toolkits weight by it. |
tests/test_profiles.py |
Load sources and operator feeds: each reads itself, no network needed. |
tests/test_public_bundles.py |
The public dual-access bundles (data models step 3): each is the dict it used to be, with the same keys in the same order, and its attribute view agrees with the dict view. |
tests/test_public_coverage.py |
Direct tests for public pieces the rest of the suite reached only through a whole pipeline: the replay policy, the linear-algebra and network kernels on cases small enough to check by hand, the episode reader, the release lookup, the trust selector base, the removal guard and the learned localizer's threshold. |
tests/test_ramp_rules.py |
The rules a ramp is drawn and kept by: its targets are one neighbourhood; no frame of an emitted ramp steps past the stealth bound, into the frame or out of the ramp's last one, on the fewest-tamper support and on the whole area alike; and a ramp no support holds is given up after a fixed number of tries, which the walk answers by moving the episode. |
tests/test_registry.py |
The registry's asset layout: one timeline per system and its HDF5 pool, from data release v0.8.0. |
tests/test_rref_attack.py |
[WU26]'s row-reduction attack (p. 655 and Sec. IV-D1 steps 1-5, after [YAN17]) as the overload attack's support method (OverloadSettings.support_method="rref"): the column-exchange reduction, the supports it pins on the paper's IEEE-14 scenarios, and that the attack it builds is feasible. |
tests/test_schema.py |
The file protocol lives in one module: the fixture file carries exactly the names it spells, and no other module spells a dataset path. |
tests/test_sdk.py |
Behavioral tests for the SDK surface: the contracts the docs promise, checked on a tiny timeline. |
tests/test_search_speed.py |
The fewest-tamper search's speed-ups change nothing it finds: exhaustive searches on fixed IEEE-14 windows return the answers the search returned before them (pinned), and each shortcut equals the computation it replaced (the cached boundary, the reused solve blocks, the attack vector over the support's branches only). |
tests/test_solve_settings.py |
The solve setting of the pool-building step (SolveSettings) on the IEEE cases, with pandapower alone: what the model refuses, the default as the released power flow, and a least-cost OPF pool. |
tests/test_split_first.py |
Split-first generation: the timeline is cut into train, val and test before any episode is placed; each split gets the whole number of episodes closest to its attacked fraction, shared between the families by largest remainder and placed uniformly without overlap or cut; an episode with no feasible design moves to another onset of its split (an Am anywhere in it, a ramp later); and every frame's jitter comes from its own (seed, timestep) stream, so timelines that place different attacks carry the same benign frames. |
tests/test_timeline.py |
The one-file timeline writer: its layout, its episodes and the At and Am frames. |
tests/test_timeline_digests.py |
The generated IEEE timeline, whole: every dataset and attribute of the file against a stored digest. |
tests/test_toolkit_boundary.py |
The dependency between the two toolkits points one way: the analysis toolkit fdia_analysis builds on the generation toolkit fdia_graph, and fdia_graph never imports it. Checked in the source (no import, no module name in a lazy table) and by running: a fresh interpreter in which fdia_analysis is blocked (so the check is the same whether or not it is installed) loads every module of fdia_graph, generates a timeline and reads it back. |
tests/test_tools.py |
Four repository tools on small samples: the constants rule of tools/layout.py on a temporary tree, tools/count_lines.py on a file whose lines are easy to miscount, the phone rules of tools/render_mermaid.py on two flow diagrams, and the plain-pages rule and the release exception of the changelog rule of tools/prereview.py. |
tests/test_tour.py |
The tour of docs/guides/tour.md prints what the page shows: examples/tour.py runs as published and its output is compared, line for line, with the block the page quotes. The comparison runs only with FDIA_SLOW=1, and no scheduled workflow runs it. |
tests/test_trust_formulas.py |
The row reduction the attack search and the trusted-meter kernel share (the kernel itself, the open attack subspace, its cost and the greedy selection, is checked in analysis/tests/test_trust_formulas.py). |
tests/test_trusted_pmus.py |
[WU26]'s trusted-PMU schedule as a constraint on the fewest-tamper search: a PMU trusted at slot s keeps its bus's /V/ and angle true at every snapshot t >= s (eqs. 26-32), its branch currents stay untrusted (eq. 27), and one support is held for the window. |
tests/test_validation.py |
The validation engine (models.validation): rules declared on fields, one message shape, and the public entry points that build their config models before any work. |
tests/test_versions.py |
The two toolkits are released together at one version: both pyproject.toml files and both __version__ values say the same number, and fdia-analysis requires exactly that fdia-graph (a released fdia-graph of another version may lack a name fdia_analysis imports). No data needed; tools/release.py refuses to tag a commit where this does not hold. |
The analysis toolkit's tests¶
| file | what it does |
|---|---|
analysis/tests/test_detect.py |
The detection building block: the persistence rule and its calibration, the package that exports no name, the rule's golden snapshot (golden/persistence_rule.json: a change of behavior fails here and has to say why), and the alarm-rule example of docs/guides/extending.md run as published (no data needed). |
analysis/tests/test_edges.py |
The analysis toolkit's part of tests/test_edges.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: The public edges: wrong arguments fail early with a message naming what is allowed, and the filters mean what the docs say. The other test files prove the happy path; this file is the rest. |
analysis/tests/test_estimators.py |
Estimator behaviour the frozen scores cannot see: the per-unit guard on every public path, one estimator whatever calls it, the weighted solve keeping its best step, classical one-at-a-time residual removal, and the spread-out meter-sigma calibration. |
analysis/tests/test_federated.py |
fdia_analysis.federated: the partition of buses into clients and the averaging formulas. |
analysis/tests/test_formulas.py |
The analysis toolkit's part of tests/test_formulas.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: The formulas kernel: each function on a case small enough to check by hand, and the estimator's torch measurement function pinned to the numpy kernel so there is one AC model in the package. |
analysis/tests/test_loader_timeline.py |
The analysis toolkit's part of tests/test_loader_timeline.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: fg.load on a timeline file: the record table and the timeline from one file, order, the benign layer on records, batches and exports, ds.windows and ds.episodes. Uses the timeline fixture of conftest. |
analysis/tests/test_malformed_inputs.py |
A malformed setting or argument of the analysis toolkit is a ConfigError, never a raw TypeError, KeyError, ValueError or IndexError from deeper in the code (docs/reference/REVIEW_CHECKLIST.md, item 4). |
analysis/tests/test_minimize.py |
The analysis toolkit's part of tests/test_minimize.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: The fewest-tamper support search [WU26 eq. 12]: exact against brute force on IEEE-14, a lower bound that never exceeds a cost, the two sigmas (the emitter's per-scan jitter, the meters' accuracy class the search counts against), and a continuous reweighted-l1 cross-check the search is never beaten by. |
analysis/tests/test_models.py |
The analysis toolkit's part of tests/test_models.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: Bundle, the dual-access base of the typed records: every dict use the package's callers rely on must keep working, and the attribute view must agree with it. |
analysis/tests/test_models_package.py |
Every data model of the analysis toolkit lives in fdia_analysis.models: they are defined nowhere else, each is imported from the module that defines it (no package of the toolkit exports a name), no name of it is also a name of fdia_graph.models, and its own modules depend on nothing but numpy, the standard library and the generation toolkit's models. The checks are the generation toolkit's (tests/test_models_package.py), run on this package. |
analysis/tests/test_old_releases.py |
The analysis toolkit's part of tests/test_old_releases.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: The pinned data releases stay readable. The generator makes only At and Am, but a timeline of each of v0.8.0, v0.8.1 and v0.8.3 loads, splits, filters by family name and scores per family as before; the record shards and stream files of the releases before v0.8.0 are refused. Each fixture under tests/data was written by the SDK that built its release, or is a slice of the published file (tests/data/README.md). |
analysis/tests/test_package_equivalence.py |
The analysis toolkit's part of tests/test_package_equivalence.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: Hand-written loops and formulas replaced by library calls or array operations: each test pins the replacement to the code it replaced (identical, or to tolerance where the arithmetic order changes), so the simplification cannot drift. |
analysis/tests/test_pmu_channels.py |
The analysis toolkit's part of tests/test_pmu_channels.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: The hybrid meter model: angles at the PMU buses only, the PMU branch-current phasors [WU26 eqs. 19-20] emitted, stored, loaded and attacked, and the eq. (3) pseudo-measurements an estimator can derive from them. The v0.8.3 meter model stays the default and writes none of it. |
analysis/tests/test_public_bundles.py |
The analysis toolkit's part of tests/test_public_bundles.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: The public dual-access bundles (data models step 3): each is the dict it used to be, with the same keys in the same order, and its attribute view agrees with the dict view. |
analysis/tests/test_public_coverage.py |
The analysis toolkit's part of tests/test_public_coverage.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: Direct tests for public pieces the rest of the suite reached only through a whole pipeline: the replay policy, the linear-algebra and network kernels on cases small enough to check by hand, the episode reader, the release lookup, the trust selector base, the removal guard and the learned localizer's threshold. |
analysis/tests/test_results.py |
The results store: records are checked on construction, the store round-trips and keeps history, a run records its provenance, nested reports flatten to records, and a results block of a document fills from the store (the tool that fills the repository's docs is checked in test_results_docs.py). |
analysis/tests/test_results_docs.py |
The docs' results blocks render from the results store (tools/results_docs.py): the repository's docs match it, a block edited by hand fails the check, and the lint reports a number typed outside a block. |
analysis/tests/test_sdk.py |
The analysis toolkit's part of tests/test_sdk.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: Behavioral tests for the SDK surface: the contracts the docs promise, checked on a tiny timeline. |
analysis/tests/test_timeline.py |
The analysis toolkit's part of tests/test_timeline.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: The one-file timeline writer: its layout, its episodes and the At and Am frames. |
analysis/tests/test_trust.py |
The trusted-meter selectors on the tiny timeline: the greedy selection raises the attack cost, the secured meters expose the stealthy families to the residual test, and the DQN learns a selection that closes the attack subspace too. |
analysis/tests/test_trust_formulas.py |
The analysis toolkit's part of tests/test_trust_formulas.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: The trusted-meter kernel: row reduction, the open attack subspace, its cost, the greedy selection. |
analysis/tests/test_validation.py |
The analysis toolkit's part of tests/test_validation.py: the tests that run an estimator, a localizer, a trust selector or an analysis formula. Of that module: The validation engine (models.validation): rules declared on fields, one message shape, and the public entry points that build their config models before any work. |
Examples¶
| file | what it does |
|---|---|
examples/first_look.py |
One overload attack as an operator would see it: the figure at the top of the README. |
examples/nygrid/custom_alarm_rule.py |
A detector rule of your own: a CUSUM on the residual statistic, next to the package's persistence rule. |
examples/nygrid/custom_attack_family.py |
An attack family of your own: a slow bias on one load bus's injection meter. |
examples/quickstart.py |
60-second tour of fdia-graph: load a dataset, inspect it, and get it in whatever format you want. |
examples/tour.py |
One overload episode on IEEE-14, step by step: the script behind docs/guides/tour.md. |
examples/train_arma.py |
Stronger localizer baseline: an edge-fused ARMA graph convolution net (Bianchi et al., IEEE TPAMI 2021). |
examples/train_gnn.py |
End-to-end example: train a GNN attack-localizer on an fdia-graph dataset — the whole point of the SDK. |
examples/train_tgnn.py |
Temporal Graph NN localizer benchmark on an fdia-graph dataset. |
Pipelines¶
| file | what it does |
|---|---|
pipelines/newyork/make_case.py |
The recipe of the New York case file: case_nygrid.m made again from NYgrid's Data/ folder. |
pipelines/newyork/run_pool.py |
Build the pool of operating points for a time window as NYISO's real-time dispatch, in chunks run in parallel. |
The results store's queries¶
| file | what it does |
|---|---|
results/queries.py |
The repository's results queries: what each results block in the docs renders from the store. |
Other files¶
| file | what it does |
|---|---|
conftest.py |
The test configuration of both toolkits (tests/ and analysis/tests/, run from the repository root): the throwaway cache, the fixtures the two trees share, and the rule that leaves the New York tests out where their extra is not installed. A fixture only one test file uses stays in that file; the plain helpers the two trees share are in tests/helpers.py. |