Skip to content

How the package flows

A timeline is the meter readings of one grid, frame by frame, with attacks placed in it and labelled per bus. The package builds one in the same stages for every test system. What differs between systems is the settings, and how the operating points are solved.

Six stages, top to bottom. 1. Test system: Case, Network. 2. Operating points: generate_states for the IEEE cases, PoolBuilder for New York. 3. Meters and attacks: MeterPlan, NoiseModel, the attack designs. 4. Timeline file: TimelineSource.generate, TimelineWriter. 5. Load: fg.load returns FdiaGraph. 6. Analyse: fdia_analysis.

The sections follow the picture; box 3 is two sections, the meters and then the attacks. Paths are under src/fdia_graph/ unless a section says otherwise.

Three folders serve every stage. formulas/ holds the mathematics as pure functions, one per equation. models/ holds every bundle of values that is passed or returned. constants/ holds the fixed values, each with its unit and its source.

Test system

The grid: its buses, branches and generating units, with a base operating state.

  • Case (systems/case.py) holds one grid as a frozen record of arrays.
  • Network (systems/network.py) builds the admittances of a Case once. It gives the injections, flows and currents of any state.

Case.from_ieee(118) gives an IEEE case and nygrid_case() gives the New York grid. Both return the same class. Test systems lists every system.

You now have: a Case and its Network, which describe the grid.

Operating points

One AC operating point per frame, in time order. The set is called the pool. data/ holds where it comes from, for every test system: first the load data, then the solve.

The load data:

  • data/profiles.py reads a load series from a file (load_profile) or fetches it from an operator's feed (fetch_profile). The result is a load profile, one number per step.
  • The New York grid takes a load per bus. data/inputs.py downloads and reads its public input tables, data/load_sources.py fetches the building and sales data, and LoadModel in data/loads.py builds each bus's load from them. data/config.py holds that build's settings.

The solve:

  • IEEE cases: generate_states in data/ieee_pool.py scales the loads along a load profile and solves one power flow per step.
  • New York grid: data/dispatch.py sets each hour's dispatch. PoolBuilder in data/pool.py then solves one optimal power flow per five-minute frame, with IpoptSolver (data/ipopt_solver.py), which runs on the Ipopt that data/ipopt.py finds and checks, and one power flow at its outputs, with PandapowerSolver (data/pandapower_solver.py). data/pool.py also reads and writes the pool file.
  • Both solvers are engines of one interface, Solver (data/solver.py). A SolveSettings passed to either builder picks the kind of solve and the engine (Solving).

The IEEE pools are released, so fg.generate downloads one and you do not build it. Solving explains the two kinds of solve, and what happens to a frame that does not solve. Build the operating points has the steps.

You now have: the pool, the true state of the grid at every frame.

Meters and noise

What the operator reads from a state. The three classes are in sensing/ and serve every grid.

  • MeterPlan (meters.py): every meter as one row of a table, with its kind, its place, its owner and its accuracy class.
  • Measurement (measure.py): the measurement function h(x), the readings a state gives, and its Jacobian.
  • NoiseModel (noise.py): each meter's accuracy class, split into a constant bias and a jitter drawn again at every scan.

A benign scan is h(x) of a pool state plus noise. It needs no new solve. Meters and noise explains the plan, the accuracy classes and the noise.

You now have: one benign scan per frame, the readings with no attack.

Attacks

An attack is an episode: a run of consecutive frames under one design. engine/ holds the generator (core.py) and, under engine/attacks/, the attack designs of every grid. There are two families.

  • At, the slow ramp: a false load that rises a little each frame.
  • Am, the overload: the reported flow of a line rises to its rating.

Each attacked frame is the reading of one false AC state. The attacker re-solves a small area of the grid and holds every voltage outside it true. The attack vector is h(x_false) - h(x_true), added to the benign scan.

Family Design Family class
At ramp_design SearchRamp
Am am_overload_design SearchOverload

