rlkit added MBBL environments
June 30, 2019 ยท View on GitHub
Reinforcement learning framework and algorithms implemented in PyTorch. This is the repo by Vitchyr Pong. We updated the environments so that we can perform benchmarking as part of the Model Based Reinforcement Learning Benchmarking Library (MBBL). Please refer to the project page for more information.
Benchmarking
Installation
Please follow the standard installation in the below original readme. Then please go to MBBL to install the mbbl package for the environments.
run the code
We only support the running of SAC and TD3. First copy the scripts under the root directory.
cp exp_scripts/*.sh ./
To run SAC or TD3 for example on HalfCheetah:
bash sac.sh gym_cheetah
bash td3.sh gym_cheetah
Original readme of rlkit
Implemented algorithms:
- Skew-Fit
- Reinforcement Learning with Imagined Goals (RIG)
- Special case of Skew-Fit: set power = 0
- paper
- Temporal Difference Models (TDMs)
- Only implemented in v0.1.2-. See Legacy Documentation section below.
- paper
- Documentation
- Hindsight Experience Replay (HER)
- (Double) Deep Q-Network (DQN)
- Soft Actor Critic (SAC)
- example script
- original paper and updated version
- TensorFlow implementation from author
- Includes the "min of Q" method, the entropy-constrained implementation, reparameterization trick, and numerical tanh-Normal Jacbian calcuation.
- Twin Delayed Deep Determinstic Policy Gradient (TD3)
To get started, checkout the example scripts, linked above.
What's New
Version 0.2
04/05/2019
The initial release for 0.2 has the following major changes:
- Remove
Serializableclass and use default pickle scheme. - Remove
PyTorchModuleclass and use nativetorch.nn.Moduledirectly. - Switch to batch-style training rather than online training.
- Makes code more amenable to parallelization.
- Implementing the online-version is straightforward.
- Refactor training code to be its own object, rather than being integrated
inside of
RLAlgorithm. - Refactor sampling code to be its own object, rather than being integrated
inside of
RLAlgorithm. - Implement Skew-Fit: State-Covering Self-Supervised Reinforcement Learning, a method for performing goal-directed exploration to maximize the entropy of visited states.
- Update soft actor-critic to more closely match TensorFlow implementation:
- Rename
TwinSACto justSAC. - Only have Q networks.
- Remove unnecessary policy regualization terms.
- Use numerically stable Jacobian computation.
- Rename
Overall, the refactors are intended to make the code more modular and readable than the previous versions.
Version 0.1
12/04/2018
- Add RIG implementation
12/03/2018
- Add HER implementation
- Add doodad support
10/16/2018
- Upgraded to PyTorch v0.4
- Added Twin Soft Actor Critic Implementation
- Various small refactor (e.g. logger, evaluate code)
Installation
- Copy
config_template.pytoconfig.py:
cp rlkit/launchers/config_template.py rlkit/launchers/config.py
- Install and use the included Ananconda environment
$ conda env create -f environment/[linux-cpu|linux-gpu|mac]-env.yml
$ source activate rlkit
(rlkit) $ python examples/ddpg.py
Choose the appropriate .yml file for your system.
These Anaconda environments use MuJoCo 1.5 and gym 0.10.5.
You'll need to get your own MuJoCo key if you want to use MuJoCo.
DISCLAIMER: the mac environment has only been tested without a GPU.
For an even more portable solution, try using the docker image provided in environment/docker.
The Anaconda env should be enough, but this docker image addresses some of the rendering issues that may arise when using MuJoCo 1.5 and GPUs.
The docker image supports GPU, but it should work without a GPU.
To use a GPU with the image, you need to have nvidia-docker installed.
Using a GPU
You can use a GPU by calling
import rlkit.torch.pytorch_util as ptu
ptu.set_gpu_mode(True)
before launching the scripts.
If you are using doodad (see below), simply use the use_gpu flag:
run_experiment(..., use_gpu=True)
Visualizing a policy and seeing results
During training, the results will be saved to a file called under
LOCAL_LOG_DIR/<exp_prefix>/<foldername>
LOCAL_LOG_DIRis the directory set byrlkit.launchers.config.LOCAL_LOG_DIR. Default name is 'output'.<exp_prefix>is given either tosetup_logger.<foldername>is auto-generated and based off ofexp_prefix.- inside this folder, you should see a file called
params.pkl. To visualize a policy, run
(rlkit) $ python scripts/run_policy.py LOCAL_LOG_DIR/<exp_prefix>/<foldername>/params.pkl
If you have rllab installed, you can also visualize the results
using rllab's viskit, described at
the bottom of this page
tl;dr run
python rllab/viskit/frontend.py LOCAL_LOG_DIR/<exp_prefix>/
to visualize all experiments with a prefix of exp_prefix. To only visualize a single run, you can do
python rllab/viskit/frontend.py LOCAL_LOG_DIR/<exp_prefix>/<folder name>
Alternatively, if you don't want to clone all of rllab, a repository containing only viskit can be found here. You can similarly visualize results with.
python viskit/viskit/frontend.py LOCAL_LOG_DIR/<exp_prefix>/
This viskit repo also has a few extra nice features, like plotting multiple Y-axis values at once, figure-splitting on multiple keys, and being able to filter hyperparametrs out.
Visualizing a goal-conditioned policy
To visualize a goal-conditioned policy, run
(rlkit) $ python scripts/run_goal_conditioned_policy.py
LOCAL_LOG_DIR/<exp_prefix>/<foldername>/params.pkl
Launching jobs with doodad
The run_experiment function makes it easy to run Python code on Amazon Web
Services (AWS) or Google Cloud Platform (GCP) by using
doodad.
It's as easy as:
from rlkit.launchers.launcher_util import run_experiment
def function_to_run(variant):
learning_rate = variant['learning_rate']
...
run_experiment(
function_to_run,
exp_prefix="my-experiment-name",
mode='ec2', # or 'gcp'
variant={'learning_rate': 1e-3},
)
You will need to set up parameters in config.py (see step one of Installation).
This requires some knowledge of AWS and/or GCP, which is beyond the scope of
this README.
To learn more, more about doodad, go to the repository.
Credits
A lot of the coding infrastructure is based on rllab. The serialization and logger code are basically a carbon copy of the rllab versions.
The Dockerfile is based on the OpenAI mujoco-py Dockerfile.
TODOs/Pull-Request requests
- Implement policy-gradient algorithms.
- Implement model-based algorithms.
Legacy Code (v0.1.2)
For Temporal Difference Models (TDMs) and the original implementation of
Reinforcement Learning with Imagined Goals (RIG), do
git checkout tags/v0.1.2.