# ani26052007/penguin-barn-training-pipeline architecture

> Architecture diagram of the GitHub repository ani26052007/penguin-barn-training-pipeline, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ani26052007/penguin-barn-training-pipeline
- Repository: https://github.com/ani26052007/penguin-barn-training-pipeline

## Overview

1. **What this repository is**
   - A distributed reinforcement-learning system for autonomous navigation of a Clearpath Jackal robot.
   - The core architecture is an asynchronous actor–learner pipeline: many rollout workers collect trajectories in simulation, while a central trainer consumes those trajectories and updates the policy.

2. **Top-level runtime boundary**
   - Python is the main application runtime for training, evaluation, and rollout orchestration.
   - ROS/Gazebo is the simulation and robot-control boundary, packaged either inside Singularity or run natively for debugging.
   - The repository is designed to run either on a single machine with multiple containers or on a cluster with a shared filesystem.

3. **Training/control plane**
   - `train.py` is the central learner entrypoint.
   - `actor.py` is the rollout worker entrypoint.
   - The learner reads trajectories from a shared buffer directory, updates the model, and writes the latest policy back to that same shared location so actors can reload it.
   - In cluster mode, this becomes an asynchronous pipeline where actors may lag behind the newest policy.

4. **Rollout and simulation data flow**
   - Actors interact with gym-like environments from `envs/`, collect transitions, and persist episode data under `local_buffer/`.
   - The central learner consumes these buffered rollouts, trains an RL model, and periodically publishes updated weights.
   - `logs/` captures per-actor and training logs, while `train_ckpt_step264000.pt` and `local_buffer/policy_latest.pt` show the system’s checkpointing pattern.

5. **Environment abstraction layer**
   - `envs/registration.py`, `wrappers.py`, `motion_control_envs.py`, `parameter_tuning_envs.py`, `jackal_gazebo_envs.py`, `gazebo_simulation.py`, and `move_base.py` define the simulation-facing environment layer.
   - This layer hides ROS/Gazebo specifics behind RL-friendly observations/actions, so the algorithms operate on a consistent interface even though the backend is a robot simulator.
   - The environment layer is also where different task variants are exposed: static, dynamic wall, dynamic box, parameter tuning, and motion-control setups.

6. **Algorithm layer**
   - `rl_algos/` contains the learning methods: DDPG, TD3, SAC, safe TD3, model-based variants, and the Reinflow/trajectory transformer path.
   - `base_rl_algo.py`, `collector.py`, `net.py`, and `tester.py` suggest a common interface for policy networks, replay/trajectory collection, and evaluation.
   - The architecture experiments in `configs/architecture_*` map to different policy backbones: MLP, CNN, RNN/GRU, and Transformer with varying history lengths.

7. **Model-based and safe-RL branches**
   - `configs/model_based/` and `rl_algos/model_based.py` represent the branch where learned transition models are used for Dyna-style planning or MPC.
   - `configs/safe_rl/` and `rl_algos/safe_td3.py` represent a safety-aware branch, including Lagrangian and MPC-based variants.
   - Architecturally, these are alternate training/evaluation pipelines built on top of the same environment and rollout infrastructure.

8. **Experiment configuration system**
   - `configs/` is the main experiment matrix: algorithm choice, architecture choice, history length, generalization scale, and safety/model-based settings.
   - The YAML files are the primary switchboard for the system, determining which environment, policy class, rollout setup, and training regime are active.
   - This makes the repository highly configuration-driven rather than code-branch-driven.

9. **ROS/Gazebo integration package**
   - `jackal_helper/` is a separate ROS package that provides launch files, world definitions, planner parameters, and a C++ collision publisher.
   - `launch/` files compose Gazebo, the Jackal robot, and move_base/planning components.
   - `configs/params/` contains navigation stack parameters such as costmaps and local planner settings, which materially affect the simulated robot behavior.

10. **World generation and scenario assets**
   - `jackal_helper/worlds/BARN/` contains many pre-generated `.world` scenes and corresponding `.npy` path files.
   - `scripts/generate_dynamic_BARN.py` and `generate_dynamic_BARN_regular_shape.py` create dynamic benchmark variants.
   - These assets form the scenario corpus for evaluating generalization and dynamic-obstacle robustness.

11. **Deployment and containerization**
   - `Singularityfile.def`, `singularity_run*.sh`, and `entrypoint.sh` define the execution environment used to isolate ROS/Gazebo and the Python stack.
   - The repo is explicitly built to support containerized rollout, which is why the README emphasizes Singularity images and shared buffers.
   - `executable/` contains convenience launch scripts for actor, learner, and tester roles.

12. **Overall architectural shape**
   - At a high level, the system is: scenario assets and ROS navigation stack on one side; RL algorithm and policy training on the other; connected by a shared trajectory/policy buffer and asynchronous actor processes.
   - The key architectural boundaries are: Python RL vs ROS simulation, central learner vs distributed actors, and configuration-driven experiment selection vs shared environment/runtime code.

