A data-driven deep reinforcement learning library as an out-of-the-box tool
7.1K

d3rlpy is a data-driven deep reinforcement learning library as an out-of-the-box tool.
from d3rlpy.dataset import MDPDataset
from d3rlpy.algos import CQL
# MDPDataset takes arrays of state transitions
dataset = MDPDataset(observations, actions, rewards, terminals)
# train data-driven deep RL
cql = CQL()
cql.fit(dataset.episodes)
# ready to control
actions = cql.predict(x)
Documentation: https://d3rlpy.readthedocs.io
d3rlpy.d3rlpy supports Linux, macOS and Windows.
$ pip install d3rlpy
$ conda install -c conda-forge d3rlpy
$ docker run -it --gpus all --name d3rlpy takuseno/d3rlpy:latest bash
| algorithm | discrete control | continuous control | data-driven RL? |
|---|---|---|---|
| Behavior Cloning (supervised learning) | :white_check_mark: | :white_check_mark: | |
| Deep Q-Network (DQN) | :white_check_mark: | :no_entry: | |
| Double DQN | :white_check_mark: | :no_entry: | |
| Deep Deterministic Policy Gradients (DDPG) | :no_entry: | :white_check_mark: | |
| Twin Delayed Deep Deterministic Policy Gradients (TD3) | :no_entry: | :white_check_mark: | |
| Soft Actor-Critic (SAC) | :white_check_mark: | :white_check_mark: | |
| Batch Constrained Q-learning (BCQ) | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Bootstrapping Error Accumulation Reduction (BEAR) | :no_entry: | :white_check_mark: | :white_check_mark: |
| Advantage-Weighted Regression (AWR) | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Conservative Q-Learning (CQL) (recommended) | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Advantage Weighted Actor-Critic (AWAC) | :no_entry: | :white_check_mark: | :white_check_mark: |
| Policy in Latent Action Space (PLAS) | :no_entry: | :white_check_mark: | :white_check_mark: |
Basically, all features are available with every algorithm.

from d3rlpy.datasets import get_atari
from d3rlpy.algos import DiscreteCQL
from d3rlpy.metrics.scorer import evaluate_on_environment
from d3rlpy.metrics.scorer import discounted_sum_of_advantage_scorer
from sklearn.model_selection import train_test_split
# get data-driven RL dataset
dataset, env = get_atari('breakout-expert-v0')
# split dataset
train_episodes, test_episodes = train_test_split(dataset, test_size=0.2)
# setup algorithm
cql = DiscreteCQL(n_frames=4, q_func_factory='qr', scaler='pixel', use_gpu=True)
# start training
cql.fit(train_episodes,
eval_episodes=test_episodes,
n_epochs=100,
scorers={
'environment': evaluate_on_environment(env),
'advantage': discounted_sum_of_advantage_scorer
})
See more Atari datasets at d4rl-atari.

from d3rlpy.datasets import get_pybullet
from d3rlpy.algos import CQL
from d3rlpy.metrics.scorer import evaluate_on_environment
from d3rlpy.metrics.scorer import discounted_sum_of_advantage_scorer
from sklearn.model_selection import train_test_split
# get data-driven RL dataset
dataset, env = get_pybullet('hopper-bullet-mixed-v0')
# split dataset
train_episodes, test_episodes = train_test_split(dataset, test_size=0.2)
# setup algorithm
cql = CQL(q_func_factory='qr', use_gpu=True)
# start training
cql.fit(train_episodes,
eval_episodes=test_episodes,
n_epochs=300,
scorers={
'environment': evaluate_on_environment(env),
'advantage': discounted_sum_of_advantage_scorer
})
See more PyBullet datasets at d4rl-pybullet.
import gym
from d3rlpy.algos import SAC
from d3rlpy.online.buffers import ReplayBuffer
# setup environment
env = gym.make('HopperBulletEnv-v0')
eval_env = gym.make('HopperBulletEnv-v0')
# setup algorithm
sac = SAC(use_gpu=True)
# setup replay buffer
buffer = ReplayBuffer(maxlen=1000000, env=env)
# start training
sac.fit_online(env, buffer, n_steps=1000000, eval_env=eval_env)
Try a cartpole example on Google Colaboratory!
This library is designed as if born from scikit-learn. You can fully utilize scikit-learn's utilities to increase your productivity.
from sklearn.model_selection import train_test_split
from d3rlpy.metrics.scorer import td_error_scorer
train_episodes, test_episodes = train_test_split(dataset)
cql.fit(train_episodes,
eval_episodes=test_episodes,
scorers={'td_error': td_error_scorer})
You can naturally perform cross-validation.
from sklearn.model_selection import cross_validate
scores = cross_validate(cql, dataset, scoring={'td_error': td_error_scorer})
And more.
from sklearn.model_selection import GridSearchCV
gscv = GridSearchCV(estimator=cql,
param_grid={'actor_learning_rate': [3e-3, 3e-4, 3e-5]},
scoring={'td_error': td_error_scorer},
refit=False)
gscv.fit(train_episodes)
This library is fully formatted with black and yapf. You can format the entire scripts as follows:
$ ./scripts/format
This library is analyzed by mypy and pylint. You can check the code structures as follows:
$ ./scripts/lint
The unit tests are provided as much as possible.
This repository is using pytest-cov instead of pytest.
You can run the entire tests as follows:
$ ./scripts/test
If you give -p option, the performance tests with toy tasks are also run
(this will take minutes).
$ ./scripts/test -p
@misc{seno2020d3rlpy,
author = {Takuma Seno},
title = {d3rlpy: A data-driven deep reinforcement library as an out-of-the-box tool},
year = {2020},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/takuseno/d3rlpy}}
}
This work is supported by Information-technology Promotion Agency, Japan (IPA), Exploratory IT Human Resources Project (MITOU Program) in the fiscal year 2020.
Content type
Image
Digest
sha256:37e1aafdd…
Size
7.2 GB
Last updated
over 1 year ago
docker pull takuseno/d3rlpy