Skip to content
All work

Case study 02 / 25Reinforcement Learning ML

An RL agent that keeps a pipeline model true without hiding leaks

Model-to-meter flow error 0.82 % → 0.14 % on 26 test pipelines, with leaks left visible to the detector instead of tuned away.

My roleDesigned it and led a team of up to 3: set its standards, mentored it, agreed the roadmap with operations and the client, presented to leadership.

Stack

  • C#
  • SQLite
  • Windows services

01 · How it works

  • TodaytoChanged in this work
  • Data flow

What it does

The monitoring platform's hydraulic model needs one roughness factor per pipeline section to make its flow match the flowmeters, and the controller that tuned it had been switched off, leaving every factor fixed. I designed a reinforcement-learning agent that runs beside the app, reads each cycle's log, sets each section's factor, and learns every night in a shadow copy, promoting a new version only after it beats the current one for a week and a person approves it.

Read more

It now runs beside the live app in shadow mode; the first promotion waits for a week of real nights.

7 connections· select a part to trace it
  1. Monitoring app to Cycle log: flow at both ends
  2. Cycle log to RL agent: 13 inputs per section
  3. RL agent to Factor file: factor, max 0.5 % a cycle
  4. Factor file to Monitoring app: read in the same cycle
  5. Cycle log to Nightly shadow: recorded days, each night
  6. Nightly shadow to Engineer approval: after 7 winning days
  7. Engineer approval to RL agent: promotes the new version

02Results

  • R01Lower is better

    Model-to-meter flow error, 26 test pipelines (median)

    Before 0.82%, after 0.14%, 5.9× lower. Lower is better.
    Before
    After
  • R02Higher is better

    Test pipelines where the policy holds in a leak (of 26)

    Before 4, after 26, 6.5× higher. Higher is better.
    Before
    After
  • R03Lower is better

    Ways a rejected model could return after a resume

    Before 2, after 0, eliminated. Lower is better.
    Before
    After

What it achieved

  • What operators get: a model that follows the flowmeters, 0.82 % → 0.14 % median error on 26 test pipelines, while leaks stay visible to the detector instead of being tuned away
  • Test pipelines where the policy holds still during a leak: 4 → 26 of 26, once retention and return were added
  • A new version reaching the app: a hand-set factor → nightly learning in a shadow, at most 2 h, promoted only after 7 winning days and a person's approval
Read more
  • Ways a rejected model could come back after a resume: 2 → 0
  • A year of nights in the window: 432 items listed one by one → 0, older history summarized by week; the versions view refreshes in 1.3 ms instead of 373 ms
  • First connection to the live app: 4 defects found and fixed → 8 of 8 links working on each of 4 systems, one installation and no system-specific code

03Decisions and trade-offs

  1. Constraint

    The hydraulic model cannot be differentiated, and its episodes are long and noisy.

    Decision

    Evolution strategies over a small linear policy, in about 200 lines of our own code.

    What it cost

    Training is slow: about 21 generations a night per system.

  2. Constraint

    A version that learns every night could regress on a live pipeline.

    Decision

    Learn in a shadow; promote only after 7 winning days and a person's approval.

    What it cost

    A better version reaches the app a week later at the earliest.

  3. Constraint

    A year of nightly history would bury the agent's window.

    Decision

    Show the last week in full and summarize older nights by week.

    What it cost

    Older nights are no longer listed one by one.

The challenge

The roughness factor drifts as the pipe and the slurry change, and a fixed value leaves the model's flow off the meters. The old controller corrected it from the inlet error alone, which cannot tell rougher pipe from a leak: during a leak it moved the factor and could swallow the very signal the leak detector needs.

Read more

The first learned policies did the same: they lowered the error, yet scored worse than today against the truth in 10 of 12 runs. An agent that keeps learning on a live system also brings risks of its own: a year of nights piling up in its window, a resumed run that lets a rejected model back in, and a night that starts from a stale version.

What I learned

The reward is not the goal. A policy can lower the error and still be wrong by moving the factor during a leak; scoring every version against the truth, not only the error, caught it. Physics made the fix readable: rougher pipe lowers the flow at both ends, a leak opens them in opposite directions, so the agent chases only the common error.

Read more

Small and readable beat clever: a linear policy over 13 inputs, trained by evolution strategies without differentiating the hydraulic model, generalized from 4 training pipelines to 26. And a learning system needs brakes as much as an engine: a shadow, a winning streak and a person.

Stack

  • C#
  • SQLite
  • Windows services

Skills

  • Reinforcement learning
  • Evolution strategies
  • Hydraulic modeling
  • Safe online learning
  • Explainable ML interfaces
Cover picture for An RL agent that keeps a pipeline model true without hiding leaksCover picture for An RL agent that keeps a pipeline model true without hiding leaks