-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
58 lines (51 loc) · 1.73 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
__author__ = "Lucas de Vries"
Main
-Capture the config file
-Process the json config passed
-Create an agent instance
-Run the agent
"""
import argparse
from utils.config import process_config
from utils.train_utils import set_seed
import wandb
from agents import *
from pprint import pprint
from utils.dirs import create_dirs
import json
def main():
# parse the path of the json config file
arg_parser = argparse.ArgumentParser(description="")
arg_parser.add_argument(
'config',
metavar='config_json_file',
default='None',
help='The Configuration file in json format')
args = arg_parser.parse_args()
# parse the config json file
config = process_config(args.config)
# set environment variable for offline runs
os.environ["WANDB_MODE"] = "online"
# Pass them to wandb.init
wandb.init(config=dict(config))
# Access all hyperparameter values through wandb.config
config = wandb.config
set_seed(config['seed'])
config['run_name'] = wandb.run.name
config['run_id'] = wandb.run.id
#Make the folders that were previously in the expeiment folder
config['checkpoint_dir'] = os.path.join(wandb.run.dir, 'experiments', 'checkpoints/')
config['json_dir'] = os.path.join(wandb.run.dir, 'experiments', 'config/')
create_dirs([config['checkpoint_dir'], config['json_dir']])
_dir = os.path.join(config['json_dir'], str(config['run_id'])+'_parameters.json')
with open(_dir, 'w') as f:
json.dump(dict(config), f)
pprint(config)
# Create the Agent and pass all the configuration to it then run it..
agent_class = globals()[config['agent']]
agent = agent_class()
agent.run()
agent.finalize()
if __name__ == '__main__':
main()