2018-12-11 17:21:53 -08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Runs one or more regression tests. Retries tests up to 3 times.
|
|
|
|
#
|
|
|
|
# Example usage:
|
2020-04-20 21:47:28 +02:00
|
|
|
# $ python run_regression_tests.py regression-tests/cartpole-es-[tf|torch].yaml
|
2020-02-15 23:50:44 +01:00
|
|
|
#
|
|
|
|
# When using in BAZEL (with py_test), e.g. see in ray/rllib/BUILD:
|
|
|
|
# py_test(
|
2020-03-12 04:39:47 +01:00
|
|
|
# name = "run_regression_tests",
|
|
|
|
# main = "tests/run_regression_tests.py",
|
|
|
|
# tags = ["learning_tests"],
|
|
|
|
# size = "enormous", # = 60min timeout
|
|
|
|
# srcs = ["tests/run_regression_tests.py"],
|
|
|
|
# data = glob(["tuned_examples/regression_tests/*.yaml"]),
|
|
|
|
# Pass `BAZEL` option and the path to look for yaml regression files.
|
|
|
|
# args = ["BAZEL", "tuned_examples/regression_tests"]
|
2020-02-15 23:50:44 +01:00
|
|
|
# )
|
2018-12-11 17:21:53 -08:00
|
|
|
|
2020-02-15 23:50:44 +01:00
|
|
|
from pathlib import Path
|
2018-12-11 17:21:53 -08:00
|
|
|
import sys
|
2020-02-15 23:50:44 +01:00
|
|
|
import yaml
|
2018-12-11 17:21:53 -08:00
|
|
|
|
|
|
|
import ray
|
|
|
|
from ray.tune import run_experiments
|
2020-05-11 20:24:43 -07:00
|
|
|
from ray.rllib import _register_all
|
2018-12-11 17:21:53 -08:00
|
|
|
|
2019-02-15 13:32:43 -08:00
|
|
|
if __name__ == "__main__":
|
2020-02-15 23:50:44 +01:00
|
|
|
# Bazel regression test mode: Get path to look for yaml files from argv[2].
|
|
|
|
if sys.argv[1] == "BAZEL":
|
|
|
|
# Get the path to use.
|
|
|
|
rllib_dir = Path(__file__).parent.parent
|
|
|
|
print("rllib dir={}".format(rllib_dir))
|
|
|
|
yaml_files = rllib_dir.rglob(sys.argv[2] + "/*.yaml")
|
|
|
|
yaml_files = sorted(
|
|
|
|
map(lambda path: str(path.absolute()), yaml_files), reverse=True)
|
|
|
|
# Normal mode: Get yaml files to run from command line.
|
|
|
|
else:
|
|
|
|
yaml_files = sys.argv[1:]
|
2018-12-11 17:21:53 -08:00
|
|
|
|
2020-02-15 23:50:44 +01:00
|
|
|
print("Will run the following regression files:")
|
|
|
|
for yaml_file in yaml_files:
|
|
|
|
print("->", yaml_file)
|
2018-12-11 17:21:53 -08:00
|
|
|
|
2020-02-15 23:50:44 +01:00
|
|
|
# Loop through all collected files.
|
|
|
|
for yaml_file in yaml_files:
|
|
|
|
experiments = yaml.load(open(yaml_file).read())
|
2018-12-11 17:21:53 -08:00
|
|
|
|
|
|
|
print("== Test config ==")
|
|
|
|
print(yaml.dump(experiments))
|
|
|
|
|
2020-02-15 23:50:44 +01:00
|
|
|
passed = False
|
2018-12-11 17:21:53 -08:00
|
|
|
for i in range(3):
|
2020-05-11 20:24:43 -07:00
|
|
|
try:
|
|
|
|
ray.init(num_cpus=5)
|
|
|
|
trials = run_experiments(experiments, resume=False, verbose=1)
|
|
|
|
finally:
|
|
|
|
ray.shutdown()
|
|
|
|
_register_all()
|
2018-12-11 17:21:53 -08:00
|
|
|
|
|
|
|
for t in trials:
|
2020-02-15 23:50:44 +01:00
|
|
|
if (t.last_result["episode_reward_mean"] >=
|
2018-12-11 17:21:53 -08:00
|
|
|
t.stopping_criterion["episode_reward_mean"]):
|
2020-02-15 23:50:44 +01:00
|
|
|
passed = True
|
|
|
|
break
|
2018-12-11 17:21:53 -08:00
|
|
|
|
2020-02-15 23:50:44 +01:00
|
|
|
if passed:
|
2018-12-11 17:21:53 -08:00
|
|
|
print("Regression test PASSED")
|
2020-02-15 23:50:44 +01:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
print("Regression test FAILED on attempt {}", i + 1)
|
2018-12-11 17:21:53 -08:00
|
|
|
|
2020-02-15 23:50:44 +01:00
|
|
|
if not passed:
|
|
|
|
print("Overall regression FAILED: Exiting with Error.")
|
|
|
|
sys.exit(1)
|