# Stable Baselines3
Stable Baselines3 is a set of reliable implementations of reinforcement learning algorithms in PyTorch. It is the next major version of [Stable Baselines](https://github.com/hill-a/stable-baselines).
These algorithms will make it easier for the research community and industry to replicate, refine, and identify new ideas, and will create good baselines to build projects on top of. We expect these tools will be used as a base around which new ideas can be added, and as a tool for comparing a new approach against existing ones. We also hope that the simplicity of these tools will allow beginners to experiment with a more advanced toolset, without being buried in implementation details.
## Links
Repository:
https://github.com/DLR-RM/stable-baselines3
Blog post:
https://araffin.github.io/post/sb3/
Documentation:
https://stable-baselines3.readthedocs.io/en/master/
RL Baselines3 Zoo:
https://github.com/DLR-RM/rl-baselines3-zoo
SB3 Contrib:
https://github.com/Stable-Baselines-Team/stable-baselines3-contrib
## Quick example
Most of the library tries to follow a sklearn-like syntax for the Reinforcement Learning algorithms using Gym.
Here is a quick example of how to train and run PPO on a cartpole environment:
```python
import gymnasium
from stable_baselines3 import PPO
env = gymnasium.make("CartPole-v1", render_mode="human")
model = PPO("MlpPolicy", env, verbose=1)
model.learn(total_timesteps=10_000)
vec_env = model.get_env()
obs = vec_env.reset()
for i in range(1000):
action, _states = model.predict(obs, deterministic=True)
obs, reward, done, info = vec_env.step(action)
vec_env.render()
# VecEnv resets automatically
# if done:
# obs = vec_env.reset()
```
Or just train a model with a one liner if [the environment is registered in Gymnasium](https://gymnasium.farama.org/tutorials/gymnasium_basics/environment_creation/) and if [the policy is registered](https://stable-baselines3.readthedocs.io/en/master/guide/custom_policy.html):
```python
from stable_baselines3 import PPO
model = PPO("MlpPolicy", "CartPole-v1").learn(10_000)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/DLR-RM/stable-baselines3",
"name": "stable-baselines3",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "reinforcement-learning-algorithms reinforcement-learning machine-learning gymnasium gym openai stable baselines toolbox python data-science",
"author": "Antonin Raffin",
"author_email": "antonin.raffin@dlr.de",
"download_url": "https://files.pythonhosted.org/packages/d6/30/8ca42fdc67fee2eb024d355f33c54bfafaac474a8d4f3c647ad619e7bd7e/stable_baselines3-2.4.0.tar.gz",
"platform": null,
"description": "\n\n# Stable Baselines3\n\nStable Baselines3 is a set of reliable implementations of reinforcement learning algorithms in PyTorch. It is the next major version of [Stable Baselines](https://github.com/hill-a/stable-baselines).\n\nThese algorithms will make it easier for the research community and industry to replicate, refine, and identify new ideas, and will create good baselines to build projects on top of. We expect these tools will be used as a base around which new ideas can be added, and as a tool for comparing a new approach against existing ones. We also hope that the simplicity of these tools will allow beginners to experiment with a more advanced toolset, without being buried in implementation details.\n\n\n## Links\n\nRepository:\nhttps://github.com/DLR-RM/stable-baselines3\n\nBlog post:\nhttps://araffin.github.io/post/sb3/\n\nDocumentation:\nhttps://stable-baselines3.readthedocs.io/en/master/\n\nRL Baselines3 Zoo:\nhttps://github.com/DLR-RM/rl-baselines3-zoo\n\nSB3 Contrib:\nhttps://github.com/Stable-Baselines-Team/stable-baselines3-contrib\n\n## Quick example\n\nMost of the library tries to follow a sklearn-like syntax for the Reinforcement Learning algorithms using Gym.\n\nHere is a quick example of how to train and run PPO on a cartpole environment:\n\n```python\nimport gymnasium\n\nfrom stable_baselines3 import PPO\n\nenv = gymnasium.make(\"CartPole-v1\", render_mode=\"human\")\n\nmodel = PPO(\"MlpPolicy\", env, verbose=1)\nmodel.learn(total_timesteps=10_000)\n\nvec_env = model.get_env()\nobs = vec_env.reset()\nfor i in range(1000):\n action, _states = model.predict(obs, deterministic=True)\n obs, reward, done, info = vec_env.step(action)\n vec_env.render()\n # VecEnv resets automatically\n # if done:\n # obs = vec_env.reset()\n\n```\n\nOr just train a model with a one liner if [the environment is registered in Gymnasium](https://gymnasium.farama.org/tutorials/gymnasium_basics/environment_creation/) and if [the policy is registered](https://stable-baselines3.readthedocs.io/en/master/guide/custom_policy.html):\n\n```python\nfrom stable_baselines3 import PPO\n\nmodel = PPO(\"MlpPolicy\", \"CartPole-v1\").learn(10_000)\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Pytorch version of Stable Baselines, implementations of reinforcement learning algorithms.",
"version": "2.4.0",
"project_urls": {
"Changelog": "https://stable-baselines3.readthedocs.io/en/master/misc/changelog.html",
"Code": "https://github.com/DLR-RM/stable-baselines3",
"Documentation": "https://stable-baselines3.readthedocs.io/",
"Homepage": "https://github.com/DLR-RM/stable-baselines3",
"RL-Zoo": "https://github.com/DLR-RM/rl-baselines3-zoo",
"SB3-Contrib": "https://github.com/Stable-Baselines-Team/stable-baselines3-contrib",
"SBX": "https://github.com/araffin/sbx"
},
"split_keywords": [
"reinforcement-learning-algorithms",
"reinforcement-learning",
"machine-learning",
"gymnasium",
"gym",
"openai",
"stable",
"baselines",
"toolbox",
"python",
"data-science"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cad72b16532ef5a898d540a3172e35184585c2145a50dab1bd7cd74592805b81",
"md5": "60d803ac81a6a086c71b9bb4106a98f9",
"sha256": "c37c6986d8b3b253e4e52620dc1e4eaeb28b896ee411de289782deab8f83721f"
},
"downloads": -1,
"filename": "stable_baselines3-2.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "60d803ac81a6a086c71b9bb4106a98f9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 183910,
"upload_time": "2024-11-18T10:03:24",
"upload_time_iso_8601": "2024-11-18T10:03:24.983454Z",
"url": "https://files.pythonhosted.org/packages/ca/d7/2b16532ef5a898d540a3172e35184585c2145a50dab1bd7cd74592805b81/stable_baselines3-2.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d6308ca42fdc67fee2eb024d355f33c54bfafaac474a8d4f3c647ad619e7bd7e",
"md5": "9b34190b33658d1ed55b255fa944dabd",
"sha256": "c56f70c10e0a99973130a0ebee83619d0ec3bf1197e0196383276404d2190cc1"
},
"downloads": -1,
"filename": "stable_baselines3-2.4.0.tar.gz",
"has_sig": false,
"md5_digest": "9b34190b33658d1ed55b255fa944dabd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 212133,
"upload_time": "2024-11-18T10:03:27",
"upload_time_iso_8601": "2024-11-18T10:03:27.713093Z",
"url": "https://files.pythonhosted.org/packages/d6/30/8ca42fdc67fee2eb024d355f33c54bfafaac474a8d4f3c647ad619e7bd7e/stable_baselines3-2.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-18 10:03:27",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "DLR-RM",
"github_project": "stable-baselines3",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "stable-baselines3"
}