This repository contains a small RL project with:
- Training baselines: PPO + SAC (Stable-Baselines3).
- Model-based RL hooks: TD‑MPC2 entrypoints (via a git submodule; see below), and local implementations of SSM dynamics layers (S4/S5/Mamba-style) + MPPI planning utilities.
- Visualization stack:
- Backend: FastAPI server that loads checkpoints and streams live rollouts over WebSocket.
- Frontend: Vite + React dashboard that visualizes live rollouts and offline artifacts.
If you are looking for a “how it works” narrative, start with knowledge_base.md and theory.md.
python -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -r requirements.txtNotes:
- PyTorch:
requirements.txtpinstorch>=2.2.0but you may want the correct CUDA wheel for your system. - MuJoCo + dm_control:
dm_controluses MuJoCo; ensure your system can render headlessly if needed.
This repo expects the official TD‑MPC2 code as a submodule:
- Submodule declared in
.gitmodulesat pathtdmpc_2 - URL:
https://github.com/nicklashansen/tdmpc2.git
Initialize it:
git submodule update --init --recursiveImportant:
- In the current checkout, the local folder
tdmpc2/is present but empty, and imports likefrom tdmpc2.train_tdmpc2 import ...will fail until TD‑MPC2 code is available onPYTHONPATH. - If you use the submodule, you’ll typically need to ensure its package is importable (e.g. add it to
PYTHONPATH, install editable, or mirror code intotdmpc2/).
python main.py ppo --env-name walker --task walk --total-steps 10000
python main.py sac --env-name cheetah --task run --total-steps 10000Outputs are written to:
logs/<run_name>/...(SB3 eval.npz, checkpoints)artifacts/<run_name>/...(metrics JSONL,summary.json)
The run layout is created by run_layout.init_run_paths() and deletes any existing output for the same run_name.
python main.py plot
python main.py plot --all-phasesPlots are written under artifacts/plots/....
Backend exposes:
- WebSocket:
/ws(live frames + metrics) - REST:
/health,/metrics/live,/artifacts/*
Run both:
python app.py serve --reloadFrontend mode selection:
--frontend=auto(default): use built static UI ifdashboard/distexists, otherwise start Vite dev server ifnpmis available.--frontend=dev: always start Vite dev server.--frontend=static: only serve the built UI through FastAPI.--frontend=none: backend only.
Build the frontend for static serving:
cd dashboard
npm install
npm run buildThen python app.py serve will mount dashboard/dist at / on port 8000.
- Unified CLI:
main.py- Commands:
test,ppo,sac,tdmpc,tdmpc-s4,tdmpc-s5,tdmpc-mamba,phase3,phase4,plot,all-phases
- Commands:
- Unified server launcher:
app.pypython app.py serveoruvicorn app:app --reload
- FastAPI app:
server/server.py - Frontend:
dashboard/src/main.tsx→dashboard/src/app/App.tsx
knowledge_base.md: full end-to-end implementation flow (training, artifacts, server, frontend, evaluation).theory.md: algorithm theory + pseudocode + references for TD‑MPC2, MPPI, S4/S5/Mamba, and how they relate to this project.