-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubmit.py
More file actions
140 lines (120 loc) · 5 KB
/
submit.py
File metadata and controls
140 lines (120 loc) · 5 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
128
129
130
131
132
133
134
135
136
137
138
139
140
import numpy as np
from pathlib import Path
import yaml
import os
import shutil
import fileinput
from src.utils import A_0, nm
file_name = "sbatch.template"
submit_name = "sbatch.sbatch"
replace_name = "JOB_NAME"
replace_args = "ARGS_PATH"
replace_path = "DIR_PATH"
def main(job_names, command_strs):
for command_str, job_name in zip(command_strs, job_names):
shutil.copyfile(file_name, submit_name)
with fileinput.FileInput(submit_name, inplace=True) as file:
for line in file:
print(line.replace(replace_args, command_str), end="")
with fileinput.FileInput(submit_name, inplace=True) as file:
for line in file:
print(line.replace(replace_name, job_name), end="")
with fileinput.FileInput(submit_name, inplace=True) as file:
dir_path = str(Path(command_str).parent)
for line in file:
print(line.replace(replace_path, dir_path), end="")
os.system(f"sbatch {submit_name}")
print("DONE")
if __name__ == "__main__":
args = {
"target_angle": np.pi / 2.0,
"target_dist": A_0 * nm,
"w_dist_orient": 0.5,
"w_reg": 500.0,
"w_phase": 0.0,
"cma_sigma": 0.25,
"cma_opts": {"popsize": 100, "tolfun": 1e-3, "tolx": 5e-4},
"ZeroCoeffs": [0, 1, 2, 5, 6, 7, 8, 9, 10],
"x_0_init": 0.25,
"width": 400 * nm,
"polarization": [1, 1j],
"Nmax": 4,
"rho_scale": 1.0,
"power": 0.25,
"radius": 75 * nm,
"lmax": 2,
"wavelength": 770 * nm,
"e_field_sampling": 50,
"min_sep_dist": 200 * nm,
"max_sep_fac": 2,
"save_path": None,
"save_freq": 10,
"sim_init_sep": 700 * nm,
"sim_init_angle": np.pi / 2.0,
}
# dir_name = "Experiments/Trials_50"
# N_trails = 50
# dir_name = "Experiments/Trials_sep_params"
# N_trails = 10
# sep_dists = [150 * nm, 200 * nm, 250 * nm]
# max_sep_facs = [2, 3, 4]
# x_0_inits = [0.25, [0.8239384, 0.02414681, -3.40704586, 1.37237894, -0.14930837]]
# w_regs = [100.0, 500.0, 2500.0]
# dir_name = "Experiments/more_bindings_v4"
dir_name = "Experiments/more_bindings_moreEval_2nd3rd"
N_trails = 10
sep_dists = [200 * nm]
max_sep_facs = [5]
x_0_inits = [0.5, 1.0, 2.0, 3.0]
# x_0_inits = [1.0, 2.0, 3.0, 4.0]
# x_0_inits = [
# 1,
# 2,
# [2.25616176, 0.40949393, -3.01409651, 1.33885962, -1.78278619],
# [-1.15905219, 0.71659915, -5.26650067, 2.52866329, 0.73721344],
# ]
w_regs = [1.0, 10.0, 100.0, 1000.0]
w_phases = [1.0, 10.0, 100.0, 1000.0]
# target_seps = [1, 2, 3, 4]
# target_seps = [578, 1160, 1740]
target_seps = [1160, 1740]
# target_seps = [578]
# target_seps = [1740]
job_names = list()
arg_paths = list()
for trial in range(N_trails):
for sep_dist in sep_dists:
for max_sep_fac in max_sep_facs:
for x_0_init in x_0_inits:
for w_reg in w_regs:
for target_sep in target_seps:
for w_phase in w_phases:
if isinstance(x_0_init, list):
x_0_name = "fixed"
# if x_0_init == x_0_inits[0]:
# x_0_name = "1st"
# elif x_0_init == x_0_inits[1]:
# x_0_name = "2nd"
else:
# x_0_name = "random"
x_0_name = x_0_init
exp_name = f"/sep_dist={int(sep_dist / nm)}-max_sep_fac={int(max_sep_fac)}-x_0={x_0_name}-w_reg={int(w_reg)}-trial={trial}-target_dist={int(target_sep)}-w_phase={int(w_phase)}"
args["sep_dist"] = sep_dist
args["max_sep_fac"] = max_sep_fac
args["x_0_init"] = x_0_init
args["w_reg"] = w_reg
args["target_dist"] = target_sep * nm
args["w_phase"] = w_phase
args["save_path"] = dir_name + exp_name
if args["save_path"] is not None:
save_path = Path(args["save_path"])
save_path.mkdir(parents=True, exist_ok=True)
with open(
save_path / "params.yaml", "w"
) as yaml_file:
yaml.dump(
args, yaml_file, default_flow_style=False
)
job_names.append(exp_name)
arg_paths.append(str(save_path / "params.yaml"))
main(job_names, arg_paths)