2019-05-10 20:36:18 -07:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-02-19 21:18:45 +01:00
|
|
|
# Do not import tf for testing purposes.
|
2020-02-11 00:22:07 +01:00
|
|
|
os.environ["RLLIB_TEST_NO_TF_IMPORT"] = "1"
|
|
|
|
|
2022-03-24 04:32:29 -07:00
|
|
|
# Test registering (includes importing) all Trainers.
|
|
|
|
from ray.rllib import _register_all
|
|
|
|
|
|
|
|
# This should surface any dependency on tf, e.g. inside function
|
|
|
|
# signatures/typehints.
|
|
|
|
_register_all()
|
|
|
|
|
2019-05-10 20:36:18 -07:00
|
|
|
from ray.rllib.agents.a3c import A2CTrainer
|
2022-01-29 18:41:57 -08:00
|
|
|
|
|
|
|
assert (
|
|
|
|
"tensorflow" not in sys.modules
|
|
|
|
), "`tensorflow` initially present, when it shouldn't!"
|
2019-05-10 20:36:18 -07:00
|
|
|
|
2021-04-24 08:13:41 +02:00
|
|
|
# Note: No ray.init(), to test it works without Ray
|
2019-05-10 20:36:18 -07:00
|
|
|
trainer = A2CTrainer(
|
2022-01-29 18:41:57 -08:00
|
|
|
env="CartPole-v0", config={"framework": "torch", "num_workers": 0}
|
|
|
|
)
|
2019-05-10 20:36:18 -07:00
|
|
|
trainer.train()
|
|
|
|
|
2022-03-15 09:34:21 -07:00
|
|
|
assert (
|
|
|
|
"tensorflow" not in sys.modules
|
|
|
|
), "`tensorflow` should not be imported after creating and training A3CTrainer!"
|
2020-02-11 00:22:07 +01:00
|
|
|
|
|
|
|
# Clean up.
|
|
|
|
del os.environ["RLLIB_TEST_NO_TF_IMPORT"]
|
2020-06-25 19:01:32 +02:00
|
|
|
|
|
|
|
print("ok")
|