# shivaverma/openaigym architecture

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

- Interactive diagram: https://gitdiagram.com/shivaverma/openaigym
- Repository: https://github.com/shivaverma/openaigym

## Overview

1. **Repository purpose**
   - This is a collection of independent reinforcement-learning experiments for classic control tasks.
   - Each subfolder is a self-contained solution for one OpenAI Gym-style environment, rather than a single integrated application.

2. **Top-level architecture**
   - The repo is organized by environment: Cart-Pole, Mountain-Car, Taxi, Pendulum, Lunar-Lander, and Bipedal-Walker.
   - There is no shared application runtime or central service layer; each project owns its own training loop, model definitions, and saved artifacts.

3. **Two main algorithm families**
   - **Discrete-action tasks** use value-based methods, primarily **DQN**:
     - `cart-pole/CartPole-v0.py`
     - `mountain-car/MountainCar-v0.py`
     - `taxi/Taxi-v2.py`
     - `lunar-lander/discrete/lunar_lander.py`
   - **Continuous-action tasks** use **DDPG** with actor/critic networks:
     - `pendulam/pendulam-v0/*`
     - `lunar-lander/continuous/*`
     - `bipedal-walker/ddpg-torch/*`

4. **Discrete-task boundary**
   - These scripts are standalone training programs.
   - Their flow is typically: environment state in → policy/value inference → discrete action out → reward and next state returned by the simulator.
   - Because action spaces are small and discrete, the architecture is simpler and does not require replay/noise components typical of DDPG.

5. **Continuous-task boundary**
   - Continuous-control folders are structured around the standard DDPG decomposition:
     - `actor.py` / `model.py` for policy networks
     - `critic.py` for Q-value estimation
     - `replay_buffer.py` for off-policy experience storage
     - `noise.py` for exploration noise
     - `ddpg.py` or `ddpg_agent.py` for orchestration
   - Data flow is: environment observation → actor proposes continuous action → noise is added during training → transition is stored in replay buffer → actor and critic are updated from sampled batches.

6. **PyTorch vs Keras/TensorFlow split**
   - The repo mixes frameworks:
     - Most older projects appear to be Keras/TensorFlow-based per README requirements.
     - `bipedal-walker/ddpg-torch` is explicitly a **PyTorch** implementation.
   - This is an architectural boundary: each subproject is framework-local and not designed as a reusable shared library across frameworks.

7. **Bipedal-Walker as the most complete training pipeline**
   - `bipedal-walker/ddpg-torch` contains the full agent stack and training entrypoint:
     - `train.py` drives episodes and checkpointing
     - `ddpg_agent.py` encapsulates the agent logic
     - `model.py` defines network modules
   - It also stores model checkpoints in `weights-simple` and `weights-hardcore`.
   - The `training/` folder contains rendered progression GIFs, showing that this project emphasizes iterative training and visual evaluation.

8. **Transfer/continued training path in Bipedal-Walker**
   - A notable data flow exists between terrain variants:
     - training on **simple terrain** produces checkpoints
     - those weights are reused to continue training on **hardcore terrain**
   - This makes `weights-simple` a seed artifact for `weights-hardcore`, reflecting staged curriculum-style training.

9. **Lunar-Lander has two distinct implementations**
   - `lunar-lander/discrete` and `lunar-lander/continuous` are separate solutions for the same environment, split by action-space type.
   - The discrete version is more self-contained and includes generated training images under `images/training`.
   - The continuous version mirrors the DDPG structure seen in other continuous-control projects.

10. **Pendulum is a classic DDPG example**
    - `pendulam/pendulam-v0` follows the canonical actor-critic + replay buffer + noise pattern.
    - The folder layout suggests the same agent orchestration pattern as the continuous Lunar Lander, but scoped to a single environment.

