-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
61 lines (43 loc) · 1.68 KB
/
Copy pathrun.py
File metadata and controls
61 lines (43 loc) · 1.68 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
import shutil
import time
from datetime import datetime
from pathlib import Path
import ray
import hydra
import yaml
from omegaconf import DictConfig, OmegaConf
from utils import set_random_seeds, setup_logging
from hydra.utils import instantiate
@hydra.main(version_base=None, config_path="config",
config_name='ipbt_cls_0000'
)
def main(cfg: DictConfig) -> None:
ray.init(address=cfg.server.ray_address)
cfg.general.seed_base += cfg.general.seed_offset
set_random_seeds(cfg.general.seed_base)
exp_dir = Path(cfg.path.dir_exp)
if cfg.general.continue_auto:
exp_dir.mkdir(exist_ok=True, parents=True)
else:
shutil.rmtree(exp_dir, ignore_errors=True)
exp_dir.mkdir(parents=True)
setup_logging(exp_dir / '_log.txt')
OmegaConf.save(cfg, exp_dir / 'config.yaml')
print(f'Experiment name: {cfg.general.exp_name}')
# create a file, the name of which is cfg.general.exp_desc
with open(exp_dir / cfg.general.exp_desc, 'w') as f:
f.write('')
ss = instantiate(cfg.search_space, seed=cfg.general.seed_base)
@ray.remote(num_cpus=1, num_gpus=0.25)
def instantiate_task():
return instantiate(cfg.task, search_space=ss, cfg=cfg, _recursive_=False)
task = ray.get(instantiate_task.remote())
algo = instantiate(cfg.algo, search_space=ss, cfg=cfg, task=task, _recursive_=False)
st = time.time()
algo.run()
runtime = time.time() - st
yaml.safe_dump(runtime, open(exp_dir / 'runtime.yaml', 'w'))
print('Success', datetime.now().strftime('%d/%m/%Y | %H:%M:%S'),
f' | {cfg.general.exp_name} | seed offset {cfg.general.seed_offset}')
if __name__ == '__main__':
main()