Skip to main content

Gymnasium environments for reinforcement learning in glucose management

Project description

glucosim

Gymnasium Environments for Reinforcement Learning in Glucose Management

Python 3.10+ License: MIT Tests PyPI version


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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glucosim-0.1.0.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

glucosim-0.1.0-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

File details

Details for the file glucosim-0.1.0.tar.gz.

File metadata

  • Download URL: glucosim-0.1.0.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for glucosim-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3d2f20acd0cb9c3af6e6ebbf5a3c1814c5054eca9e8944aa02222f0d39a6a4fe
MD5 15bbb4a957ea6e147b37010cf18003b4
BLAKE2b-256 897a0ff6e96652db4944a7f565cce44b2b881f93bdcf0ce3a81c6c77540c0673

See more details on using hashes here.

File details

Details for the file glucosim-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: glucosim-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for glucosim-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7c0e655c84dc1a3b0780ead43134dbf15df97d0558bcd924681a425f7b5bdf1
MD5 f0495a7b2b95cff8c9d5a6cf220f3c33
BLAKE2b-256 dbbacfa36ee24135167824d595a19ea0f7ebc6c50e3ab00abb0572e460f028ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page