forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_dependency_tf.py
42 lines (31 loc) · 1023 Bytes
/
test_dependency_tf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
# Do not import tf for testing purposes.
os.environ["RLLIB_TEST_NO_TF_IMPORT"] = "1"
# 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()
from ray.rllib.algorithms.a2c import A2CConfig
assert (
"tensorflow" not in sys.modules
), "`tensorflow` initially present, when it shouldn't!"
config = (
A2CConfig()
.environment("CartPole-v1")
.framework("torch")
.rollouts(num_rollout_workers=0)
)
# Note: No ray.init(), to test it works without Ray
algo = config.build()
algo.train()
assert (
"tensorflow" not in sys.modules
), "`tensorflow` should not be imported after creating and training A3C!"
# Clean up.
del os.environ["RLLIB_TEST_NO_TF_IMPORT"]
algo.stop()
print("ok")