Main entry points: [`configs`](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/configs) (Configs), [`jackal_helper`](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/jackal_helper) (Jackal helper), [`executable`](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/executable) (Role scripts), [`train.py`](https://github.com/ani26052007/penguin-barn-training-pipeline/blob/main/train.py) (Train)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Python runtime"]
  node_train_py["Train<br/>learner entrypoint<br/>[train.py]"]
  node_actor_py["Actor<br/>rollout entrypoint<br/>[actor.py]"]
  node_rl_algos["Algorithms<br/>rl methods"]
  node_envs["Envs<br/>simulation wrapper"]
  node_buffer[("Local buffer<br/>trajectory store")]
  node_logs["Logs"]
end

subgraph group_simulation["ROS/Gazebo"]
  node_jackal_helper["Jackal helper<br/>ros package"]
  node_launches["Launch files<br/>ros launch"]
  node_nav_params["Nav params<br/>planner params"]
  node_worlds[("BARN worlds<br/>scenario corpus")]
  node_scripts["World tools<br/>scenario generation"]
end

subgraph group_experiments["Experiment config"]
  node_configs["Configs<br/>experiment matrix"]
  node_arch_cfg["Arch configs<br/>policy backbones"]
  node_dyn_cfg["Dynamic configs<br/>task configs"]
  node_generalization["Generalization<br/>world sweep"]
  node_model_based_cfg["Model-based<br/>planning configs"]
  node_safe_cfg["Safe RL<br/>safety configs"]
end

subgraph group_deployment["Deployment"]
  node_deploy["Container<br/>runtime packaging"]
  node_role_scripts["Role scripts<br/>launch wrappers"]
end

node_actor_py -->|"creates"| node_envs
node_actor_py -->|"writes rollouts"| node_buffer
node_train_py -->|"reads rollouts"| node_buffer
node_train_py -->|"publishes policy"| node_buffer
node_train_py -->|"trains with"| node_rl_algos
node_rl_algos -->|"optimizes on"| node_envs
node_rl_algos -->|"selected by"| node_configs
node_configs -->|"includes"| node_arch_cfg
node_configs -->|"includes"| node_dyn_cfg
node_configs -->|"includes"| node_generalization
node_configs -->|"includes"| node_model_based_cfg
node_configs -->|"includes"| node_safe_cfg
node_envs -->|"bridges to"| node_jackal_helper
node_jackal_helper -->|"composes"| node_launches
node_jackal_helper -->|"tunes"| node_nav_params
node_jackal_helper -->|"runs in"| node_worlds
node_scripts -->|"generates"| node_worlds
node_deploy -->|"packages"| node_role_scripts
node_role_scripts -->|"starts"| node_train_py
node_role_scripts -->|"starts"| node_actor_py
node_role_scripts -->|"emits"| node_logs

click node_train_py "https://github.com/ani26052007/penguin-barn-training-pipeline/blob/main/train.py"
click node_actor_py "https://github.com/ani26052007/penguin-barn-training-pipeline/blob/main/actor.py"
click node_rl_algos "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/rl_algos"
click node_envs "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/envs"
click node_buffer "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/local_buffer"
click node_logs "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/logs"
click node_configs "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/configs"
click node_arch_cfg "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/configs/architecture_static"
click node_dyn_cfg "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/configs/architecture_dynamic_wall"
click node_generalization "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/configs/generalization"
click node_model_based_cfg "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/configs/model_based"
click node_safe_cfg "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/configs/safe_rl"
click node_jackal_helper "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/jackal_helper"
click node_launches "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/jackal_helper/launch"
click node_nav_params "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/jackal_helper/configs/params"
click node_worlds "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/jackal_helper/worlds/BARN"
click node_scripts "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/scripts"
click node_deploy "https://github.com/ani26052007/penguin-barn-training-pipeline/blob/main/Singularityfile.def"
click node_role_scripts "https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/executable"

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_train_py,node_actor_py,node_rl_algos,node_envs,node_buffer,node_logs toneBlue
class node_jackal_helper,node_launches,node_nav_params,node_worlds,node_scripts toneAmber
class node_configs,node_arch_cfg,node_dyn_cfg,node_generalization,node_model_based_cfg,node_safe_cfg toneMint
class node_deploy,node_role_scripts toneRose
```

## Components

### Python runtime

Training, rollout, and evaluation processes in the main application runtime.

- [Train](https://github.com/ani26052007/penguin-barn-training-pipeline/blob/main/train.py): learner entrypoint · Central learner that consumes buffered rollouts and publishes updated policy weights. · `train.py`
- [Actor](https://github.com/ani26052007/penguin-barn-training-pipeline/blob/main/actor.py): rollout entrypoint · Asynchronous worker that runs environments, collects trajectories, and writes episodes to the shared buffer. · `actor.py`
- [Algorithms](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/rl_algos): rl methods · Core RL implementations and shared learning/evaluation interfaces, including DDPG, TD3, SAC, safe RL, and model-based variants. · `rl_algos`
- [Envs](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/envs): simulation wrapper · Gym-like environment layer that hides ROS/Gazebo specifics behind a consistent RL interface. · `envs`
- [Local buffer](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/local_buffer): trajectory store · Shared rollout and policy exchange area used by actors and the learner. · `local_buffer`
- [Logs](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/logs): run logs · Per-actor and training logs emitted during rollout and learning. · `logs`

### ROS/Gazebo

Simulation, navigation stack, and robot-control boundary.

- [Jackal helper](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/jackal_helper): ros package · ROS package that composes Gazebo, Jackal, and navigation stack launch files plus C++ support code. · `jackal_helper`
- [Launch files](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/jackal_helper/launch): ros launch · ROS launch composition for Gazebo, Jackal, and move_base/planning startup. · `jackal_helper/launch`
- [Nav params](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/jackal_helper/configs/params): planner params · Navigation stack parameters that materially shape simulated robot behavior. · `jackal_helper/configs/params`
- [BARN worlds](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/jackal_helper/worlds/BARN): scenario corpus · Pre-generated benchmark worlds and path files for navigation evaluation and robustness testing. · `jackal_helper/worlds/BARN`
- [World tools](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/scripts): scenario generation · Scripts that generate dynamic BARN variants and support benchmark scenario creation. · `scripts`

### Experiment config

Configuration matrix and scenario assets that select tasks, architectures, and regimes.

- [Configs](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/configs): experiment matrix · YAML switchboard for algorithm, architecture, history length, generalization scale, and safety/model-based settings. · `configs`
- [Arch configs](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/configs/architecture_static): policy backbones · Architecture variants for MLP, CNN, RNN/GRU, and Transformer histories across task families. · `configs/architecture_static`
- [Dynamic configs](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/configs/architecture_dynamic_wall): task configs · Task-specific configuration sets for dynamic wall and dynamic box benchmarks. · `configs/architecture_dynamic_wall`
- [Generalization](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/configs/generalization): world sweep · Scaling configs that vary the number of worlds used for training and evaluation. · `configs/generalization`
- [Model-based](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/configs/model_based): planning configs · Configuration branch for Dyna and MPC-style learning with learned dynamics. · `configs/model_based`
- [Safe RL](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/configs/safe_rl): safety configs · Safety-aware configuration branch for Lagrangian and MPC variants. · `configs/safe_rl`

### Deployment

Containerization and role launch scripts for single-node or cluster execution.

- [Container](https://github.com/ani26052007/penguin-barn-training-pipeline/blob/main/Singularityfile.def): runtime packaging · Singularity and shell entrypoints that isolate ROS/Gazebo and Python execution. · `Singularityfile.def`
- [Role scripts](https://github.com/ani26052007/penguin-barn-training-pipeline/tree/main/executable): launch wrappers · Convenience scripts for running actor, learner, tester, and cluster workflows. · `executable`

## Connections

- Actor → Envs: creates · Actors instantiate task environments and collect trajectories there.
- Actor → Local buffer: writes rollouts · Episode data and trajectories are persisted to the shared buffer.
- Train → Local buffer: reads rollouts · The learner consumes buffered trajectories from shared storage.
- Train → Local buffer: publishes policy · Updated weights are written back for actors to reload.
- Train → Algorithms: trains with · Training logic is implemented by the algorithm layer.
- Algorithms → Envs: optimizes on · Algorithms operate through the common environment interface.
- Algorithms → Configs: selected by · Experiment YAMLs choose algorithm and architecture variants.
- Configs → Arch configs: includes · Architecture sweeps define policy backbones and history lengths.
- Configs → Dynamic configs: includes · Dynamic task families are configured separately from static ones.
- Configs → Generalization: includes · Generalization sweeps control world counts and scale.
- Configs → Model-based: includes · Model-based experiments use dedicated config sets.
- Configs → Safe RL: includes · Safe RL experiments use dedicated config sets.
- Envs → Jackal helper: bridges to · Environment implementations wrap the ROS/Gazebo simulation boundary.
- Jackal helper → Launch files: composes · Launch files assemble Gazebo, robot, and navigation components.
- Jackal helper → Nav params: tunes · Planner and costmap settings alter navigation behavior.
- Jackal helper → BARN worlds: runs in · Benchmark world assets define the simulation scenarios.
- World tools → BARN worlds: generates · Scenario generation scripts create dynamic BARN variants and assets.
- Container → Role scripts: packages · Containerization supports the role launch wrappers.
- Role scripts → Train: starts · Wrapper scripts launch the central learner role.
- Role scripts → Actor: starts · Wrapper scripts launch rollout workers.
- Role scripts → Logs: emits · Role executions write training and actor logs.
