How shivaverma/openaigym works
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-v0/ddpg.py Pendulum DDPG · continuous/ddpg.py Lunar DDPG · train.py Bipedal Train · actor.py Pendulum Actor
Components 21
Discrete DQN
Standalone value-based training scripts for classic-control and discrete-action Lunar Lander.
- Cart Pole · Standalone CartPole training program.
cart-pole/CartPole-v0.py - Mountain Car · Standalone MountainCar training program.
mountain-car/MountainCar-v0.py - Taxi · Standalone Taxi training program.
taxi/Taxi-v2.py - Lunar Discrete · 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 · Continuous-control DDPG example for Pendulum.
pendulam/pendulam-v0/ddpg.py - Pendulum Actor · Policy network for continuous action selection.
pendulam/pendulam-v0/actor.py - Pendulum Critic · Q-value network for Pendulum.
pendulam/pendulam-v0/critic.py - Pendulum Buffer · Off-policy experience storage.
pendulam/pendulam-v0/replay_buffer.py - Pendulum Noise · Action noise for training-time exploration.
pendulam/pendulam-v0/noise.py - Lunar DDPG · Continuous-action Lunar Lander DDPG pipeline.
lunar-lander/continuous/ddpg.py - Lunar Actor · Continuous control actor network.
lunar-lander/continuous/actor.py - Lunar Critic · Continuous control critic network.
lunar-lander/continuous/critic.py - Lunar Buffer · Experience replay for off-policy updates.
lunar-lander/continuous/replay_buffer.py - Lunar Noise · Exploration process used during training.
lunar-lander/continuous/noise.py - Bipedal Train · Main training script driving episodes and checkpoints.
bipedal-walker/ddpg-torch/train.py - Bipedal Agent · Agent orchestration and update logic.
bipedal-walker/ddpg-torch/ddpg_agent.py - Bipedal Model · 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 · Initial checkpoints from simple-terrain training.
bipedal-walker/weights-simple - Hardcore Weights · Continued-training checkpoints for hardcore terrain.
bipedal-walker/weights-hardcore - Training Outputs · Rendered progress GIFs from Bipedal Walker training.
bipedal-walker/training
Other components
- Gym API · Shared simulator interface used by all experiment scripts.
Connections 22
- 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.