Watershed · Example study
A week of the grid, reconciled as it arrives
Two parties each keep a record of the same events. The records arrive in batches through the day and have to agree by the end of it. Meanwhile each party has a position that follows from them, and someone wants to know whether it is covered.
This is usually a batch job, run overnight, and until it runs nobody can see where things stand. Watershed keeps the answer current in real time, as the records arrive. Each record is a row, the rules are formulas, and every count and total is up to date as rows land. This study runs it on a real week of Great Britain’s electricity grid: 685,720 half-hourly readings for 286 parties.
Two records of the same thing
Before each half hour, every generator and supplier on a grid tells the operator how much energy each of its units will put in or take out. Afterwards the meters say what happened. Three questions follow.
- Do the meters agree? A metering point can be read by the party that owns it and by the network operator. Each reading ends in one of five states: agreed, within tolerance, meters disagree, no reading from the operator, or no reading from the party.
- Is every party covered? A party’s imbalance is what was metered less what it said, added up over its units. A party holds some flexible reserve to make up an imbalance. What the reserve cannot make up is uncovered, and the operator has to find it.
- What if the weather turns? Wind moves what wind farms put in and cold moves what customers take out. The same week under different weather shows how far out the system could get.
Volumes are in megawatt-hours throughout. There are no prices in the model.
Usually a batch job, with no view until it runs
Reconciliation is commonly a scheduled job. The day’s records are collected, and after the day closes, often overnight, a batch compares all of them and writes a report. One published design for reconciling data across systems puts it this way: the batch “can run in night after close of business” to give a “refreshed view of discrepancies on daily basis” (Gupta, 2016). It is built that way because comparing everything is expensive, so it is done once.
The cost is that nobody has a view in the meantime. While records are arriving there is no answer to “how many don’t match so far?” or “which party is short right now?”. A reading that went missing at nine in the morning is found the next day. And when one record is corrected afterwards, the answer is out of date until the batch runs again.
The grid is one example. The same shape turns up wherever two sides keep their own record of the same events: phone operators that carry each other’s calls exchange their call records “every month” to reconcile them, and it is “very common to have discrepancies” between the two (Tutorialspoint); a warehouse’s stock system against a shop’s; a courier’s scans against a sender’s manifest; an insurer’s list of members against an employer’s.
Great Britain’s electricity settlement shows it on a longer clock. Each time the volumes are calculated is a settlement run. The first full run is about a month after the day, and four reconciliation runs follow at about two, five, seven and fourteen months as actual meter readings replace estimates (Elexon). Most of that wait is for meter readings to be collected, which no engine shortens.
What changes here is the part in between. Watershed does not compare everything again. It keeps the answer and updates it as each record lands, so the reconciliation and every party’s position are current for whatever has arrived:
- In real time, as the data arrives. Fed one at a time, each reading was fully reconciled before the next in 10 to 12 microseconds on average, and 0.24 milliseconds at the worst. That is more than 85,000 a second. This grid produces about two a second.
- A view at any moment. Reading the full reconciliation and every party’s cover takes under 10 microseconds, because it is already worked out.
- Corrections without a rerun. One corrected reading updates everything that depends on it in 15 microseconds.
The what-if question then reuses the same formulas as a plan for many scenarios, so it does not need a second model either.
A real week of the grid
The readings are Elexon’s, the company that runs settlement for Great Britain’s electricity market. For 13 to 19 January 2025 and for every unit that has both, the model takes:
- What the unit said it would do: its final physical notification, a level in megawatts, added up over the half hour.
- What was metered: its actual volume for the half hour.
That is 2,044 units belonging to 286 parties, about 98,000 readings a day. In 401,067 of the 685,720 readings the unit said zero and metered zero; most of those are interconnector units that were not in use.
Wind farms metered 259 GWh less than they notified, 18% under. Across every unit, 151 GWh less went in than was notified. The data does not say why. One likely cause is the operator instructing units away from what they notified, which this data set does not include.
What is still made up
- The second reading of each meter. Nobody publishes two readings of one point. The party’s reading is the real one, and the operator’s is the same figure with faults put in: about one reading in 330 missing from the operator, one in 500 missing from the party, one in 200 well apart, and one in 100 differing slightly.
- Each party’s reserve. It is not public, so it is sized from what the party was out by over the week.
- How far the weather moves a unit. Which units are wind farms and which are suppliers’ demand is real. How much they move is not.
Because of this the parties are numbered and not named. A shortfall worked out from a made-up reserve should not be put on a real company.
The model
A reading is one row in a collection. Everything else is a formula over rows, written once.
- ReadingsWhat was nominated, and what each meter says, as each side reports it
- StateOne of five states per reading, from the two readings and the tolerance
- Counts and gapsReadings in each state, and how far apart the meters are in total
- Each partyImbalance over its units, less its reserve: what is uncovered
- The systemParties uncovered, the volume uncovered, and how far out the grid is
The whole week is 10,966,203 calculations, about sixteen for each reading. The rules are ordinary expressions. This is the state of a reading, lightly abridged:
let apart = readings.column(&mut g, "apart_mwh", f.by_operator - f.by_party)?;
let near = apart.abs().le(f.by_party.abs() * tolerance);
let state = readings.column(&mut g, "state",
when(!f.party_read).then("no reading from the party")
.otherwise(when(!f.operator_read).then("no reading from the operator")
.otherwise(when(apart.equals(0.0)).then("agreed")
.otherwise(when(near).then("within tolerance")
.otherwise("meters disagree")))),
)?;
let by_state = readings.group_count(&mut g, "readings_by_state", state)?;
let imbalance = readings.group_sum(&mut g, "imbalance_by_party", f.party, out)?;
What we measured
| Step | Result |
|---|---|
| Loading 675,720 readings, from both meters in 40 batches | 16.8 s in all; 1.0 s for the slowest batch |
| The last 10,000 readings arriving one at a time, each reconciled before the next | 10 to 12 µs each on average; 99 in 100 within 50 µs; 0.24 ms at the worst, over three runs |
| Reading the reconciliation and every party’s cover at any point | Under 10 µs |
| One meter read again | 15 µs, 20 calculations rerun |
| Meter tolerance changed from 0.5% to 20% | 41 ms; 4,399 of 11 million calculations rerun |
| 200,000 weather scenarios | 0.24 s on 32 CPU threads; 0.4 to 0.5 s on the GPU |
| Peak memory | 4.5 GB |
Reconciled as it arrives
The week is loaded the way it would arrive: twenty batches from the parties and twenty from the operator, in turn. A reading whose other side has not reported yet is in the model as soon as the first side lands, in the state “no reading from the operator” or “no reading from the party”.
After each batch the model is brought up to date. The slowest of the forty took 1.0 second for about 34,000 readings. At that point every count by state, every party’s imbalance and the system’s position are correct for everything received so far.
Batches are how the data was fed, not something the engine needs. The last 10,000 readings of the week were kept back and fed one at a time from each side, 19,950 arrivals in all, with everything brought up to date after each one: the reading’s state, the counts, its party’s imbalance and cover, and the system’s position. Over three runs that took 10 to 12 microseconds each on average. Ninety-nine in a hundred were done within 50 microseconds, and the slowest took 0.24 milliseconds.
So the end-of-week report is not a calculation. Reading all of it took under 10 microseconds.
| State | Readings | Gap, MWh |
|---|---|---|
| Agreed | 678,102 | 0.0 |
| Within tolerance | 2,870 | 53.3 |
| Meters disagree | 1,305 | −1,191.4 |
| No reading from the operator | 2,072 | −6,131.7 |
| No reading from the party | 1,371 | 5,524.2 |
The faults are the ones put in, so these counts are a check and not a finding: each equals the number of readings given that fault. A fault in what a meter says only shows where something flowed, which is why fewer readings disagree than were given the fault.
With the made-up reserves, 37 of the 286 parties ended the week out by more than their reserve covers.
A correction, and a change of rule
After the week is in, the operator reads a disputed meter again. One row changes. Watershed follows the dependencies from it: the reading’s state, two counts, its party’s imbalance and cover, and the system totals. Over 1,000 corrections made one at a time, each took 15 microseconds and reran 20 of the 11 million calculations.
A change of rule reaches further. Loosening the meter tolerance from 0.5% to 20% took 41 milliseconds and reran 4,399 calculations. Readings whose meters agree exactly never read the tolerance, so they are not asked again. That is decided by the dependencies and not by anything written for this case.
Either way there is one set of formulas. Nobody wrote a second, faster calculation for corrections.
The same week under other weather
The weather enters as two inputs: wind as a share above or below forecast, and how many degrees colder it is. A party’s wind farms put in more or less in proportion, and its customers take out 1% more for each degree. Both are simplifications.
For many scenarios Watershed compiles the model into a plan. Everything that does not depend on the weather is folded into constants, including all 685,720 readings, which leaves a plan of 984 calculations. Making it took 0.8 seconds.
Running 200,000 scenarios took 0.24 seconds on 32 CPU threads and 0.4 to 0.5 seconds on an RTX 3090. A plan this small does not need a GPU: copying data to and from the card costs more than the arithmetic saves. The benchmark study covers when a GPU does help.
The scenario results themselves are not a forecast. The range is made up, with wind anywhere from 60% under forecast to 60% over for the whole week, so the volumes that come out are far larger than a real week would produce. What the run shows is that the plan and the live model are the same calculation: the first scenario equals what the live model gives with that weather set on it, to the last bit.
What was checked
The example checks itself each time it runs, and stops if a check fails.
- Counts. The number of readings in each state equals the number given that fault.
- Totals. After the corrections and the change of rule, every count and sum equals adding the rows up from scratch.
- Plan against model. One weather scenario from the plan is bit-identical to the live model with that weather set.
Method and limitations
- Few runs. The times are from single runs on a Ryzen 9 5950X with an RTX 3090, or the range over two or three where one is given. They are not medians.
- Real time here means the calculation. Readings were fed from a file as fast as the engine took them. Nothing was read from a live feed, and the time to receive and parse a reading is not included.
- It is not settlement. What a unit is out by here is its metered volume against its notification. The market settles a party against what it contracted, which is not public, and the operator’s own instructions move units away from what they notified. Elexon’s published system imbalance is a different quantity and the model’s total is not comparable with it.
- A third of the units. About 6,050 units have a metered volume in each half hour and about 2,040 of them have a notification. Only those are in the model.
- The second reading, the reserves and the weather response are made up, as set out above.
- The weather is not real yet. Real weather days, with each unit’s response fitted from its own output, are the next step and have not been done.
- Memory. The live model holds every calculation in memory: 4.5 GB for this week.
The readings are fetched from Elexon’s Insights API by a script and are not kept in the repository. They are used under the BMRS data licence. Elexon has not endorsed this work.
To run it:
git clone https://github.com/surefold/watershed && cd watershed/crates/watershed-gpu
python3 examples/shared/grid_data.py /path/to/data # a week, about 690,000 readings
cargo run --release --example grid_balancing -- /path/to/data
cargo run --release --example grid_balancing -- 1000000 400 # or a made-up day, with no download