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
Metadata
Release files for glucosim 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| glucosim-0.1.1.tar.gz | 25.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| glucosim-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 53.4 kB
Release files / glucosim-0.1.1.tar.gz
| Download URL | glucosim-0.1.1.tar.gz |
|---|---|
| Size | 25.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc99acacb72c8db579a1f8e8c3161597dcc9e240761df8a7cb230d8dcde59608
|
|
BLAKE2b-256 checksum How to use checksums |
3d193f4a835f42545614da503f3bd139f5d9f037eb041c1a0ea7287680fbaadd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.6
|
Release files / glucosim-0.1.1-py3-none-any.whl
| Download URL | glucosim-0.1.1-py3-none-any.whl |
|---|---|
| Size | 27.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
658b47b99b305c28e77ed7387367052a5eafa0a22e015e3014642c8cb795deee
|
|
BLAKE2b-256 checksum How to use checksums |
b6f0b1cde160868d358040f2ad3de16483ae0c9534edc5b982232c1ad3282c10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.6
|
Security for glucosim 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.