シンプルな分散強化学習フレームワークを目指して作成しています。
以下の特徴があります。
- 分散強化学習のサポート
- 環境とアルゴリズム間のインタフェースの自動調整
- Gym/Gymnasiumの環境に対応
- カスタマイズ可能な環境クラスの提供
- カスタマイズ可能な強化学習アルゴリズムクラスの提供
- 有名な強化学習アルゴリズムの提供
- (新しいアルゴリズムへの対応)
ドキュメント
https://pocokhc.github.io/simple_distributed_rl/
アルゴリズムの解説記事(Qiita)
https://qiita.com/pocokhc/items/a2f1ba993c79fdbd4b4d
- Pypiからインストールできます。
# 基本的な機能のみをインストール
pip install srl-framework
# 主要な拡張機能や補助的なライブラリも含めてインストール(※TensorFlowやPyTorchは含まれません)
pip install srl-framework[full]Tensorflow/PyTorchは含まれないので別途インストールしてください。
- Tensorflow
- https://www.tensorflow.org/install?hl=ja
- tensorflow-probability[tf]
- PyTorch
インストールされるライブラリの詳細や、ダウンロードのみでの使い方は以下のドキュメントを参照してください。
https://pocokhc.github.io/simple_distributed_rl/pages/install.html
簡単な使い方は以下です。
import srl
from srl.algorithms import ql # qlアルゴリズムのimport
def main():
# runnerの作成
runner = srl.Runner("Grid", ql.Config())
# 学習
runner.train(timeout=10)
# 学習結果の評価
rewards = runner.evaluate()
print(f"evaluate episodes: {rewards}")
# 可視化例
runner.animation_save_gif("Grid.gif")
if __name__ == "__main__":
main()animation_save_gifで生成された画像は以下です。
使い方の詳細は以下のドキュメントを参照してください。 https://pocokhc.github.io/simple_distributed_rl/pages/howtouse.html
自作の環境とアルゴリズムの作成に関しては以下のドキュメントを参照してください。
| Algorithm | Observation | Action | Tensorflow | Torch | Comment |
|---|---|---|---|---|---|
| QL | Discrete | Discrete | Basic Q Learning | ||
| DQN | Box | Discrete | ✔ | ✔ | |
| C51 | Box | Discrete | ✔ | - | CategoricalDQN |
| Rainbow | Box | Discrete | ✔ | ✔ | |
| R2D2 | Box | Discrete | ✔ | - | |
| Agent57 | Box | Discrete | ✔ | ✔ | |
| SND | Box | Discrete | ✔ | - | |
| Go-Explore | Box | Discrete | ✔ | - | DQN base, R2D3 memory base |
| Algorithm | Observation | Action | Tensorflow | Torch | Comment |
|---|---|---|---|---|---|
| VanillaPolicy | Discrete | Discrete Continuous |
|||
| A3C/A2C | - | - | - | - | Not implemented |
| TRPO | - | - | - | - | Not implemented |
| PPO | Box | Discrete Continuous |
✔ | - | |
| DDPG/TD3 | Box | Continuous | ✔ | - | |
| SAC | Box | Discrete Continuous |
✔ | - |
| Algorithm | Observation | Action | Tensorflow | Torch | Comment |
|---|---|---|---|---|---|
| MCTS | Discrete | Discrete | MDP base | ||
| AlphaZero | Image(shape) | Discrete | ✔ | - | MDP base |
| MuZero | Image(shape) | Discrete | ✔ | - | |
| StochasticMuZero | Box | Discrete | ✔ | - | |
| EfficientZeroV2 | Box | Discrete Continuous |
✔ | - |
| Algorithm | Observation | Action | Framework | Comment |
|---|---|---|---|---|
| DynaQ | Discrete | Discrete | - |
| Algorithm | Observation | Action | Tensorflow | Torch | Comment |
|---|---|---|---|---|---|
| WorldModels | Box | Discrete | ✔ | - | |
| PlaNet | Box | Discrete | ✔(+tensorflow-probability) | - | |
| Dreamer | - | - | - | - | merge DreamerV3 |
| DreamerV2 | - | - | - | - | merge DreamerV3 |
| DreamerV3 | Box | Discrete Continuous |
✔(+tensorflow-probability) | - | |
| DIAMOND | Image | Discrete | ✔ | - |
| Algorithm | Observation | Action | Framework | Comment |
|---|---|---|---|---|
| CQL | Discrete | Discrete | ProgressRate: 0% |
| Algorithm | Observation | Action | Framework | Comment |
|---|---|---|---|---|
| QL_agent57 | Discrete | Discrete | QL + Agent57 Progress:80% |
|
| Agent57_light | Box | Discrete | TF Torch |
Agent57 - (LSTM,MultiSteps) |
| SearchDynaQ | Discrete | Discrete | Original(ModelBase) QL(TableBase)+PolicyIteration+IntrinsicReward |
|
| GoDynaQ | Discrete | Discrete | Original(ModelBase) SearchDynaQ+Go-Explore |
|
| GoDQN | Box | Discrete | TF | Original(Progress:90%) DQN+Go-Explore |
| DQN_NoT | Box | Discrete | Torch | Original No Target DQN |
| GoDQ_v1 | Box | Discrete | Torch | Original NoT_DQN + BYOL-Explorer(IntrinsicReward) + Archive + SR-SPR |
| GoDQ_v1_LSTM | Box | Discrete | Torch | Original GoDQ_v1+LSTM |
| PPO-V | Box | Discrete Continuous |
Torch | Original OffPolicy PPO |
| SAC-NoT | Box | Discrete Continuous |
Torch | Original No Target SAC |
ネットワーク経由での分散学習は以下のドキュメントを参照してください。
またクラウドサービスとの連携はQiita記事を参照
- 疑似コード
※実装側の動作に関してはアルゴリズムの作成方法を参照
# 学習単位の初期化
env.setup()
worker.setup()
trainer.setup()
for episode in range(N)
# 1エピソードの初期化
env.reset()
worker.reset()
# 1エピソードのループ
while not env.done:
# アクションを取得
action = worker.policy()
# 描画
env.render()
worker.render()
# 環境の1stepを実行
env.step(action)
worker.on_step()
# 学習
trainer.train()
# 終了後の描画
env.render()
# 学習単位の終了
env.teardown()
worker.teardown()
trainer.teardown()Look dockers folder
- PC1
- windows11
- CPUx1: Core i7-8700 3.2GHz
- GPUx1: NVIDIA GeForce GTX 1060 3GB
- memory 48GB
- PC2
- windows11
- CPUx1: Core i9-12900 2.4GHz
- GPUx1: NVIDIA GeForce RTX 3060 12GB
- memory 32GB

