Model-based monitoring
A model says what a channel should read. A check compares. This page covers how the checks decide, what they were measured to do on the simulated loop, and what they cannot tell you.
Run it: downrange demo --scenario loop. Change the fault with --loop-fault, for example pump-degrade=0.85@50, or none.

The demonstration system #
A water loop: reservoir, pump on an electric motor, flow meter, throttle valve, back to the reservoir. Simulated by apps/downrange-gen/src/looprig.rs. The model, in systems/demo-loop.system.toml:
| Check | Model | Source of the model |
|---|---|---|
flow-model |
Q = k_q · n | pump affinity law: flow proportional to speed |
dp-model |
Δp = r · Q² | turbulent loss proportional to flow squared |
current-model |
I = i0 + k_i · n³ | shaft power proportional to speed cubed |
These are static models. The simulated flow lags speed by about a second, so every check is gated on the speed being steady (when).
How a check decides #
- Data quality. A sample that is not a number is not evaluated.
- Mode.
whenmust be true, on inputs no older thanmax_input_age_s. Otherwise the check is gated: it forgets partial evidence, and an event that is already open stays open. - Statistic.
residual: z = (observed − expected) / √(σ_measurement² + σ_model²). The two sigmas are added as independent errors. That is an assumption.cusum: the same z, accumulated on each side with a slack. Finds a small shift that never crosses the residual threshold in one sample.frozen: seconds since the value last changed by more thanmin_change.missing: seconds since the channel last arrived, judged on the timestamps of the other channels.
- Persistence and hysteresis.
persistsamples in a row above the threshold open an event.persistin a row below threshold minus hysteresis close it.
Everything is stepped by samples and their vehicle time. A replay gives the same events, checked by digest (tests/loop_monitor.rs).
Detection and isolation are separate #
Detection says a statistic crossed a line. Isolation asks which explanations are still consistent with the other checks. For a firing check, each channel it reads is a suspect, unless another check that reads the same channel is being evaluated now and is quiet. The component's own model stays a suspect, and so does "the model was wrong from the start".
The event lists what is left. With more than one entry it says Ambiguous. Downrange does not pick one, and attaches no probability.
Worked out on the loop:
| What was injected | What fired | Suspects left |
|---|---|---|
| Flow meter reads 1.5 L/min high | flow-model, flow-drift, dp-model | the flow meter (two checks disagree with it), the pump, the model. The speed sensor is cleared by current-model |
| Pump really delivers 85% | flow-model, flow-drift | the pump, the model. The flow meter is cleared: flow and pressure still agree |
| Pressure sensor reads 12 kPa high | dp-model | the pressure sensor (nothing else reads it, and the event says so), the valve's loss model, the model |
A biased flow meter and a degraded pump raise the same first alarm. The second check is what tells them apart. With one check there is nothing to tell them apart, and the event says ambiguous.
Measured on the simulated loop #
30 runs per case, 100 s each, seeds 100 to 129, fault at T+50 s. The thresholds were fixed before these seeds were looked at. Reproduce with cargo test --release -p downranged --test loop_monitor -- --nocapture.
| Case | Detected by | Missed | Delay, median | Delay, worst |
|---|---|---|---|---|
| No fault | nothing | 0 false events in 30 runs (50 minutes of simulated time) | ||
| Flow meter bias +1.5 L/min | flow-model | 0 / 30 | 0.18 s | 0.38 s |
| Flow meter drift +0.05 L/min per s | flow-drift (CUSUM) | 0 / 30 | 8.86 s | 9.32 s |
| Flow meter frozen | flow-frozen | 0 / 30 | 1.00 s | 1.00 s |
| Flow meter missing | flow-missing | 0 / 30 | 0.50 s | 0.50 s |
| Pressure sensor bias +12 kPa | dp-model | 0 / 30 | 0.18 s | 0.36 s |
| Pump delivers 85% | flow-model | 0 / 30 | 0.50 s | 0.60 s |
| Model constant 20% wrong, no fault | flow-model | fires, as it should; "the model was wrong" is among the suspects |
For the drift, 8.9 s after onset the error is 0.44 L/min, about 1.5 sigma. The plain residual check needs 4 sigma. In the one run where it was looked at (seed 1, drift from T+45 s) it fired at T+75 s, after a speed change.
What these numbers are not #
- The simulator and the model share their equations. This shows the method works when the model is right. It says nothing about a real pump, where the affinity law is an approximation and sigma_model would have to be found from data.
- The fault sizes were chosen to be detectable. A 0.3 L/min bias is inside one sigma and would not be found by
flow-model. No detection-probability curve against fault size was made. - Zero false events in 50 simulated minutes is a small sample with Gaussian noise. Real sensors have outliers.
- One operating profile. The checks are gated out for about 10 s after each speed change. A system that never settles is never checked.
- No fault was injected during a transient, and no two faults at once.
Faults in the simulator #
downrange-gen --scenario loop --loop-fault <kind>[=<value>]@<seconds>
flow-bias (L/min), flow-drift (L/min per s), flow-frozen, flow-missing, dp-bias (kPa), pump-degrade (fraction of flow delivered).
Writing your own #
Start from systems/demo-loop.system.toml. For each check you need a model you believe and two numbers you can defend: how noisy the measurement is and how wrong the model can be when nothing is broken. If you cannot say what sigma_model is, record some healthy runs and look at the residual first. Downrange draws it for you: every check publishes chk.<id>.expected and chk.<id>.stat as plottable series.