The designs are made by the parts FdiaGenerator holds (engine/core.py), the classes of engine/attacks/. They run on every test system. A timeline asks every family the same thing, the episode of a window (EpisodeFamily.designed, engine/attacks/family.py); the designs answer as the families SearchRamp and SearchOverload (engine/attacks/search.py). A source also takes a family of your own in place of one of them. The attack families describes both families and their designs.

You now have: the episodes, each with its frames, its buses and its attack vectors.

The timeline file

generation/ holds the stages that walk a timeline: the plan, the designs, the frames and the writer. TimelineSource.generate in generation/source.py is the one path every timeline takes: open the file, cut the train, validation and test splits, place the episodes, design them, walk the frames in time order, and finish the file.

  • The steps are written once. A source is a subclass that builds the generator, the pool and the designer of its families, and says what its files record. The package has one: SearchSource (generation/search.py), the original generator, built on a Network. IeeeSource in generation/ieee.py builds it for an IEEE case by name, and SearchSource.for_pool builds it on a pool file, as the New York case has. How the splits are cut is a setting of the source, split_by: three blocks in time order, or whole weeks, which need each frame's time (an IEEE pool stores none, so the caller passes time=).
  • TimelineWriter (generation/write.py) is the one writer of the HDF5 file.
  • schema.py defines every group, dataset and attribute name of the file, once.
  • Settings arrive as one model from models/config.py, TimelineSettings.

fg.generate starts an IEEE timeline through generate_timeline in timeline.py. On the New York case you build the source yourself, with SearchSource.for_pool. Generate a timeline has every step and every setting, and Layers and labels what the file stores per frame.

You now have: one HDF5 file. fg.generate also registers it under a name, for fg.load.

Loading

fg.load(name, split="train") returns an FdiaGraph, the dataset class in dataset/. It reads the static graph once and slices records on request, so the whole file is never in memory.

  • registry.py turns a name and a data release into a file. download.py fetches the file to the cache and checks its sha256.
  • dataset/ has one concern per file: base.py (shared state), graph.py (the static graph), physics.py (admittances and clean flows), records.py (one record, batches), export.py (whole-split arrays) and sequence.py (windows and episodes).
  • clients.py reads a timeline that records the owners of its buses as federated clients.
  • errors.py defines every error the package raises on purpose.

The package's __init__.py imports the heavy helpers only when they are called, so fg.load never imports torch or pandapower. The data dictionary says what every array means.

You now have: the timeline as records, batches, windows and episodes.

Analysis

The second toolkit, fdia_analysis, measures things on a loaded timeline. Its code is under analysis/src/fdia_analysis/. Each package has a page with its results.

Package Question Page
se what is the true state? State estimation
localization which buses are attacked? Localization
trust which meters should be secured? Trusted meters
federated can clients train without pooling records? Federated

se/detect/ holds the alarm rules, which turn a detector's score per scan into a first alarm, and results/ the code of the results store, where every measured number is kept.

Two toolkits, one direction

The generation toolkit is the distribution fdia-graph, the package fdia_graph under src/. The analysis toolkit is the distribution fdia-analysis, the package fdia_analysis under analysis/.

fdia_analysis imports fdia_graph: it reads timelines through fdia_graph.dataset and uses the generation toolkit's formulas and records. Nothing in fdia_graph imports fdia_analysis, and tests/test_toolkit_boundary.py checks it. The generation toolkit installs and runs alone. Install and data versions lists every extra.

Where next

Read in this order.

  1. The three tutorials: load a dataset, generate a timeline and analyse a timeline.
  2. Test systems and Solving: the grids, and how their operating points are solved.
  3. Meters and noise, The attack families and Layers and labels: what a frame of a timeline holds.
  4. Generate a timeline and Build the operating points: the steps and the settings.
  5. Glossary and Data dictionary: every term, every array and its shape.
  6. Modules: what every file does, in one line.
  7. Concepts to code and Formulas: the function behind each idea and equation.
  8. Class map and Examples: the class diagrams, and runnable baselines to copy.
  9. State estimation guide: fitting and scoring an estimator.
  10. The four study pages in the table above: what was measured, on what, and the result.
  11. Contributing: the rules and the pull-request flow.