-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsweep.py
More file actions
75 lines (62 loc) · 2.26 KB
/
Copy pathsweep.py
File metadata and controls
75 lines (62 loc) · 2.26 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Main
-Process the yml config file
-Create an agent instance
-Run the agent
"""
from src.agents import *
from src.utils.utils import (
updated_config,
update_nested_dict,
dict_print,
create_save_loc,
save_configs,
set_logger,
backup_code,
set_seed,
)
import wandb
import logging
def train():
# ############# handling the bash input arguments and yaml configuration file ###############
config = updated_config()
# create saving location
create_save_loc(config) # config['save_dir'] gets updated here!
save_dir = config["save_dir"]
# printing the configuration
dict_print(config)
# ############# Wandb setup ###############
wandb.init(
# project="AorticStenosis_XAI", # IGNORED IN SWEEP
config=config,
name=None if config["run_name"] == "" else config["run_name"],
# entity="rcl_stroke", # your wandb username or team name
mode=config["wandb_mode"], # one of "online", "offline" or "disabled" TODO ?? TODO Add the config!
notes=config["save_dir"], # to know where the model is saved!
)
# Update config based on wandb sweep selected configs
config_wandb = wandb.config
config = update_nested_dict(config, config_wandb)
# printing the configuration again
logging.info(f"################################ NEW CONFIGS ######################")
dict_print(config)
################## document config files
save_configs(config)
# ############# handling the logistics of (seed), and (logging) ###############
set_seed(config["train"]["seed"])
set_logger(save_dir, config["log_level"], "train", config["comment"])
backup_code(save_dir)
# ############# agent setup ###############
# Create the Agent and pass all the configuration to it then run it.
agent_class = globals()[config["agent"]]
agent = agent_class(config)
# ############# Run the system ###############
# if push_at_end exists in confid["model"] keys and is True, then train_push_at_end
if config["model"].get("push_at_end", False):
agent.train_push_at_end()
else:
agent.run()
agent.finalize()
if __name__ == "__main__":
config = updated_config()
wandb.agent(config['SWEEP_ID'], train, count=config['SWEEP_COUNT'])