There is only one line of code that is different.
Which algorithm is better?
The only difference: the epsilon value to avoid division by zero in the optimizer
(one is eps=1e-7
the other eps=1e-5)
import gymnasium as gym
from stable_baselines3 import SAC
# Train an agent using Soft Actor-Critic on Pendulum-v1
env = gym.make("Pendulum-v1")
model = SAC("MlpPolicy", env).learn(total_timesteps=20_000)
# Save the model
model.save("sac_pendulum")
# Load the trained model
model = SAC.load("sac_pendulum")
# Start a new episode
obs, _ = env.reset()
# What action to take in state `obs`?
action, _ = model.predict(obs, deterministic=True)
https://github.com/DLR-RM/stable-baselines3
Raffin, Antonin, et al. "Stable-baselines3: Reliable reinforcement learning implementations." JMLR (2021)
Using SB3 + Jax = SBX: https://github.com/araffin/sbx
https://iclr-blog-track.github.io/2022/03/25/ppo-implementation-details/
Huang, Shengyi, et al. "Open RL Benchmark: Comprehensive Tracked Experiments for RL." (2024).
Periodic Policy
Raffin et al. "An Open-Loop Baseline for Reinforcement Learning Locomotion Tasks", RLJ 2024.
Outstanding Paper Award on Empirical Resourcefulness in RL
Raffin, Antonin "Enabling Reinforcement Learning on Real Robots." Diss. TUM, 2024.
# Note: desired_joint_pos is of dimension 12 (3 joints per leg)
desired_joint_pos = default_joint_pos + scale * action
# Debugging action space
import ipdb; ipdb.set_trace()
>> vec_env.action_space
Box(-100.0, 100.0, (12,), float32)
def objective(trial: optuna.Trial) -> float:
"""Optimize for best performance after 5 minutes of training."""
# Sample hyperparameters
hyperparams = sample_sac_params(trial)
agent = sbx.SAC(env=env, **hyperparams)
# Callback to exit the training loop after 5 minutes
callback = TimeoutCallback(timeout=60 * 5)
# Train with a max budget of 50_000_000 timesteps
agent.learn(total_timesteps=int(5e7), callback=callback)
# Log the number of interactions with the environments
trial.set_user_attr("num_timesteps", agent.num_timesteps)
# Evaluate the trained agent
env.seed(args_cli.seed)
mean_reward, std_reward = evaluate_policy(agent, env, n_eval_episodes=512)
return mean_reward
A GUI to train and visualize RL policies with SB3 in the Newton simulator
Mechanical engineers can train and visualize policies without RL expertise
truncation vs termination
Timeout: max_episode_steps=4