Artificial pancreas
A closed-loop insulin controller on a glucose-insulin physiology model — taming post-meal spikes while never causing a hypo: the meal challenge, the hypoglycemia trap, a low-glucose-suspend safety layer, and a virtual-patient cohort.

- time-in-range (hybrid + safety)
- 100%time-in-range (hybrid + safety)
- hypoglycemic events
- 0hypoglycemic events
- time-in-range gain
- 81% → 100%time-in-range gain
- cohort patients TIR ≥ 80%
- 40 / 40cohort patients TIR ≥ 80%
- design notebooks
- 10design notebooks
- control
- safety-criticalcontrol
Closed-loop control where a mistake is an emergency.
An artificial pancreas reads blood glucose and doses insulin automatically — a closed control loop on a living patient. What makes it hard isn't keeping glucose down after a meal; it's doing that without ever pushing it too low, because a hypoglycemic event isn't a missed setpoint, it's a medical emergency. This program models the physiology, builds the controller, walks straight into that safety trap, and shows the safety layer that gets out of it — then proves it across a virtual patient cohort.
A meal is a disturbance you can't reject in time.
Carbohydrate hits the bloodstream in minutes; injected insulin takes far longer to act. So a meal sends glucose spiking, and without control it climbs past 200 mg/dL and stays high for hours. The model — a Bergman minimal glucose-insulin system with a meal glucose-appearance term — reproduces that postprandial excursion exactly, and quantifies the damage: only 81% of the day inside the healthy 70-180 band, nearly a fifth of it hyperglycemic. That's the problem a closed loop is there to fix.


The harder you chase the highs, the closer you get to the lows.
It's tempting to turn the controller up: more aggressive insulin dosing flattens the post-meal peaks and pushes time-in-range higher still. But insulin keeps acting after glucose has already turned around, so a hot controller overshoots downward — straight into hypoglycemia. The program makes the trap explicit: chasing the last few points of time-in-range with gain alone causes hypo events. In a real device that's not a worse score, it's a 2 a.m. ambulance. The answer isn't a better gain — it's a safety layer.



Every number is one you can re-run.
The sign-off notebook re-derives each requirement from the same physiology model the program builds.
Result
- Open-loop time-in-range: 81%
- Hybrid + safety TIR: 100%
- Hypoglycemic events (hybrid): 0
- Cohort TIR ≥ 80%: 40 / 40
- Requirements verified: 6 / 6
Requirement
- Open-loop time-in-range: baseline
- Hybrid + safety TIR: R-03
- Hypoglycemic events (hybrid): R-04 = 0
- Cohort TIR ≥ 80%: R-05
- Requirements verified: PASS
A teaching & controls model, not a medical device.
The patient is the Bergman minimal model — glucose, insulin action and plasma insulin — not the high-fidelity UVA/Padova simulator used for regulatory work; the cohort is a simple spread of physiological parameters, and the CGM and pump are idealized. This is a controls and safety-engineering model, explicitly not a medical device or clinical advice. It is exactly the fidelity that builds the intuition and the control logic — the meal disturbance, the hypoglycemia trap, the value of a safety layer, and cohort robustness — on reproducible numbers, before a high-fidelity simulator and a regulated development process. And it pairs with the memory-safe-Rust path: a controller where 'verified' has to mean something.
Keep exploring






