Reinforcement-learning Gymnasium environments for hemostasis and anticoagulation management
Project description
hemosim
Reinforcement-learning Gymnasium environments for hemostasis and anticoagulation management
hemosim provides four Gymnasium-compatible environments for training and evaluating RL agents on bedside anticoagulation-dosing decisions. Every environment is backed by mechanistic pharmacokinetic/pharmacodynamic (PK/PD) models derived from the published clinical literature (IWPC, Hamberg, Raschke, Hirsh, Hockin–Mann, RE-LY/ROCKET-AF/ARISTOTLE). A POMDP reformulation exposes the delayed, noisy, action-ordered laboratory-measurement process that any bedside policy must reason through.
Scope
What this package is. A reproducible simulation substrate: environments, PK/PD models, a POMDP-reformulated lab-ordering interface, clinical-outcome metrics (Rosendaal TTR, ISTH 2005 major bleeding, Warkentin 4T HIT, thromboembolic event aggregator), a rule-based CDS safety layer, a published-data calibration harness, a SPIRIT 2013–compliant silent-deployment protocol, and an extensible baselines suite including a faithful reimplementation of the Nemati 2016 DQN architecture.
What this package is not. It does not ship a trained bedside-ready RL policy. End-to-end policy training against individual-patient MIMIC-IV trajectories is a separate (Phase 2) contribution with its own calibration and evaluation protocol.
Installation
pip install hemosim
Environments
| Environment | Task | Observation | Action |
|---|---|---|---|
hemosim/WarfarinDosing-v0 |
90-day warfarin titration, INR 2–3 target | Box(8) | Box(1) |
hemosim/HeparinInfusion-v0 |
5-day UFH infusion, aPTT 60–100 s target | Box(6) | Box(2) |
hemosim/HeparinInfusion-POMDP-v0 |
Same, with delayed/noisy action-ordered labs | Box(10) | Box(5) |
hemosim/DOACManagement-v0 |
365-day DOAC selection for atrial fibrillation | Box(8) | MultiDiscrete(3,3) |
hemosim/DICManagement-v0 |
7-day DIC component-therapy management | Box(8) | MultiDiscrete(4,4,3,3) |
Quick Start — clinical baseline on warfarin
import gymnasium as gym
import hemosim
from hemosim.agents.baselines import WarfarinClinicalBaseline
env = gym.make("hemosim/WarfarinDosing-v0")
obs, info = env.reset(seed=100000)
agent = WarfarinClinicalBaseline(seed=42)
for day in range(1, 91):
action = agent.predict(obs)
obs, reward, terminated, truncated, info = env.step(action)
if day % 14 == 0:
print(f"day={day:3d} INR={info['inr']:.2f} dose={info['dose_mg']:.1f} mg "
f"therapeutic={info['therapeutic']}")
if terminated or truncated:
break
The fixed-dose INR-adjusted clinical baseline titrates to the 2.0–3.0 INR therapeutic range over the 90-day episode. For the POMDP environment, the same pattern applies but the agent must also emit a lab-order action on each step (see §7 of the paper for the HeparinInfusionPOMDPEnv observation/action schema).
Reproducibility
Every number in the paper and in results/EXPECTED_RESULTS.json can be reproduced from a fresh clone with a single command:
./scripts/reproduce.sh
The harness creates a clean venv, installs the package, runs the test suite, re-runs the baseline evaluation on 100 held-out patient seeds, and diffs the output against results/EXPECTED_RESULTS.json with a 5% relative tolerance on mean_reward. Exit code 0 means PASS.
Train/held-out seed discipline. Training uses seeds in range(0, 10000); evaluation uses seeds in range(100000, 101000). The 90,000-seed buffer is a deliberate guard against boundary errors. See HELDOUT_SEEDS.md and src/hemosim/reproducibility.py for the assert_held_out / assert_train guards.
Documentation
- Paper (30 pages):
paper/hemosim.pdf— environments, PK/PD models, POMDP, calibration residuals, CDS harness, clinical translation pathway. - Silent-deployment protocol (SPIRIT 2013–compliant, 21 pages):
paper/silent_deployment_protocol.pdf— IRB-ready for partner-site submission. - Protocol summary (400-word executive):
paper/protocol_summary.md. - Seed-pool policy:
HELDOUT_SEEDS.md. - Changelog:
CHANGELOG.md.
Citation
Cite both the software and the methods paper:
@misc{dhia2026hemosim_paper,
author = {Dhia, Hass},
title = {{hemosim}: Reproducible Simulation Infrastructure for Reinforcement
Learning in Anticoagulation Management, with a POMDP Reformulation
and a Clinical Translation Pathway},
year = {2026},
howpublished = {\url{https://github.com/HassDhia/hemosim/blob/main/paper/hemosim.pdf}},
note = {Preprint. Smart Technology Investments Research Institute.},
}
@software{dhia2026hemosim_software,
author = {Dhia, Hass},
title = {{hemosim}: Gymnasium Environments for Reinforcement Learning in
Hemostasis and Anticoagulation Management},
year = {2026},
version = {0.2.2},
publisher = {Smart Technology Investments Research Institute},
url = {https://github.com/HassDhia/hemosim},
}
License
MIT. See LICENSE. Copyright © Smart Technology Investments Research Institute.
Contact
- Hass Dhia — Smart Technology Investments Research Institute
- Email: partners@smarttechinvest.com
- Web: smarttechinvest.com/research
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 hemosim-0.2.2.tar.gz.
File metadata
- Download URL: hemosim-0.2.2.tar.gz
- Upload date:
- Size: 164.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bef12eab638e137b2f01f59a61ab05da3227bbe8797efe93e86d8cd599841a86
|
|
| MD5 |
a4eec1d41190b5ac3020c47a6b2f8bf0
|
|
| BLAKE2b-256 |
e98e15209ebab6a6b5320c193f17490adf72ae9ece255b2157441463a0474072
|
File details
Details for the file hemosim-0.2.2-py3-none-any.whl.
File metadata
- Download URL: hemosim-0.2.2-py3-none-any.whl
- Upload date:
- Size: 105.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b62ae34846ded766ca2ff0ccb323c5893d2ed5c787e2b27c67ecfd2b4a2c7e61
|
|
| MD5 |
628bd8ed1ec8603c8161e9dbf10d6e71
|
|
| BLAKE2b-256 |
b4fb6ab30a952140453b4894541d457da1783b2466e4f63cc6b856b2349e6190
|