Metadata-Version: 2.4
Name: anesthesim
Version: 0.1.0
Summary: Gymnasium environments for reinforcement learning in automated anesthesia drug dosing
Project-URL: Repository, https://github.com/HassDhia/anesthesim
Project-URL: Documentation, https://github.com/HassDhia/anesthesim#readme
Author-email: Hass Dhia <partners@smarttechinvest.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.10
Requires-Dist: gymnasium>=0.29
Requires-Dist: numpy>=1.24
Requires-Dist: scipy>=1.11
Provides-Extra: all
Requires-Dist: mypy; extra == 'all'
Requires-Dist: pytest-cov; extra == 'all'
Requires-Dist: pytest>=7.0; extra == 'all'
Requires-Dist: ruff; extra == 'all'
Requires-Dist: stable-baselines3>=2.0; extra == 'all'
Requires-Dist: torch>=2.0; extra == 'all'
Provides-Extra: dev
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Provides-Extra: train
Requires-Dist: stable-baselines3>=2.0; extra == 'train'
Requires-Dist: torch>=2.0; extra == 'train'
Description-Content-Type: text/markdown

# AnestheSim

**Gymnasium environments for reinforcement learning in automated anesthesia drug dosing**

![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![Tests](https://img.shields.io/badge/tests-109%20passing-brightgreen.svg)
[![PyPI version](https://img.shields.io/pypi/v/anesthesim.svg)](https://pypi.org/project/anesthesim/)

---

Three Gymnasium-compatible RL environments for automated anesthesia drug dosing: propofol infusion control via the Marsh three-compartment pharmacokinetic model with Hill pharmacodynamic BIS prediction, remifentanil effect-site concentration targeting via the Minto model, and combined propofol-remifentanil anesthesia management using the Greco synergistic interaction surface. Includes configurable difficulty tiers with patient variability and surgical stimulation events, heuristic TCI (Target-Controlled Infusion) clinical baselines, PPO RL agents, and a benchmark suite across three difficulty levels. 109 tests, MIT licensed.

## Installation

```bash
pip install anesthesim              # Core (numpy, scipy, gymnasium)
pip install anesthesim[train]       # + SB3, PyTorch for RL training
pip install anesthesim[all]         # Everything
```

Development install:

```bash
git clone https://github.com/HassDhia/anesthesim.git
cd anesthesim
pip install -e ".[all]"
```

## Quick Start

```python
import gymnasium as gym
import anesthesim

env = gym.make("anesthesim/PropofolControl-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 | Task | Observation | Action | Key Challenge |
|---|---|---|---|---|
| `PropofolControl-v0` | BIS-guided propofol infusion | Box(6): Cp, Ce, BIS, error, rate, time | Box(1): rate [0,200] mcg/kg/min | PK/PD delay, surgical stimulation |
| `RemifentanilDosing-v0` | Effect-site concentration targeting | Box(6): Cp, Ce, target, error, rate, time | Box(1): rate [0,0.5] mcg/kg/min | Rapid onset/offset, changing targets |
| `CombinedAnesthesia-v0` | Multi-drug BIS control | Box(8): 2x Cp, 2x Ce, BIS, error, 2x rate | Box(2): propofol + remifentanil rates | Drug synergy exploitation |

## Architecture

AnestheSim implements established pharmacokinetic/pharmacodynamic models:

- **Marsh PK Model** (Marsh et al., 1991): Three-compartment model for propofol distribution
- **Minto PK Model** (Minto et al., 1997): Three-compartment model for remifentanil with effect-site
- **Hill PD Model** (Schnider et al., 1999): Sigmoid Emax model mapping propofol Ce to BIS
- **Greco Interaction Model** (Bouillon et al., 2004): Response surface for propofol-remifentanil synergy

## Paper

The accompanying paper is available at:
- [PDF (GitHub)](https://github.com/HassDhia/anesthesim/blob/main/paper/anesthesim.pdf)

## Citation

If you use anesthesim in your research, please cite:

```bibtex
@software{dhia2026anesthesim,
  author = {Dhia, Hass},
  title = {AnestheSim: Gymnasium Environments for Reinforcement Learning in Automated Anesthesia Drug Dosing},
  year = {2026},
  publisher = {Smart Technology Investments Research Institute},
  url = {https://github.com/HassDhia/anesthesim}
}
```

## License

MIT License. See [LICENSE](LICENSE) for details.

## Contact

Hass Dhia - Smart Technology Investments Research Institute
- Email: partners@smarttechinvest.com
- Web: [smarttechinvest.com/research](https://smarttechinvest.com/research)
