-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_experiment.py
89 lines (73 loc) · 2.64 KB
/
setup_experiment.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Creates a new folder for the experiment and copies the necessary files to run the experiment
import os
import argparse
from datetime import datetime
import json
class color:
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
def get_git_commit_hash():
try:
return os.popen("git rev-parse HEAD").read().strip()
except:
return "Unknown"
def main():
date = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
parser = argparse.ArgumentParser(description='Setup an experiment')
parser.add_argument(
'--experiment_name',
type=str,
help='Name of the experiment',
default="xai-nlp-benchmark-" + date,
required=False,
)
parser.add_argument(
'--artifact_path',
type=str,
help='Path to the artifact',
default="./artifacts",
required=False,
)
args = parser.parse_args()
# Create the experiment folder
artifacts_dir = os.path.join(args.artifact_path, args.experiment_name)
os.makedirs(artifacts_dir, exist_ok=True)
config_dir = os.path.join(artifacts_dir, "configs")
os.makedirs(config_dir, exist_ok=True)
print("Created experiment folder", artifacts_dir, end="\n\n")
# Update paths in the config files
project_configs = filter(
lambda x: x.endswith("project_config.json"), os.listdir("configs")
)
git_commit_hash = get_git_commit_hash()
for config in project_configs:
with open(f"./configs/{config}", "r") as f:
project_config = json.load(f)
project_config["general"]["artifacts_dir"] = artifacts_dir