MCPcopy Index your code
hub / github.com/XinJingHao/PPO-Continuous-Pytorch

github.com/XinJingHao/PPO-Continuous-Pytorch @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
30 symbols 82 edges 3 files 1 documented · 3%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

PPO-Continuous-Pytorch

A clean and robust Pytorch implementation of PPO on continuous action space:

Pendulum | LunarLanderContinuous :-----------------------:|:-----------------------:| | |

Other RL algorithms by Pytorch can be found here.

Dependencies

gymnasium==0.29.1
numpy==1.26.1
pytorch==2.1.0

python==3.11.5

How to use my code

Train from scratch

python main.py

where the default enviroment is 'Pendulum'.

Play with trained model

python main.py --EnvIdex 0 --render True --Loadmodel True --ModelIdex 100

which will render the 'Pendulum'.

Change Enviroment

If you want to train on different enviroments, just run

python main.py --EnvIdex 1

The --EnvIdex can be set to be 0~5, where

'--EnvIdex 0' for 'Pendulum-v1'  
'--EnvIdex 1' for 'LunarLanderContinuous-v2'  
'--EnvIdex 2' for 'Humanoid-v4'  
'--EnvIdex 3' for 'HalfCheetah-v4'  
'--EnvIdex 4' for 'BipedalWalker-v3'  
'--EnvIdex 5' for 'BipedalWalkerHardcore-v3' 

Note: if you want train on BipedalWalker, BipedalWalkerHardcore, or LunarLanderContinuous, you need to install box2d-py first. You can install box2d-py via:

pip install gymnasium[box2d]

if you want train on Humanoid or HalfCheetah, you need to install MuJoCo first. You can install MuJoCo via:

pip install mujoco
pip install gymnasium[mujoco]

Visualize the training curve

You can use the tensorboard to record anv visualize the training curve.

  • Installation (please make sure PyTorch is installed already):
pip install tensorboard
pip install packaging
  • Record (the training curves will be saved at '\runs'):
python main.py --write True
  • Visualization:
tensorboard --logdir runs

Hyperparameter Setting

For more details of Hyperparameter Setting, please check 'main.py'

References

Proximal Policy Optimization Algorithms
Emergence of Locomotion Behaviours in Rich Environments

Training Curves

avatar
All the experiments are trained with same hyperparameters (see main.py).

Core symbols most depended-on inside this repo

select_action
called by 2
PPO.py
forward
called by 2
utils.py
get_dist
called by 2
utils.py
forward
called by 2
utils.py
forward
called by 2
utils.py
Action_adapter
called by 2
utils.py
evaluate_policy
called by 2
utils.py
train
called by 1
PPO.py

Shape

Method 20
Class 5
Function 5

Languages

Python100%

Modules by API surface

utils.py22 symbols
PPO.py7 symbols
main.py1 symbols

For agents

$ claude mcp add PPO-Continuous-Pytorch \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact