stable-baselines3/docs/guide/quickstart.rst

40 lines
981 B
ReStructuredText
Raw Normal View History

2019-09-26 09:46:40 +00:00
.. _quickstart:
===============
Getting Started
===============
Most of the library tries to follow a sklearn-like syntax for the Reinforcement Learning algorithms.
Here is a quick example of how to train and run SAC on a Pendulum environment:
.. code-block:: python
import gym
from torchy_baselines.sac.policies import MlpPolicy
from torchy_baselines.common.vec_env import DummyVecEnv
from torchy_baselines import SAC
2020-01-20 15:19:35 +00:00
env = gym.make('Pendulum-v0')
2019-09-26 09:46:40 +00:00
model = SAC(MlpPolicy, env, verbose=1)
model.learn(total_timesteps=10000)
obs = env.reset()
for i in range(1000):
action = model.predict(obs)
obs, rewards, dones, info = env.step(action)
env.render()
Or just train a model with a one liner if
`the environment is registered in Gym <https://github.com/openai/gym/wiki/Environments>`_ and if
the policy is registered:
.. code-block:: python
from torchy_baselines import SAC
model = SAC('MlpPolicy', 'Pendulum-v0').learn(10000)