forked from MorphologicalComputations/SpringMassNetworks
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrain.py
executable file
·243 lines (209 loc) · 11.1 KB
/
train.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#! /usr/bin/env python2
from roboTraining.experiment import *
if __name__ == "__main__":
"""Start the experiment function with different parameters"""
trainingIt = 15000
simTime = 10
# Get MPI info
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
machine = platform.node()
# Print machine info
print("\n == Initializing Robot Training Experiment == ")
print("\n Date: " + str(datetime.datetime.now()))
print(" Machine: " + machine + " (" + str(rank+1) + "/" + str(size) + ")")
print(" OS: " + str(platform.system()) + " version " + str(platform.release()))
print(" Python version: " + str(platform.python_version ()))
print(" Argument List: " + str(sys.argv) + "\n")
# Do experiment
if len(sys.argv) > 1:
# Different couple of amplitude and omega to create a pareto curve
if sys.argv[1].lower() == "pareto":
# Get arg list and estimate iteration number and time
arg_list = createParetoVal(3)
fileName = "Machine-" + str(rank)
n_iteration = int(math.ceil(len(arg_list)/float(size)))
print(" == Running " + str(len(arg_list)) + " experiments on " + str(size) + \
" processors: " + str(n_iteration) + " optimizations expected in approximately " + \
"{:.2f} hours == \n".format(float(simTime) / 20 * trainingIt * n_iteration / 3600))
# Simulate multiple time if the number of cores does not correspond to number of points
for i in range(n_iteration):
index = i * size + rank
if index < len(arg_list):
print("-- " + machine + " (" + str(rank+1) + "/" + str(size) + ")" + \
" -- Experiment " + str(index+1) + " with Omega=" + \
str(arg_list[index][0]) + " and Amplitude=" + str(arg_list[index][1]))
e = Experiment(fileName_=fileName, folderName_="Pareto", omega_=arg_list[index][0], \
simTime_=simTime, maxIter_=trainingIt, maxAmplitude_=arg_list[index][1])
e.run()
# Different couple of simulation time and optimization methods
if sys.argv[1].lower() == "simtime":
# Get arg list and estimate iteration number and time
arg_list = createSimTimeVal()
fileName = "Machine-" + str(rank)
n_iteration = int(math.ceil(len(arg_list)/float(size)))
time = 0
for i in range(n_iteration):
index = i * size + rank
if index < len(arg_list):
time += float(arg_list[index][0]) / 20 * trainingIt / 3600
print(" == Running " + str(len(arg_list)) + " experiments on " + str(size) + \
" processors: " + str(n_iteration) + " optimizations expected in approximately " + \
"{:.2f} hours == \n".format(time) )
# Simulate multiple time if the number of cores does not correspond to number of points
for i in range(n_iteration):
index = i * size + rank
if index < len(arg_list):
print("-- " + machine + " (" + str(rank+1) + "/" + str(size) + ")" + \
" -- Experiment " + str(index+1) + " with SimTime=" + \
str(arg_list[index][0]) + " and Optmization=" + str(arg_list[index][1]))
e = Experiment(fileName_=fileName, folderName_="SimTime", simTime_=arg_list[index][0],\
maxIter_=trainingIt, optMethod_=arg_list[index][1])
e.run()
# Different nodes number
if sys.argv[1].lower() == "nodes":
# Get arg list and estimate training iteration number
arg_list = createNodesVal()
fileName = "Machine-" + str(rank)
n_iteration = int(math.ceil(len(arg_list)/float(size)))
time = 0
for i in range(n_iteration):
index = i * size + rank
if index < len(arg_list):
time += float(simTime) / 20 * (1100 * arg_list[index][0] + 3000) / 3600
print(" == Running " + str(len(arg_list)) + " nodes experiments on " + str(size) + \
" processors: " + str(n_iteration) + " optimizations expected in approximately " + \
"{:.2f} hours == \n".format(time))
# Simulate multiple time if the number of cores does not correspond to number of points
for i in range(n_iteration):
index = i * size + rank
if index < len(arg_list):
train_it_index = (1100 * arg_list[index][0] + 3000)
print("-- " + machine + " (" + str(rank+1) + "/" + str(size) + ")" + \
" -- Experiment " + str(index+1) + " with number of nodes=" + \
str(arg_list[index][0]) + " and " + str(train_it_index) + " iterations")
e = Experiment(fileName_=fileName, folderName_="Nodes", noNodes_=arg_list[index][0], noisy_=True, \
mass_=float(20)/arg_list[index][0], simTime_=simTime, maxIter_=train_it_index, maxSpring_=1000)
e.run()
# Different couple of spring constant and mass
if sys.argv[1].lower() == "km":
# Get arg list and estimate iteration number and time
arg_list = createKMVal()
fileName = "Machine-" + str(rank)
n_iteration = int(math.ceil(len(arg_list)/float(size)))
print(" == Running " + str(len(arg_list)) + " KM experiments on " + str(size) + \
" processors: " + str(n_iteration) + " optimizations expected in approximately " + \
"{:.2f} hours == \n".format(float(simTime) / 20 * trainingIt * n_iteration / 3600))
# Simulate multiple time if the number of cores does not correspond to number of points
for i in range(n_iteration):
index = i * size + rank
if index < len(arg_list):
print("-- " + machine + " (" + str(rank+1) + "/" + str(size) + ")" + \
" -- Experiment " + str(index+1) + " with k=" + \
str(arg_list[index][0]) + " and m=" + str(arg_list[index][1]))
e = Experiment(fileName_=fileName, folderName_="KM", spring_=arg_list[index][0],\
simTime_=simTime, maxIter_=trainingIt, mass_=arg_list[index][1])
e.run()
# Different reference for energy and distance scores
if sys.argv[1].lower() == "ref":
# Get arg list and estimate iteration number and time
arg_list = createRefVal()
fileName = "Machine-" + str(rank)
n_iteration = int(math.ceil(len(arg_list)/float(size)))
print(" == Running " + str(len(arg_list)) + " experiments on " + str(size) + \
" processors: " + str(n_iteration) + " optimizations expected in approximately " + \
"{:.2f} hours == \n".format(float(simTime) / 20 * trainingIt * n_iteration / 3600))
# Simulate multiple time if the number of cores does not correspond to number of points
for i in range(n_iteration):
index = i * size + rank
if index < len(arg_list):
print("-- " + machine + " (" + str(rank+1) + "/" + str(size) + ")" + \
" -- Experiment " + str(index+1) + " with Pref=" + \
str(arg_list[index][0]) + " and Dref=" + str(arg_list[index][1]))
e = Experiment(fileName_=fileName, folderName_="Reference", refPower_=arg_list[index][0],\
simTime_=simTime, maxIter_=trainingIt, refDist_=arg_list[index][1])
e.run()
# Different reference for energy and distance scores
if sys.argv[1].lower() == "paretop":
# Get arg list and estimate iteration number and time
arg_list = createRefPowerParetoVal()
fileName = "Machine-" + str(rank)
n_iteration = int(math.ceil(len(arg_list)/float(size)))
print(" == Running " + str(len(arg_list)) + " Power pareto experiments on " + str(size) + \
" processors: " + str(n_iteration) + " optimizations expected in approximately " + \
"{:.2f} hours == \n".format(float(simTime) / 20 * trainingIt * n_iteration / 3600))
# Simulate multiple time if the number of cores does not correspond to number of points
for i in range(n_iteration):
index = i * size + rank
if index < len(arg_list):
print("-- " + machine + " (" + str(rank+1) + "/" + str(size) + ")" + \
" -- Experiment " + str(index+1) + " with Pref=" + str(arg_list[index][0]) + \
" and Omega=" + str(arg_list[index][1]))
e = Experiment(fileName_=fileName, folderName_="Pareto_power", refPower_=arg_list[index][0],\
omega_=arg_list[index][1], simTime_=simTime, maxIter_=trainingIt, perfMetr_="powersat",
trainOmega_=False, noisy_=True)
e.run()
# Different reference for energy and distance scores
if sys.argv[1].lower() == "paretod":
# Get arg list and estimate iteration number and time
arg_list = createRefDistParetoVal()
fileName = "Machine-" + str(rank)
n_iteration = int(math.ceil(len(arg_list)/float(size)))
print(" == Running " + str(len(arg_list)) + " Distance pareto experiments on " + str(size) + \
" processors: " + str(n_iteration) + " optimizations expected in approximately " + \
"{:.2f} hours == \n".format(float(simTime) / 20 * trainingIt * n_iteration / 3600))
# Simulate multiple time if the number of cores does not correspond to number of points
for i in range(n_iteration):
index = i * size + rank
if index < len(arg_list):
print("-- " + machine + " (" + str(rank+1) + "/" + str(size) + ")" + \
" -- Experiment " + str(index+1) + " with Dref=" + str(arg_list[index][0]) + \
" and Omega=" + str(arg_list[index][1]))
e = Experiment(fileName_=fileName, folderName_="Pareto_dist", refDist_=arg_list[index][0],\
omega_=arg_list[index][1], simTime_=simTime, maxIter_=trainingIt, perfMetr_="distsat", \
trainOmega_=False, noisy_=True)
e.run()
# Different reference for energy and distance scores
if sys.argv[1].lower() == "omega":
# Get arg list and estimate iteration number and time
arg_list = createOmegaVal()
fileName = "Machine-" + str(rank)
n_iteration = int(math.ceil(len(arg_list)/float(size)))
print(" == Running " + str(len(arg_list)) + " omega experiments on " + str(size) + \
" processors: " + str(n_iteration) + " optimizations expected in approximately " + \
"{:.2f} hours == \n".format(float(simTime) / 20 * trainingIt * n_iteration / 3600))
# Simulate multiple time if the number of cores does not correspond to number of points
for i in range(n_iteration):
index = i * size + rank
if index < len(arg_list):
if arg_list[index][1]==3:
trainingIt = 6000
elif arg_list[index][1]==5:
trainingIt = 8000
elif arg_list[index][1]==7:
trainingIt = 10000
print("-- " + machine + " (" + str(rank+1) + "/" + str(size) + ")" + \
" -- Experiment " + str(index+1) + " with omega=" + str(arg_list[index][0]) + \
" and n_nodes=" + str(arg_list[index][1]))
e = Experiment(fileName_=fileName, folderName_="Omega", omega_=arg_list[index][0],\
simTime_=simTime, maxIter_=trainingIt, perfMetr_="powereff", noNodes_=arg_list[index][1], \
mass_=float(20)/arg_list[index][1], maxSpring_=1000, noisy_=True, trainOmega_=False)
e.run()
# Noisy otpimization with the same argument list
if sys.argv[1].lower() == "noisy":
print(" == Running " + str(size) + " experiments on " + str(size) + \
" processors: 1 optimization expected in approximately " + \
"{:.2f} hours == \n".format(float(simTime) / 20 * trainingIt / 3600))
fileName = "Machine-" + str(rank)
e = Experiment(fileName_=fileName, folderName_="CMA", simTime_=simTime, maxIter_=trainingIt, optMethod_="CMA", \
noisy_=True, refDist_=simTime*10, trainDamp_=True)
e.run()
else:
# Pool of CMA otpimization with the same argument list
print(" == Running " + str(size) + " experiments on " + str(size) + \
" processors: 1 optimization expected in approximately " + \
"{:.2f} hours == \n".format(float(simTime) / 20 * trainingIt / 3600))
fileName = "Machine-" + str(rank)
e = Experiment(fileName_=fileName, folderName_="CMA", simTime_=simTime, maxIter_=trainingIt, optMethod_="CMA")
e.run()