2020-04-20 21:47:28 +02:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import ray
|
2022-05-06 05:54:22 -07:00
|
|
|
import ray.rllib.algorithms.es as es
|
2020-06-13 17:51:50 +02:00
|
|
|
from ray.rllib.utils.test_utils import check_compute_single_action, framework_iterator
|
2020-04-20 21:47:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestES(unittest.TestCase):
|
|
|
|
def test_es_compilation(self):
|
|
|
|
"""Test whether an ESTrainer can be built on all frameworks."""
|
2020-10-12 22:49:48 +02:00
|
|
|
ray.init(num_cpus=4)
|
2022-05-02 16:55:28 +02:00
|
|
|
config = es.ESConfig()
|
2020-04-20 21:47:28 +02:00
|
|
|
# Keep it simple.
|
2022-05-02 16:55:28 +02:00
|
|
|
config.training(
|
|
|
|
model={
|
|
|
|
"fcnet_hiddens": [10],
|
|
|
|
"fcnet_activation": None,
|
|
|
|
},
|
|
|
|
noise_size=2500000,
|
|
|
|
episodes_per_batch=10,
|
|
|
|
train_batch_size=100,
|
|
|
|
)
|
|
|
|
config.rollouts(num_rollout_workers=1)
|
2022-02-08 16:43:00 +01:00
|
|
|
# Test eval workers ("normal" WorkerSet, unlike ES' list of
|
|
|
|
# RolloutWorkers used for collecting train batches).
|
2022-05-02 16:55:28 +02:00
|
|
|
config.evaluation(evaluation_interval=1, evaluation_num_workers=2)
|
2020-04-20 21:47:28 +02:00
|
|
|
|
2020-07-23 12:50:25 -07:00
|
|
|
num_iterations = 1
|
2020-04-20 21:47:28 +02:00
|
|
|
|
2020-07-02 13:03:10 +02:00
|
|
|
for _ in framework_iterator(config):
|
[RLlib] Upgrade gym version to 0.21 and deprecate pendulum-v0. (#19535)
* Fix QMix, SAC, and MADDPA too.
* Unpin gym and deprecate pendulum v0
Many tests in rllib depended on pendulum v0,
however in gym 0.21, pendulum v0 was deprecated
in favor of pendulum v1. This may change reward
thresholds, so will have to potentially rerun
all of the pendulum v1 benchmarks, or use another
environment in favor. The same applies to frozen
lake v0 and frozen lake v1
Lastly, all of the RLlib tests and have
been moved to python 3.7
* Add gym installation based on python version.
Pin python<= 3.6 to gym 0.19 due to install
issues with atari roms in gym 0.20
* Reformatting
* Fixing tests
* Move atari-py install conditional to req.txt
* migrate to new ale install method
* Fix QMix, SAC, and MADDPA too.
* Unpin gym and deprecate pendulum v0
Many tests in rllib depended on pendulum v0,
however in gym 0.21, pendulum v0 was deprecated
in favor of pendulum v1. This may change reward
thresholds, so will have to potentially rerun
all of the pendulum v1 benchmarks, or use another
environment in favor. The same applies to frozen
lake v0 and frozen lake v1
Lastly, all of the RLlib tests and have
been moved to python 3.7
* Add gym installation based on python version.
Pin python<= 3.6 to gym 0.19 due to install
issues with atari roms in gym 0.20
Move atari-py install conditional to req.txt
migrate to new ale install method
Make parametric_actions_cartpole return float32 actions/obs
Adding type conversions if obs/actions don't match space
Add utils to make elements match gym space dtypes
Co-authored-by: Jun Gong <jungong@anyscale.com>
Co-authored-by: sven1977 <svenmika1977@gmail.com>
2021-11-03 08:24:00 -07:00
|
|
|
for env in ["CartPole-v0", "Pendulum-v1"]:
|
2022-05-02 16:55:28 +02:00
|
|
|
trainer = config.build(env=env)
|
2021-08-16 22:01:01 +02:00
|
|
|
for i in range(num_iterations):
|
|
|
|
results = trainer.train()
|
|
|
|
print(results)
|
|
|
|
|
|
|
|
check_compute_single_action(trainer)
|
|
|
|
trainer.stop()
|
2020-07-02 13:03:10 +02:00
|
|
|
ray.shutdown()
|
2020-05-08 16:31:31 +02:00
|
|
|
|
2020-04-20 21:47:28 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import pytest
|
|
|
|
import sys
|
2022-01-29 18:41:57 -08:00
|
|
|
|
2020-04-20 21:47:28 +02:00
|
|
|
sys.exit(pytest.main(["-v", __file__]))
|