Repository navigation
Expand file tree
/
Copy pathauto_script_all.py
More file actions
127 lines (111 loc) · 3.77 KB
/
Copy pathauto_script_all.py
File metadata and controls
127 lines (111 loc) · 3.77 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import subprocess
from concurrent.futures import ThreadPoolExecutor, as_completed
import subprocess
import time
def run_cmd(cmd, output, timeout=None):
"""
Run command (list form) with subprocess.run, return a dict with results.
cmd: list, e.g. ['python', '-c', 'import time; time.sleep(1)']
timeout: seconds or None
"""
start = time.time()
try:
proc = subprocess.run(cmd, text=True, check=False, timeout=timeout, stdout=open(output, 'wb'))
return {
"cmd": cmd,
"returncode": proc.returncode,
"stdout": proc.stdout,
"stderr": proc.stderr,
"duration": time.time() - start,
"timed_out": False,
}
except subprocess.TimeoutExpired as e:
return {
"cmd": cmd,
"returncode": None,
"stdout": e.stdout or "",
"stderr": str(e),
"duration": time.time() - start,
"timed_out": True,
}
def run_parallel(commands, outputs, max_workers=4, timeout=None):
"""
commands: list of list (each inner is argv list)
outputs: list of output file paths corresponding to each command
max_workers: maximum concurrent subprocesses
timeout: per-process timeout in seconds (or None)
Returns: list of result dicts in order of completion.
"""
results = []
with ThreadPoolExecutor(max_workers=max_workers) as exe:
futures = {exe.submit(run_cmd, cmd, output, timeout): cmd for cmd, output in zip(commands, outputs)}
for fut in as_completed(futures):
res = fut.result()
# simple progress print
print(f"Finished: {res['cmd']} -> rc={res['returncode']} (took {res['duration']:.2f}s)")
results.append(res)
return results
def main():
print('Running set of commands...')
command = [
"python",
"main.py"
]
common_commands = [
"seed=0",
"load_ckp=0",
"enable_log=false",
"compile=false",
"mode=eval",
]
molecule_option = ['task.test.molecular.how_many_to_generate=10', '+options=remap_cls']
generic_option = ['task.test.graph.how_many_to_generate=10']
num_graphs_comm = {
'qm9': molecule_option,
'zinc': molecule_option,
'comm': generic_option,
'ego-small': generic_option,
'enz': generic_option,
'ego': generic_option
}
ifh_ds_models = {
'qm9': ['1-2', '1-4'],
'zinc' : ['1-3', '1-4-8'],
'comm': ['1-2', '1-2-8'],
'ego-small': ['1-2', '1-2-8'],
'ego': ['1-3', '1-4-16']
}
mifh_ds_models = {
'comm': ['deg-dist'],
'ego-small': ['deg-dist'],
'enz': ['deg-dist'],
'ego': ['deg-dist']
}
# ifh_ds_models = {
# 'qm9': ['1-2', '1-4'],
# 'zinc' : ['1-3', '1-4-8'],
# }
# mifh_ds_models = {
# 'comm': ['deg-dist'],
# 'ego-small': ['deg-dist'],
# 'ego': ['deg-dist']
# }
commands = [
command +
[f"+preset/ifh/{ds}={model}"] +
common_commands +
num_graphs_comm[ds] for ds, models in ifh_ds_models.items() for model in models
]
commands += [
command +
[f"+preset/mifh/{ds}={model}"] +
common_commands +
num_graphs_comm[ds] for ds, models in mifh_ds_models.items() for model in models
]
outputs = [f"outputs/all_gen/out_{ds}_{model}.txt" for ds, models in ifh_ds_models.items() for model in models]
outputs += [f"outputs/all_gen/out_{ds}_{model}.txt" for ds, models in mifh_ds_models.items() for model in models]
#print(commands)
all_results = run_parallel(commands, outputs, max_workers=6)
print("All commands completed.")
if __name__ == "__main__":
main()