2022-02-04 17:01:12 +01:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import ray
|
|
|
|
import ray.rllib.agents.slateq as slateq
|
2022-02-22 09:36:44 +01:00
|
|
|
from ray.rllib.examples.env.recommender_system_envs_with_recsim import (
|
|
|
|
InterestEvolutionRecSimEnv,
|
2022-02-04 17:01:12 +01:00
|
|
|
)
|
|
|
|
from ray.rllib.utils.test_utils import (
|
|
|
|
check_compute_single_action,
|
|
|
|
check_train_results,
|
|
|
|
framework_iterator,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class TestSlateQ(unittest.TestCase):
|
|
|
|
"""Sanity tests for Slateq algorithm."""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
ray.init(num_cpus=4)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
ray.shutdown()
|
|
|
|
|
|
|
|
def test_slateq_compilation(self):
|
2022-02-22 09:36:44 +01:00
|
|
|
"""Test whether a SlateQTrainer can be built with both frameworks."""
|
2022-02-04 17:01:12 +01:00
|
|
|
config = {
|
2022-02-22 09:36:44 +01:00
|
|
|
"env": InterestEvolutionRecSimEnv,
|
|
|
|
"learning_starts": 1000,
|
2022-02-04 17:01:12 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 09:36:44 +01:00
|
|
|
num_iterations = 2
|
2022-02-04 17:01:12 +01:00
|
|
|
|
2022-02-22 09:36:44 +01:00
|
|
|
# TODO: Add tf and switch with-eager-tracing to True.
|
|
|
|
for _ in framework_iterator(
|
|
|
|
config, frameworks=("tf2", "torch"), with_eager_tracing=False
|
|
|
|
):
|
2022-02-04 17:01:12 +01:00
|
|
|
trainer = slateq.SlateQTrainer(config=config)
|
|
|
|
for i in range(num_iterations):
|
|
|
|
results = trainer.train()
|
|
|
|
check_train_results(results)
|
|
|
|
print(results)
|
|
|
|
check_compute_single_action(trainer)
|
|
|
|
trainer.stop()
|
|
|
|
|
|
|
|
def test_slateq_loss_function(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import pytest
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.exit(pytest.main(["-v", __file__]))
|