2020-04-07 18:07:39 -07:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2021-04-24 08:13:41 +02:00
|
|
|
if __name__ == "__main__":
|
2020-04-07 18:07:39 -07:00
|
|
|
# Do not import torch for testing purposes.
|
|
|
|
os.environ["RLLIB_TEST_NO_TORCH_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 torch, e.g. inside function
|
|
|
|
# signatures/typehints.
|
|
|
|
_register_all()
|
|
|
|
|
2022-06-01 09:29:16 +02:00
|
|
|
from ray.rllib.algorithms.a2c import A2C
|
2022-01-29 18:41:57 -08:00
|
|
|
|
2021-04-24 08:13:41 +02:00
|
|
|
assert "torch" not in sys.modules, "`torch` initially present, when it shouldn't!"
|
2020-04-07 18:07:39 -07:00
|
|
|
|
2021-04-24 08:13:41 +02:00
|
|
|
# Note: No ray.init(), to test it works without Ray
|
2022-06-01 09:29:16 +02:00
|
|
|
trainer = A2C(
|
2021-04-24 08:13:41 +02:00
|
|
|
env="CartPole-v0",
|
|
|
|
config={
|
2020-05-27 16:19:13 +02:00
|
|
|
"framework": "tf",
|
2021-04-24 08:13:41 +02:00
|
|
|
"num_workers": 0,
|
|
|
|
# Disable the logger due to a sort-import attempt of torch
|
|
|
|
# inside the tensorboardX.SummaryWriter class.
|
|
|
|
"logger_config": {
|
|
|
|
"type": "ray.tune.logger.NoopLogger",
|
|
|
|
},
|
2020-04-07 18:07:39 -07:00
|
|
|
},
|
|
|
|
)
|
|
|
|
trainer.train()
|
|
|
|
|
2022-03-15 09:34:21 -07:00
|
|
|
assert (
|
|
|
|
"torch" not in sys.modules
|
2022-06-01 09:29:16 +02:00
|
|
|
), "`torch` should not be imported after creating and training A3C!"
|
2020-04-15 13:25:16 +02:00
|
|
|
|
|
|
|
# Clean up.
|
|
|
|
del os.environ["RLLIB_TEST_NO_TORCH_IMPORT"]
|
2020-07-05 13:09:51 +02:00
|
|
|
|
|
|
|
print("ok")
|