-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
38 lines (30 loc) · 1003 Bytes
/
test.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
'''
Script to test a specific policy in an enviroment
Usage: python test.py --config-name=train
'''
import logging
import pathlib
import hydra
from omegaconf import DictConfig, OmegaConf
log = logging.getLogger(__name__)
OmegaConf.register_new_resolver("eval", eval)
@hydra.main(
version_base=None,
config_path=str(pathlib.Path(__file__).parent.joinpath('imitation','config')),
config_name="test"
)
def test(cfg):
print(OmegaConf.to_yaml(cfg))
log.info("Running test...")
# instanciate environment runner from cfg file
runner = hydra.utils.instantiate(cfg.task.env_runner)
# instanciate policy from cfg file
policy = hydra.utils.instantiate(cfg.policy)
# instanciate agent from policy
agent = hydra.utils.instantiate(cfg.agent, policy=policy, env=runner.env)
# run policy in environment
for i in range(cfg.num_episodes):
runner.reset()
runner.run(agent, cfg.max_steps)
if __name__ == "__main__":
test()