# nedamhs/diabetesrl architecture

> Architecture diagram of the GitHub repository nedamhs/diabetesrl, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nedamhs/diabetesrl
- Repository: https://github.com/nedamhs/diabetesrl

## Overview

DiabetesRL is a research project for PPO-based automated insulin control in the SimGlucose diabetes simulator. The main workflow trains vanilla or stacked-observation policies, then evaluates trained policies through simulated patient episodes and reports survival and glucose-range metrics; the README also describes cross-patient evaluation. The source excerpts show environment construction, observation/action wrappers, reward logic, and evaluation helpers. Notebook internals were not sampled, so notebook-to-code wiring is documented at a high level rather than inferred in detail.

Main entry points: [`train.ipynb`](https://github.com/nedamhs/diabetesrl/blob/main/train.ipynb) (PPO training), [`project.ipynb`](https://github.com/nedamhs/diabetesrl/blob/main/project.ipynb) (Evaluation notebook), [`src/make_environment.py`](https://github.com/nedamhs/diabetesrl/blob/main/src/make_environment.py) (Environment builders), [`src/utils.py`](https://github.com/nedamhs/diabetesrl/blob/main/src/utils.py) (Evaluation helpers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_simulation["Simulation setup"]
  node_simglucose{{"SimGlucose"}}
  node_env_builder["Environment builders"]
  node_action_clip["Action clipping<br/>[wrappers.py]"]
  node_feature_engineering["Feature engineering<br/>[wrappers.py]"]
  node_observation_stack["Observation stacking<br/>[wrappers.py]"]
end

subgraph group_learning["Policy learning"]
  node_reward_logic["Reward shaping<br/>[reward_function.py]"]
  node_train_notebook["PPO training<br/>[train.ipynb]"]
  node_vanilla_policy["Vanilla policy"]
  node_stacked_policy["Stacked policy"]
  node_recurrent_policy["Recurrent policy"]
end

subgraph group_evaluation["Evaluation"]
  node_eval_notebook["Evaluation notebook<br/>[project.ipynb]"]
  node_eval_helpers["Evaluation helpers<br/>[utils.py]"]
  node_metrics["Episode metrics<br/>[utils.py]"]
end

node_researcher(("Researcher"))

node_researcher -->|"trains"| node_train_notebook
node_researcher -->|"evaluates"| node_eval_notebook
node_train_notebook -.->|"saves weights"| node_vanilla_policy
node_train_notebook -.->|"saves weights"| node_stacked_policy
node_train_notebook -.->|"saves weights"| node_recurrent_policy
node_env_builder -->|"creates environment"| node_simglucose
node_env_builder -->|"wraps actions"| node_action_clip
node_env_builder -->|"wraps observations"| node_feature_engineering
node_env_builder -->|"adds stacking"| node_observation_stack
node_eval_notebook -.->|"uses evaluation"| node_eval_helpers
node_eval_notebook -.->|"evaluates policy"| node_vanilla_policy
node_eval_notebook -.->|"evaluates policy"| node_stacked_policy
node_eval_notebook -.->|"evaluates policy"| node_recurrent_policy
node_eval_helpers -->|"computes metrics"| node_metrics
node_eval_helpers -.->|"runs rollouts"| node_env_builder
node_train_notebook -.->|"uses reward"| node_reward_logic

click node_env_builder "https://github.com/nedamhs/diabetesrl/blob/main/src/make_environment.py"
click node_action_clip "https://github.com/nedamhs/diabetesrl/blob/main/src/wrappers.py"
click node_feature_engineering "https://github.com/nedamhs/diabetesrl/blob/main/src/wrappers.py"
click node_observation_stack "https://github.com/nedamhs/diabetesrl/blob/main/src/wrappers.py"
click node_reward_logic "https://github.com/nedamhs/diabetesrl/blob/main/src/reward_function.py"
click node_train_notebook "https://github.com/nedamhs/diabetesrl/blob/main/train.ipynb"
click node_vanilla_policy "https://github.com/nedamhs/diabetesrl/blob/main/trained_policies/vanilla_policy_state_dict.pt"
click node_stacked_policy "https://github.com/nedamhs/diabetesrl/blob/main/trained_policies/stacked_policy_state_dict.pt"
click node_recurrent_policy "https://github.com/nedamhs/diabetesrl/blob/main/trained_policies/recurrent_policy_state_dict.pt"
click node_eval_notebook "https://github.com/nedamhs/diabetesrl/blob/main/project.ipynb"
click node_eval_helpers "https://github.com/nedamhs/diabetesrl/blob/main/src/utils.py"
click node_metrics "https://github.com/nedamhs/diabetesrl/blob/main/src/utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_simglucose,node_env_builder,node_action_clip,node_feature_engineering,node_observation_stack toneBlue
class node_reward_logic,node_train_notebook,node_vanilla_policy,node_stacked_policy,node_recurrent_policy toneAmber
class node_eval_notebook,node_eval_helpers,node_metrics toneMint
class node_researcher toneIndigo
```

## Components

### Simulation setup

- **SimGlucose**
- [Environment builders](https://github.com/nedamhs/diabetesrl/blob/main/src/make_environment.py): `src/make_environment.py`
- [Action clipping](https://github.com/nedamhs/diabetesrl/blob/main/src/wrappers.py): `src/wrappers.py`
- [Feature engineering](https://github.com/nedamhs/diabetesrl/blob/main/src/wrappers.py): `src/wrappers.py`
- [Observation stacking](https://github.com/nedamhs/diabetesrl/blob/main/src/wrappers.py): `src/wrappers.py`

### Policy learning

- [Reward shaping](https://github.com/nedamhs/diabetesrl/blob/main/src/reward_function.py): `src/reward_function.py`
- [PPO training](https://github.com/nedamhs/diabetesrl/blob/main/train.ipynb): `train.ipynb`
- [Vanilla policy](https://github.com/nedamhs/diabetesrl/blob/main/trained_policies/vanilla_policy_state_dict.pt): `trained_policies/vanilla_policy_state_dict.pt`
- [Stacked policy](https://github.com/nedamhs/diabetesrl/blob/main/trained_policies/stacked_policy_state_dict.pt): `trained_policies/stacked_policy_state_dict.pt`
- [Recurrent policy](https://github.com/nedamhs/diabetesrl/blob/main/trained_policies/recurrent_policy_state_dict.pt): `trained_policies/recurrent_policy_state_dict.pt`

### Evaluation

- [Evaluation notebook](https://github.com/nedamhs/diabetesrl/blob/main/project.ipynb): `project.ipynb`
- [Evaluation helpers](https://github.com/nedamhs/diabetesrl/blob/main/src/utils.py): `src/utils.py`
- [Episode metrics](https://github.com/nedamhs/diabetesrl/blob/main/src/utils.py): `src/utils.py`

### Other components

- **Researcher**

## Connections

- Researcher → PPO training: trains (evidence: `README.md`)
- Researcher → Evaluation notebook: evaluates (evidence: `README.md`)
- PPO training → Vanilla policy: saves weights (evidence: `README.md`)
- PPO training → Stacked policy: saves weights (evidence: `README.md`)
- PPO training → Recurrent policy: saves weights (evidence: `README.md`)
- Environment builders → SimGlucose: creates environment (evidence: `src/make_environment.py`)
- Environment builders → Action clipping: wraps actions (evidence: `src/make_environment.py`)
- Environment builders → Feature engineering: wraps observations (evidence: `src/make_environment.py`)
- Environment builders → Observation stacking: adds stacking (evidence: `src/make_environment.py`)
- Evaluation notebook → Evaluation helpers: uses evaluation (evidence: `README.md`)
- Evaluation notebook → Vanilla policy: evaluates policy (evidence: `README.md`)
- Evaluation notebook → Stacked policy: evaluates policy (evidence: `README.md`)
- Evaluation notebook → Recurrent policy: evaluates policy (evidence: `README.md`)
- Evaluation helpers → Episode metrics: computes metrics (evidence: `src/utils.py`)
- Evaluation helpers → Environment builders: runs rollouts
- PPO training → Reward shaping: uses reward