11. **Artifacts and outputs**
    - The repo stores learned parameters and visual outputs alongside code:
      - `.pth` checkpoints for PyTorch models in Bipedal-Walker
      - image/gif outputs for progress visualization in several projects
    - This means the repository is not just code; it also includes training outputs that document convergence and performance.

12. **External runtime assumptions**
    - The projects assume local execution in Python 3.7 with Keras 2.4.3 and TensorFlow 2.2.0, plus PyTorch for the Bipedal-Walker Torch variant.
    - The environments are simulator-based RL tasks, so the core dependency boundary is the environment API plus the chosen deep-learning framework.

13. **How to diagram it**
    - A good architecture diagram would show one shared “RL experiments” repository containing multiple isolated pipelines.
    - Each pipeline has:
      - environment interaction loop
      - agent/network modules
      - training script
      - saved weights / visual artifacts
    - Group the projects by **discrete DQN** vs **continuous DDPG** to reflect the real structural split in the codebase.

Main entry points: [`pendulam/pendulam-v0/ddpg.py`](https://github.com/shivaverma/openaigym/blob/master/pendulam/pendulam-v0/ddpg.py) (Pendulum DDPG), [`lunar-lander/continuous/ddpg.py`](https://github.com/shivaverma/openaigym/blob/master/lunar-lander/continuous/ddpg.py) (Lunar DDPG), [`bipedal-walker/ddpg-torch/train.py`](https://github.com/shivaverma/openaigym/blob/master/bipedal-walker/ddpg-torch/train.py) (Bipedal Train), [`pendulam/pendulam-v0/actor.py`](https://github.com/shivaverma/openaigym/blob/master/pendulam/pendulam-v0/actor.py) (Pendulum Actor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_discrete["Discrete DQN"]
  node_cartpole["Cart Pole<br/>DQN script<br/>[CartPole-v0.py]"]
  node_mountaincar["Mountain Car<br/>DQN script<br/>[MountainCar-v0.py]"]
  node_taxi["Taxi<br/>DQN script<br/>[Taxi-v2.py]"]
  node_lunar_discrete["Lunar Discrete<br/>DQN script<br/>[lunar_lander.py]"]
end

subgraph group_continuous["Continuous DDPG"]
  node_pendulum_ddpg["Pendulum DDPG<br/>DDPG trainer<br/>[ddpg.py]"]
  node_pendulum_actor["Pendulum Actor<br/>policy net<br/>[actor.py]"]
  node_pendulum_critic["Pendulum Critic<br/>value net<br/>[critic.py]"]
  node_pendulum_buffer["Pendulum Buffer<br/>replay buffer<br/>[replay_buffer.py]"]
  node_pendulum_noise(("Pendulum Noise<br/>exploration noise<br/>[noise.py]"))
  node_lunar_cont_ddpg["Lunar DDPG<br/>DDPG trainer<br/>[ddpg.py]"]
  node_lunar_cont_actor["Lunar Actor<br/>policy net<br/>[actor.py]"]
  node_lunar_cont_critic["Lunar Critic<br/>value net<br/>[critic.py]"]
  node_lunar_cont_buffer["Lunar Buffer<br/>replay buffer<br/>[replay_buffer.py]"]
  node_lunar_cont_noise(("Lunar Noise<br/>exploration noise<br/>[noise.py]"))
  node_bipedal_train["Bipedal Train<br/>training entrypoint<br/>[train.py]"]
  node_bipedal_agent["Bipedal Agent<br/>DDPG agent<br/>[ddpg_agent.py]"]
  node_bipedal_model["Bipedal Model<br/>torch nets<br/>[model.py]"]
end

subgraph group_artifacts["Artifacts"]
  node_weights_simple[("Simple Weights<br/>checkpoint set")]
  node_weights_hardcore[("Hardcore Weights<br/>checkpoint set")]
  node_bipedal_training["Training Outputs<br/>visual artifacts"]
end

node_gym_api{{"Gym API<br/>environment boundary"}}

node_cartpole -->|"state/action loop"| node_gym_api
node_mountaincar -->|"state/action loop"| node_gym_api
node_taxi -->|"state/action loop"| node_gym_api
node_lunar_discrete -->|"state/action loop"| node_gym_api
node_pendulum_ddpg -->|"uses"| node_pendulum_actor
node_pendulum_ddpg -->|"uses"| node_pendulum_critic
node_pendulum_ddpg -->|"stores"| node_pendulum_buffer
node_pendulum_ddpg -->|"explores"| node_pendulum_noise
node_pendulum_ddpg -->|"control loop"| node_gym_api
node_lunar_cont_ddpg -->|"uses"| node_lunar_cont_actor
node_lunar_cont_ddpg -->|"uses"| node_lunar_cont_critic
node_lunar_cont_ddpg -->|"stores"| node_lunar_cont_buffer
node_lunar_cont_ddpg -->|"explores"| node_lunar_cont_noise
node_lunar_cont_ddpg -->|"control loop"| node_gym_api
node_bipedal_train -->|"drives"| node_bipedal_agent
node_bipedal_agent -->|"builds"| node_bipedal_model
node_bipedal_train -->|"writes"| node_weights_simple
node_weights_simple -->|"seeds"| node_weights_hardcore
node_bipedal_train -->|"renders"| node_bipedal_training
node_bipedal_train -->|"control loop"| node_gym_api
node_pendulum_actor -.->|"policy actions"| node_gym_api
node_lunar_cont_actor -.->|"policy actions"| node_gym_api

click node_cartpole "https://github.com/shivaverma/openaigym/blob/master/cart-pole/CartPole-v0.py"
click node_mountaincar "https://github.com/shivaverma/openaigym/blob/master/mountain-car/MountainCar-v0.py"
click node_taxi "https://github.com/shivaverma/openaigym/blob/master/taxi/Taxi-v2.py"
click node_lunar_discrete "https://github.com/shivaverma/openaigym/blob/master/lunar-lander/discrete/lunar_lander.py"
click node_pendulum_ddpg "https://github.com/shivaverma/openaigym/blob/master/pendulam/pendulam-v0/ddpg.py"
click node_pendulum_actor "https://github.com/shivaverma/openaigym/blob/master/pendulam/pendulam-v0/actor.py"
click node_pendulum_critic "https://github.com/shivaverma/openaigym/blob/master/pendulam/pendulam-v0/critic.py"
click node_pendulum_buffer "https://github.com/shivaverma/openaigym/blob/master/pendulam/pendulam-v0/replay_buffer.py"
click node_pendulum_noise "https://github.com/shivaverma/openaigym/blob/master/pendulam/pendulam-v0/noise.py"
click node_lunar_cont_ddpg "https://github.com/shivaverma/openaigym/blob/master/lunar-lander/continuous/ddpg.py"
click node_lunar_cont_actor "https://github.com/shivaverma/openaigym/blob/master/lunar-lander/continuous/actor.py"
click node_lunar_cont_critic "https://github.com/shivaverma/openaigym/blob/master/lunar-lander/continuous/critic.py"
click node_lunar_cont_buffer "https://github.com/shivaverma/openaigym/blob/master/lunar-lander/continuous/replay_buffer.py"
click node_lunar_cont_noise "https://github.com/shivaverma/openaigym/blob/master/lunar-lander/continuous/noise.py"
click node_bipedal_train "https://github.com/shivaverma/openaigym/blob/master/bipedal-walker/ddpg-torch/train.py"
click node_bipedal_agent "https://github.com/shivaverma/openaigym/blob/master/bipedal-walker/ddpg-torch/ddpg_agent.py"
click node_bipedal_model "https://github.com/shivaverma/openaigym/blob/master/bipedal-walker/ddpg-torch/model.py"
click node_weights_simple "https://github.com/shivaverma/openaigym/tree/master/bipedal-walker/weights-simple"
click node_weights_hardcore "https://github.com/shivaverma/openaigym/tree/master/bipedal-walker/weights-hardcore"
click node_bipedal_training "https://github.com/shivaverma/openaigym/tree/master/bipedal-walker/training"

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_cartpole,node_mountaincar,node_taxi,node_lunar_discrete toneBlue
class node_pendulum_ddpg,node_pendulum_actor,node_pendulum_critic,node_pendulum_buffer,node_pendulum_noise,node_lunar_cont_ddpg,node_lunar_cont_actor,node_lunar_cont_critic,node_lunar_cont_buffer,node_lunar_cont_noise,node_bipedal_train,node_bipedal_agent,node_bipedal_model toneAmber
class node_weights_simple,node_weights_hardcore,node_bipedal_training toneMint
class node_gym_api toneNeutral
```

## Components

### Discrete DQN

Standalone value-based training scripts for classic-control and discrete-action Lunar Lander.

- [Cart Pole](https://github.com/shivaverma/openaigym/blob/master/cart-pole/CartPole-v0.py): DQN script · Standalone CartPole training program. · `cart-pole/CartPole-v0.py`
- [Mountain Car](https://github.com/shivaverma/openaigym/blob/master/mountain-car/MountainCar-v0.py): DQN script · Standalone MountainCar training program. · `mountain-car/MountainCar-v0.py`
- [Taxi](https://github.com/shivaverma/openaigym/blob/master/taxi/Taxi-v2.py): DQN script · Standalone Taxi training program. · `taxi/Taxi-v2.py`
- [Lunar Discrete](https://github.com/shivaverma/openaigym/blob/master/lunar-lander/discrete/lunar_lander.py): DQN script · Discrete-action Lunar Lander solution with training images. · `lunar-lander/discrete/lunar_lander.py`

### Continuous DDPG

Actor-critic pipelines for continuous-control tasks, each with local agent, replay, and exploration components.

- [Pendulum DDPG](https://github.com/shivaverma/openaigym/blob/master/pendulam/pendulam-v0/ddpg.py): DDPG trainer · Continuous-control DDPG example for Pendulum. · `pendulam/pendulam-v0/ddpg.py`
- [Pendulum Actor](https://github.com/shivaverma/openaigym/blob/master/pendulam/pendulam-v0/actor.py): policy net · Policy network for continuous action selection. · `pendulam/pendulam-v0/actor.py`
- [Pendulum Critic](https://github.com/shivaverma/openaigym/blob/master/pendulam/pendulam-v0/critic.py): value net · Q-value network for Pendulum. · `pendulam/pendulam-v0/critic.py`
- [Pendulum Buffer](https://github.com/shivaverma/openaigym/blob/master/pendulam/pendulam-v0/replay_buffer.py): replay buffer · Off-policy experience storage. · `pendulam/pendulam-v0/replay_buffer.py`
- [Pendulum Noise](https://github.com/shivaverma/openaigym/blob/master/pendulam/pendulam-v0/noise.py): exploration noise · Action noise for training-time exploration. · `pendulam/pendulam-v0/noise.py`
- [Lunar DDPG](https://github.com/shivaverma/openaigym/blob/master/lunar-lander/continuous/ddpg.py): DDPG trainer · Continuous-action Lunar Lander DDPG pipeline. · `lunar-lander/continuous/ddpg.py`
- [Lunar Actor](https://github.com/shivaverma/openaigym/blob/master/lunar-lander/continuous/actor.py): policy net · Continuous control actor network. · `lunar-lander/continuous/actor.py`
- [Lunar Critic](https://github.com/shivaverma/openaigym/blob/master/lunar-lander/continuous/critic.py): value net · Continuous control critic network. · `lunar-lander/continuous/critic.py`
- [Lunar Buffer](https://github.com/shivaverma/openaigym/blob/master/lunar-lander/continuous/replay_buffer.py): replay buffer · Experience replay for off-policy updates. · `lunar-lander/continuous/replay_buffer.py`
- [Lunar Noise](https://github.com/shivaverma/openaigym/blob/master/lunar-lander/continuous/noise.py): exploration noise · Exploration process used during training. · `lunar-lander/continuous/noise.py`
- [Bipedal Train](https://github.com/shivaverma/openaigym/blob/master/bipedal-walker/ddpg-torch/train.py): training entrypoint · Main training script driving episodes and checkpoints. · `bipedal-walker/ddpg-torch/train.py`
- [Bipedal Agent](https://github.com/shivaverma/openaigym/blob/master/bipedal-walker/ddpg-torch/ddpg_agent.py): DDPG agent · Agent orchestration and update logic. · `bipedal-walker/ddpg-torch/ddpg_agent.py`
- [Bipedal Model](https://github.com/shivaverma/openaigym/blob/master/bipedal-walker/ddpg-torch/model.py): torch nets · Network definitions for actor and critic modules. · `bipedal-walker/ddpg-torch/model.py`

### Artifacts

Saved weights and visual training outputs kept beside the code.

- [Simple Weights](https://github.com/shivaverma/openaigym/tree/master/bipedal-walker/weights-simple): checkpoint set · Initial checkpoints from simple-terrain training. · `bipedal-walker/weights-simple`
- [Hardcore Weights](https://github.com/shivaverma/openaigym/tree/master/bipedal-walker/weights-hardcore): checkpoint set · Continued-training checkpoints for hardcore terrain. · `bipedal-walker/weights-hardcore`
- [Training Outputs](https://github.com/shivaverma/openaigym/tree/master/bipedal-walker/training): visual artifacts · Rendered progress GIFs from Bipedal Walker training. · `bipedal-walker/training`

### Other components

- **Gym API**: environment boundary · Shared simulator interface used by all experiment scripts.

## Connections

- Cart Pole → Gym API: state/action loop · Trains against the environment step API.
- Mountain Car → Gym API: state/action loop · Trains against the environment step API.
- Taxi → Gym API: state/action loop · Trains against the environment step API.
- Lunar Discrete → Gym API: state/action loop · Trains against the environment step API.
- Pendulum DDPG → Pendulum Actor: uses · Coordinates the policy network during training.
- Pendulum DDPG → Pendulum Critic: uses · Coordinates critic updates during training.
- Pendulum DDPG → Pendulum Buffer: stores · Pushes transitions into replay memory.
- Pendulum DDPG → Pendulum Noise: explores · Adds action noise during training.
- Pendulum DDPG → Gym API: control loop · Interacts with the simulator through observations and actions.
- Lunar DDPG → Lunar Actor: uses · Coordinates the policy network during training.
- Lunar DDPG → Lunar Critic: uses · Coordinates critic updates during training.
- Lunar DDPG → Lunar Buffer: stores · Pushes transitions into replay memory.
- Lunar DDPG → Lunar Noise: explores · Adds action noise during training.
- Lunar DDPG → Gym API: control loop · Interacts with the simulator through observations and actions.
- Bipedal Train → Bipedal Agent: drives · Runs episodes and orchestrates agent updates.
- Bipedal Agent → Bipedal Model: builds · Uses the model definitions for actor and critic networks.
- Bipedal Train → Simple Weights: writes · Saves checkpoints after simple-terrain training.
- Simple Weights → Hardcore Weights: seeds · Simple-terrain checkpoints are reused for hardcore continuation training.
- Bipedal Train → Training Outputs: renders · Produces training visualizations and GIFs.
- Bipedal Train → Gym API: control loop · Interacts with the simulator through observations and actions.
- Pendulum Actor → Gym API: policy actions · Consumes observations to propose actions within the environment loop.
- Lunar Actor → Gym API: policy actions · Consumes observations to propose actions within the environment loop.
