2020-10-06 20:28:16 +02:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import ray
|
2022-05-16 00:45:32 -07:00
|
|
|
import ray.rllib.algorithms.mbmpo as mbmpo
|
2022-01-29 18:41:57 -08:00
|
|
|
from ray.rllib.utils.test_utils import (
|
|
|
|
check_compute_single_action,
|
|
|
|
check_train_results,
|
|
|
|
framework_iterator,
|
|
|
|
)
|
2020-10-06 20:28:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestMBMPO(unittest.TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
ray.init()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
ray.shutdown()
|
|
|
|
|
|
|
|
def test_mbmpo_compilation(self):
|
2022-06-04 07:35:24 +02:00
|
|
|
"""Test whether MBMPO can be built with all frameworks."""
|
2022-05-30 17:33:01 +02:00
|
|
|
config = (
|
|
|
|
mbmpo.MBMPOConfig()
|
|
|
|
.rollouts(num_rollout_workers=2, horizon=200)
|
|
|
|
.training(dynamics_model={"ensemble_size": 2})
|
|
|
|
.environment(env="ray.rllib.examples.env.mbmpo_env.CartPoleWrapper")
|
|
|
|
)
|
2020-10-06 20:28:16 +02:00
|
|
|
num_iterations = 1
|
|
|
|
|
|
|
|
# Test for torch framework (tf not implemented yet).
|
|
|
|
for _ in framework_iterator(config, frameworks="torch"):
|
2022-05-30 17:33:01 +02:00
|
|
|
trainer = config.build()
|
2021-09-30 16:39:05 +02:00
|
|
|
|
2020-10-06 20:28:16 +02:00
|
|
|
for i in range(num_iterations):
|
2021-09-30 16:39:05 +02:00
|
|
|
results = trainer.train()
|
|
|
|
check_train_results(results)
|
|
|
|
print(results)
|
|
|
|
|
2022-01-29 18:41:57 -08:00
|
|
|
check_compute_single_action(trainer, include_prev_action_reward=False)
|
2020-10-06 20:28:16 +02:00
|
|
|
trainer.stop()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import pytest
|
|
|
|
import sys
|
2022-01-29 18:41:57 -08:00
|
|
|
|
2020-10-06 20:28:16 +02:00
|
|
|
sys.exit(pytest.main(["-v", __file__]))
|