Gymnasium environments for reinforcement learning in glucose management
Project description
glucosim
Gymnasium Environments for Reinforcement Learning in Glucose Management
Three Gymnasium-compatible RL environments for Type 1 diabetes glucose management: basal rate optimization, meal bolus dosing, and full closed-loop insulin delivery control. Includes the Bergman minimal glucose-insulin model, Dalla Man gut absorption dynamics, a CGM sensor noise model, 30 virtual patients across three age groups (child, adolescent, adult), configurable difficulty tiers, heuristic clinical baselines, PPO RL agents, and a five-tier benchmark suite. 120 tests, MIT licensed.
Installation
pip install glucosim # Core (numpy, scipy, gymnasium)
pip install glucosim[train] # + SB3, PyTorch for RL training
pip install glucosim[all] # Everything
Development install:
git clone https://github.com/HassDhia/glucosim.git
cd glucosim
pip install -e ".[all]"
Quick Start
import gymnasium as gym
import glucosim
env = gym.make("glucosim/BasalControl-v0")
obs, info = env.reset(seed=42)
for _ in range(100):
action = env.action_space.sample()
obs, reward, terminated, truncated, info = env.step(action)
if terminated or truncated:
obs, info = env.reset()
env.close()
Environments
| Environment | Paradigm | Observation | Action | Key Challenge |
|---|---|---|---|---|
BasalControl-v0 |
Continuous basal rate | CGM glucose, IOB, time, glucose rate | Basal rate (U/hr) | Maintain euglycemia over 24h |
BolusAdvisor-v0 |
Meal bolus dosing | CGM glucose, IOB, meal flag, carbs, time since meal | Bolus dose (U) | Optimal postprandial control |
ClosedLoop-v0 |
Full closed-loop | CGM glucose, IOB, time, glucose rate, meal flag, carbs | Total insulin rate (U/hr) | 48h stress test with IOB penalty |
Architecture
GlucoSim implements a modular simulation stack:
- Bergman Minimal Model - Three-equation glucose-insulin dynamics with RK4 integration
- Dalla Man Gut Model - Two-compartment carbohydrate absorption producing glucose appearance rates
- CGM Sensor Model - First-order lag filter with configurable Gaussian noise
- Virtual Patients - 30 patients across child/adolescent/adult groups with +/-20% parameter variability
- Baseline Agents - Random, proportional basal controller, and ICR bolus calculator
- PPO Agent - Stable Baselines3 PPO with tuned hyperparameters
- Benchmark Suite - Five difficulty tiers per environment (easy-adult to hard-child)
Paper
The accompanying paper is available at:
Citation
If you use glucosim in your research, please cite:
@software{dhia2026glucosim,
author = {Dhia, Hass},
title = {GlucoSim: Gymnasium Environments for Reinforcement Learning in Glucose Management},
year = {2026},
publisher = {Smart Technology Investments Research Institute},
url = {https://github.com/HassDhia/glucosim}
}
License
MIT License. See LICENSE for details.
Contact
Hass Dhia - Smart Technology Investments Research Institute
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file glucosim-0.1.1.tar.gz.
File metadata
- Download URL: glucosim-0.1.1.tar.gz
- Upload date:
- Size: 25.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc99acacb72c8db579a1f8e8c3161597dcc9e240761df8a7cb230d8dcde59608
|
|
| MD5 |
0e264952a8bab628c477ee2c00160f02
|
|
| BLAKE2b-256 |
3d193f4a835f42545614da503f3bd139f5d9f037eb041c1a0ea7287680fbaadd
|
File details
Details for the file glucosim-0.1.1-py3-none-any.whl.
File metadata
- Download URL: glucosim-0.1.1-py3-none-any.whl
- Upload date:
- Size: 27.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
658b47b99b305c28e77ed7387367052a5eafa0a22e015e3014642c8cb795deee
|
|
| MD5 |
567a93e25436bb9a8d990862dfade4ec
|
|
| BLAKE2b-256 |
b6f0b1cde160868d358040f2ad3de16483ae0c9534edc5b982232c1ad3282c10
|