2020-10-06 20:28:16 +02:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import ray
|
2022-05-13 15:05:05 -07:00
|
|
|
import ray.rllib.agents.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):
|
|
|
|
"""Test whether an MBMPOTrainer can be built with all frameworks."""
|
|
|
|
config = mbmpo.DEFAULT_CONFIG.copy()
|
|
|
|
config["num_workers"] = 2
|
|
|
|
config["horizon"] = 200
|
|
|
|
config["dynamics_model"]["ensemble_size"] = 2
|
|
|
|
num_iterations = 1
|
|
|
|
|
|
|
|
# Test for torch framework (tf not implemented yet).
|
|
|
|
for _ in framework_iterator(config, frameworks="torch"):
|
|
|
|
trainer = mbmpo.MBMPOTrainer(
|
2022-01-29 18:41:57 -08:00
|
|
|
config=config, env="ray.rllib.examples.env.mbmpo_env.CartPoleWrapper"
|
|
|
|
)
|
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__]))
|