-
Notifications
You must be signed in to change notification settings - Fork 85
/
2021_emse.py
713 lines (569 loc) · 27 KB
/
2021_emse.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
#!/usr/bin/python
import argparse
import io
import os
import pathlib
import shutil
import stat
import statistics
import math
############################################################################
### cluster settings
############################################################################
EXP_ID = "evomaster"
ACCOUNT = None
CPUS = 3
TIMEOUT_SUT_START_MINUTES = 20
CONTROLLER_PID = "CONTROLLER_PID"
MINUTES_PER_RUN = 200
############################################################################
### general settings
############################################################################
JDK_8 = "JDK_8"
JDK_11 = "JDK_11"
JS = "JS"
JAVA_HOME_8 = os.environ.get("JAVA_HOME_8", "")
JAVA_HOME_11 = os.environ.get("JAVA_HOME_11", "")
EVOMASTER_JAVA_OPTIONS = " -Xms2G -Xmx4G -jar evomaster.jar "
AGENT = "evomaster-agent.jar"
EM_POSTFIX = "-evomaster-runner.jar"
SUT_POSTFIX = "-sut.jar"
############################################################################
### where to find evomaster, suts and results
############################################################################
DEFAULT_FOLDER = "ahw-evomaster-exp"
EVOMASTER_DIR = os.environ.get("EVOMASTER_DIR", "")
EMB_DIR = os.environ.get('EMB_DIR', "")
BASE_DIR = os.path.abspath(DEFAULT_FOLDER)
REPORT_DIR = BASE_DIR + "/reports"
SCRIPT_DIR = BASE_DIR + "/scripts"
TEST_DIR = BASE_DIR + "/tests"
LOGS_DIR = BASE_DIR + "/logs"
ROOT_SCRIPT = BASE_DIR + "/runall.sh"
############################################################################
### sut settings and configuration
############################################################################
class Sut:
def __init__(self, name, timeWeight, db, platform):
self.name = name
# the higher value, the more time it will need compared to the other SUTS
self.timeWeight = timeWeight
# include database
self.db = db
# Java? JS? NodeJS
self.platform = platform
SUTS = [
Sut("features-service", 1, True, JDK_8),
Sut("scout-api", 2, True, JDK_8),
Sut("proxyprint", 2, True, JDK_8),
Sut("rest-ncs", 2, False, JDK_8),
Sut("rest-scs", 1, False, JDK_8),
Sut("rest-news", 1, True, JDK_8),
Sut("catwatch", 1, True, JDK_8)
]
SELECTED_SUT = SUTS
############################################################################
### prehandling
############################################################################
def setSut(args):
if args.sut is not None:
global SELECTED_SUT
if args.sut.lower() == "all":
SELECTED_SUT = SUTS
elif args.sut.lower() == "sql":
SELECTED_SUT = list(filter(lambda x: x.db, SUTS))
elif args.sut.lower() == "nsql":
SELECTED_SUT = list(filter(lambda x: not x.db, SUTS))
else:
SELECTED_SUT = list(filter(lambda x: x.name.lower() == args.sut.lower(), SUTS))
if not len(SELECTED_SUT):
print("ERROR: " + args.sut + " is an improper setting for selecting SUT(s)")
exit(1)
def checkAndPrehandling(args):
setSut(args)
global ROOT_SCRIPT
global REPORT_DIR
global SCRIPT_DIR
global TEST_DIR
global LOGS_DIR
global MINUTES_PER_RUN
global BASE_DIR
global EVOMASTER_DIR
global EMB_DIR
if args.maxMinutesPerRun is not None:
MINUTES_PER_RUN = args.maxMinutesPerRun
if args.minSeed > args.maxSeed:
print("ERROR: min seed is greater than max seed")
exit(1)
if args.dir is not None:
BASE_DIR = os.path.abspath(args.dir)
REPORT_DIR = BASE_DIR + "/reports"
SCRIPT_DIR = BASE_DIR + "/scripts"
TEST_DIR = BASE_DIR + "/tests"
LOGS_DIR = BASE_DIR + "/logs"
if not os.path.isdir(BASE_DIR):
print("creating folder: " + BASE_DIR)
os.makedirs(BASE_DIR)
else:
print("ERROR: target folder already exists")
exit(1)
if args.cluster:
HOME = os.environ['HOME']
EVOMASTER_DIR = HOME + "/tools"
if args.evomaster is not None:
EVOMASTER_DIR = HOME +"/"+ args.evomaster + "/tools"
EMB_DIR = HOME + "/dist"
if args.emb is not None:
EMB_DIR = HOME + "/" + args.emb + "/dist"
LOGS_DIR = os.environ['USERWORK'] + "/logs"
else:
if args.evomaster is not None:
EVOMASTER_DIR = os.path.abspath(args.evomaster)
if args.emb is not None:
EMB_DIR = os.path.abspath(args.emb)
if EVOMASTER_DIR == "":
raise Exception(
"You must specify a EVOMASTER_DIR env variable or a path specifying where evomaster.jar can be found")
if EMB_DIR == "":
raise Exception(
"You must specify a EMB_DIR env variable or a path specifying the '/dist' folder from where EMB repository was cloned")
if not os.path.exists(EMB_DIR):
raise Exception(EMB_DIR + " does not exist. Did you run script/dist.py?")
if JAVA_HOME_8 == "":
raise Exception("You must specify a JAVA_HOME_8 env variable specifying where JDK 8 is installed")
# diable jdk 11
# if JAVA_HOME_11 == "":
# raise Exception("You must specify a JAVA_HOME_11 env variable specifying where JDK 11 is installed")
# creating required dirs
os.makedirs(REPORT_DIR)
os.makedirs(SCRIPT_DIR)
os.makedirs(TEST_DIR)
os.makedirs(LOGS_DIR)
ROOT_SCRIPT = BASE_DIR + "/runall.sh"
# if not on the cluster, we need to copy jars to the exp dir
if not args.cluster:
REPORT_DIR = str(pathlib.PurePath(REPORT_DIR).as_posix())
SCRIPT_DIR = str(pathlib.PurePath(SCRIPT_DIR).as_posix())
TEST_DIR = str(pathlib.PurePath(TEST_DIR).as_posix())
LOGS_DIR = str(pathlib.PurePath(LOGS_DIR).as_posix())
# Due to Windows limitations (ie crappy FS), we need to copy JARs over
for sut in SELECTED_SUT:
if sut.platform == JDK_8 or sut.platform == JDK_11:
# copy jar files
shutil.copy(os.path.join(EMB_DIR, sut.name + EM_POSTFIX), BASE_DIR)
shutil.copy(os.path.join(EMB_DIR, sut.name + SUT_POSTFIX), BASE_DIR)
elif sut.platform == JS:
# copy folders, which include both SUT and EM Controller
shutil.copytree(os.path.join(EMB_DIR, sut.name), os.path.join(BASE_DIR, sut.name))
shutil.copy(os.path.join(EMB_DIR, AGENT), BASE_DIR)
shutil.copy(os.path.join(EVOMASTER_DIR, "evomaster.jar"), BASE_DIR)
setExp(args)
def createRunallScript(cluster):
script = open(ROOT_SCRIPT, "w")
script.write("#!/bin/bash \n\n")
script.write("cd \"$(dirname \"$0\")\"\n\n")
script.write("for s in `ls scripts/*.sh`; do\n")
script.write(" echo Going to start $s\n")
if cluster:
script.write(" sbatch $s\n")
else:
script.write(" $s & \n")
script.write("done \n")
st = os.stat(ROOT_SCRIPT)
os.chmod(ROOT_SCRIPT, st.st_mode | stat.S_IEXEC)
def writeScript(code, port, sut):
script_path = SCRIPT_DIR + "/evomaster_" + str(port) + "_" + sut.name + ".sh"
script = open(script_path, "w")
script.write(code)
st = os.stat(script_path)
os.chmod(script_path, st.st_mode | stat.S_IEXEC)
return script
def getScriptHead(timeoutMinutes, cluster):
s = "#!/bin/bash \n"
if cluster:
s += "#SBATCH --job-name=" + EXP_ID + " \n"
if ACCOUNT is None:
raise Exception("you require to specify a valid account info for running this experiment")
s += "#SBATCH --account= "+ACCOUNT+"\n"
s += "#SBATCH --mem-per-cpu=4G \n"
s += "#SBATCH --nodes=1 --ntasks-per-node=" + str(CPUS) + " \n"
s += "#SBATCH --time=" + str(timeoutMinutes) + ":00 \n\n"
return s
def createJobHead(port, sut, timeoutMinutes, cluster):
script = io.StringIO()
script.write(getScriptHead(timeoutMinutes, cluster))
sut_log = LOGS_DIR + "/log_sut_" + sut.name + "_" + str(port) + ".txt"
# Start SUT as background process on the given port
controllerPort = str(port)
sutPort = str(port + 1)
if cluster:
if sut.platform == JDK_8:
script.write("\nmodule load Java/1.8.0_212\n\n")
else:
print("ERROR: currently not handling " + sut.platform)
exit(1)
# To speed-up I/O, copy files over to SCRATCH folder
script.write("cd $SCRATCH \n")
script.write("cp " + EVOMASTER_DIR + "/evomaster.jar . \n")
# Not sure if great idea to copy 1000s of files for JS intro SCRATCH
if sut.platform == JDK_8 or sut.platform == JDK_11:
sut_em_path = os.path.join(EMB_DIR, sut.name + EM_POSTFIX)
sut_jar_path = os.path.join(EMB_DIR, sut.name + SUT_POSTFIX)
agent_path = os.path.join(EMB_DIR, AGENT)
script.write("cp " + sut_em_path + " . \n")
script.write("cp " + sut_jar_path + " . \n")
script.write("cp " + agent_path + " . \n")
script.write("\n")
script.write("\n")
timeoutStart = TIMEOUT_SUT_START_MINUTES * 60
command = ""
if sut.platform == JDK_8 or sut.platform == JDK_11:
params = " " + controllerPort + " " + sutPort + " " + sut.name + SUT_POSTFIX + " " + str(timeoutStart)
jvm = " -Xms1G -Xmx4G -Dem.muteSUT=true -Devomaster.instrumentation.jar.path="+AGENT
JAVA = getJavaCommand(sut, cluster)
command = JAVA + jvm + " -jar " + sut.name + EM_POSTFIX + " " + params + " > " + sut_log + " 2>&1 &"
elif sut.platform == JS:
# TODO plugin script for js experiment here
before = "pushd " + sut.name + "\n"
command = " EM_PORT=" + controllerPort + " npm run em > " + sut_log + " 2>&1 & "
command = before + command
if not cluster:
script.write("\n\necho \"Starting EM Runner with: " + command + "\"\n")
script.write("echo\n\n")
script.write(command + "\n\n")
# FIXME: this does not work for JS... as the process running NPM dies immediately after spawning Node
script.write(CONTROLLER_PID + "=$! \n\n") # store pid of process, so can kill it
if sut.platform == JS:
script.write("popd\n\n")
script.write("sleep 20 \n\n") # wait a bit to be sure the SUT handler can respond
return script.getvalue()
def closeJob(port, sut_name):
return "kill $" + CONTROLLER_PID + "\n"
####################################
class State:
def __init__(self, budget, njobs, port):
# total budget for the search which is left
self.budget = budget
# how many jobs/scripts we still need to create
self.jobsLeft = njobs
# to avoid TCP conflicts, each job uses a different port range
self.port = port
# number of generated script files, so far
generated = 0
# each job will have a different time duration, and we keep track
# of those durations for every single generated script
waits = []
# how many SUTs we still need to create jobs/scripts for.
# recall that in a script there can be only 1 SUT
sutsLeft = len(SUTS)
# how much budget we have used for the current opened job/script
counter = 0
# whether we are adding a new run in an existing script.
# if not, need to make sure to create all the right header / init methods
opened = False
# budget left for each remaining job/script
perJob = 0
def updatePerJob(self):
if self.jobsLeft == 0:
self.perJob = 0
else:
self.perJob = self.budget / self.jobsLeft
def updatePort(self):
self.port += 10
def updateBudget(self, weight):
# the used budget for current script increases...
self.counter += weight
# ... whereas the total left budget decreases by the same amount
self.budget -= weight
def getTimeoutMinutes(self):
# the timeout we want to wait for does depend not only on the number of runs, but
# also on the weights of the SUT (this is captured by self.counter).
# Note: we add a 10% just in case...
timeoutMinutes = TIMEOUT_SUT_START_MINUTES + int(math.ceil(1.1 * self.counter * MINUTES_PER_RUN))
self.waits.append(timeoutMinutes)
return timeoutMinutes
def resetTmpForNewRun(self):
self.counter = 0
self.opened = False
self.updatePerJob()
self.updatePort()
def hasSpareJobs(self):
return self.jobsLeft > self.sutsLeft
def writeWithHeadAndFooter(code, port, sut, timeout, cluster):
head = createJobHead(port, sut, timeout, cluster)
footer = closeJob(port, sut)
code = head + code + footer
writeScript(code, port, sut)
def createOneJob(state, sut, seed, setting, sol_name, budget, stopping_criterion, cluster):
code = addJobBody(state.port, sut, seed, setting, sol_name, budget, stopping_criterion, cluster)
state.updateBudget(sut.timeWeight)
state.jobsLeft -= 1
state.opened = True
state.generated += 1
return code
def getJavaCommand(sut, cluster):
JAVA = "java "
if not cluster:
if sut.platform == JDK_8:
JAVA = "\"" + JAVA_HOME_8 +"\"/bin/java "
elif sut.platform == JDK_11:
JAVA = "\"" + JAVA_HOME_11 +"\"/bin/java "
return JAVA
def addJobBody(port, sut, seed, setting, sol_name, budget, stopping_criterion, cluster):
script = io.StringIO()
em_log = LOGS_DIR + "/log_em_" + sut.name + "_" + str(port) + ".txt"
params = ""
label = sol_name
### Custom for these experiments
for ps in setting:
params += " --" + str(ps[0]) + "=" + str(ps[1])
if is_float(str(ps[1])) and float(ps[1]) <= 1.0:
label += "_" + str(int(float(ps[1]) * 100))
else:
label += "_" + str(ps[1])
params += " --testSuiteFileName=EM_" + label + "_" + str(seed) + "_Test"
params += " --dependencyFile=" + \
REPORT_DIR + "/dependencies_" + sut.name + "_" + label + "_" + str(seed) + ".csv"
### standard
params += " --stoppingCriterion="+stopping_criterion
if stopping_criterion == "TIME":
params += " --maxTime="+ str(budget)
elif stopping_criterion == "FITNESS_EVALUATIONS":
params += " --maxActionEvaluations=" + str(budget)
else:
raise Exception(""+stopping_criterion+ "is not supported by evomaster")
params += " --statisticsColumnId=" + sut.name
params += " --seed=" + str(seed)
params += " --sutControllerPort=" + str(port)
params += " --outputFolder=" + TEST_DIR + "/" + sut.name
params += " --statisticsFile=" + \
REPORT_DIR + "/statistics_" + sut.name + "_" + str(seed) + ".csv"
params += " --snapshotInterval=5"
params += " --snapshotStatisticsFile=" + \
REPORT_DIR + "/snapshot_" + sut.name + "_" + str(seed) + ".csv"
params += " --exceedTargetsFile=" + \
REPORT_DIR + "/exceedTarget" + sut.name + "_" + str(seed) + ".txt"
params += " --appendToStatisticsFile=true"
params += " --writeStatistics=true"
params += " --showProgress=false"
JAVA = getJavaCommand(sut, cluster)
command = JAVA + EVOMASTER_JAVA_OPTIONS + params + " >> " + em_log + " 2>&1"
if not cluster:
script.write("\n\necho \"Starting SUT with: " + command + "\"\n")
script.write("echo\n\n")
if cluster:
timeout = int(math.ceil(1.1 * sut.timeWeight * MINUTES_PER_RUN * 60))
errorMsg = "ERROR: timeout for " + sut.name
command = "timeout " + str(timeout) + " " + command \
+ " || ([ $? -eq 124 ] && echo " + errorMsg + " >> " + em_log + " 2>&1" + ")"
script.write(command + " \n\n")
return script.getvalue()
############################################################################
### experiment settings
############################################################################
class ParameterSetting:
def __init__(self, name, values):
self.name = name
self.values = values
self.count = len(self.values)
def pvalue(self, index):
if index >= len(self.values):
exit("a value at the index "+ str(index) + " does not exist")
return (self.name, self.values[index])
class Solution:
def __init__(self, name, settings):
self.name = name
self.settings = settings
self.numOfSettings = 1
for s in self.settings:
self.numOfSettings *= s.count
def genAllSettings(self):
all = []
lst = [0] * len(self.settings)
while lst is not None:
e = []
for i in range(len(lst)):
e.append(self.settings[i].pvalue(lst[i]))
all.append(e)
lst = self.plus1(lst)
return all
def plus1(self, lst):
if lst[0] < self.settings[0].count - 1:
lst[0] = lst[0] + 1
return lst
for i in range(len(lst)):
if lst[i] < self.settings[i].count-1:
lst[i] = lst[i] + 1
return lst
else:
lst[i] = 0
return None
def setting(self, index):
if index >= self.count:
exit("a setting at the index "+ str(index) + " does not exist")
return self.values[index]
class Experiment:
def __init__(self, name, solutions):
self.name = name
self.solutions = solutions
self.numOfSettings = 0
for s in self.solutions:
self.numOfSettings += s.numOfSettings
def numOfSolutions(self):
return len(self.solutions)
def solution(self, index):
if index >= len(self.solutions):
exit("a solution at the index "+ str(index) + " does not exist")
return self.solutions[index]
############################################################################
### resource-dependency experiment settings
############################################################################
#resourceSampleStrategy
NONE_RES_SMART_SAMPLE = ParameterSetting("resourceSampleStrategy", ["NONE"])
ALL_RES_SMART_SAMPLE = ParameterSetting("resourceSampleStrategy", ["EqualProbability","Actions","TimeBudgets","Archive","ConArchive"])
BEST_RES_SMART_SAMPLE = ParameterSetting("resourceSampleStrategy", ["ConArchive"])
#probOfSmartSampling
ZERO_SMART_SAMPLE_PROB = ParameterSetting("probOfSmartSampling", [0.0])
DEFAULT_SMART_SAMPLE_PROB = ParameterSetting("probOfSmartSampling", [0.5])
ALL_SMART_SAMPLE_PROB = ParameterSetting("probOfSmartSampling", [0.5, 1.0])
BEST_SMART_SAMPLE_PROB = ParameterSetting("probOfSmartSampling", [1.0])
#doesApplyNameMatching
F_WITH_MATCH = ParameterSetting("doesApplyNameMatching", [False])
T_WITH_MATCH = ParameterSetting("doesApplyNameMatching", [True])
#probOfEnablingResourceDependencyHeuristics
ZERO_PROB_DEP = ParameterSetting("probOfEnablingResourceDependencyHeuristics", [0.0])
ALL_RDMIO_PROB_DEP_BEST = ParameterSetting("probOfEnablingResourceDependencyHeuristics", [0.5, 1.0])
RDMIO_BEST_PROB_DEP_BEST = ParameterSetting("probOfEnablingResourceDependencyHeuristics", [1.0])
MIO_BASE1= Solution("MIO_BASE1", [NONE_RES_SMART_SAMPLE, ZERO_SMART_SAMPLE_PROB,F_WITH_MATCH,ZERO_PROB_DEP])
MIO_BASE2= Solution("MIO_BASE2", [NONE_RES_SMART_SAMPLE, NONE_RES_SMART_SAMPLE,F_WITH_MATCH,ZERO_PROB_DEP])
MIO_REST_RESOURCE= Solution("MIO_REST_RESOURCE", [ALL_RES_SMART_SAMPLE, ALL_SMART_SAMPLE_PROB,F_WITH_MATCH,ZERO_PROB_DEP])
MIO_REST_RESOURCE_DEP= Solution("MIO_REST_RESOURCE_DEP", [ALL_RES_SMART_SAMPLE, ALL_SMART_SAMPLE_PROB,F_WITH_MATCH,ZERO_PROB_DEP])
MIO_RESDEP = Experiment("MIO_RESDEP",[MIO_BASE1,MIO_BASE2,MIO_REST_RESOURCE,MIO_REST_RESOURCE_DEP])
############################################################################
### configure experiments
############################################################################
EXPS = [MIO_RESDEP]
SELECTED_EXP = EXPS[0]
SELECTED_SOLUTION= SELECTED_EXP.solutions
def setExp(args):
global SELECTED_EXP
global SELECTED_SOLUTION
if args.setting is not None:
SELECTED_EXP = list(filter(lambda x: x.name.lower() == args.setting.lower(), EXPS))[0]
if SELECTED_EXP is None:
raise Exception("" + args.setting + " cannot be found.")
SELECTED_SOLUTION = SELECTED_EXP.solutions
if args.solution is not None:
if args.solution.lower() == "all":
SELECTED_SOLUTION = SELECTED_EXP.solutions
else:
SELECTED_SOLUTION = list(filter(lambda x: x.name.lower() == args.solution.lower(), SELECTED_EXP.solutions))
if not len(SELECTED_SOLUTION):
raise Exception(""+args.solution+" cannot be found in the setting "+ SELECTED_EXP.name)
def createJobs(minSeed, maxSeed, njobs, portSeed, budget, stoppingCriterion, cluster):
num = 0
for s in SELECTED_SOLUTION:
num += s.numOfSettings
NRUNS_PER_SUT = (1 + maxSeed - minSeed) * num
SUT_WEIGHTS = sum(map(lambda x: x.timeWeight, SELECTED_SUT))
state = State(NRUNS_PER_SUT * SUT_WEIGHTS, njobs, portSeed)
SELECTED_SUT.sort(key=lambda x: -x.timeWeight)
for sut in SELECTED_SUT:
weight = sut.timeWeight
state.sutsLeft -= 1
state.resetTmpForNewRun()
code = ""
completedForSut = 0
for seed in range(minSeed, maxSeed + 1):
for solution in SELECTED_SOLUTION:
sol_name = solution.name
print("processing " + sol_name +" for "+sut.name)
for setting in solution.genAllSettings():
if state.counter == 0:
code = createOneJob(state, sut, seed, setting, sol_name, budget, stoppingCriterion, cluster)
elif (state.counter + weight) < state.perJob \
or not state.hasSpareJobs() or \
(NRUNS_PER_SUT - completedForSut < 0.3 * state.perJob / weight):
code += addJobBody(state.port, sut, seed, setting, sol_name, budget, stoppingCriterion, cluster)
state.updateBudget(weight)
else:
writeWithHeadAndFooter(code, state.port, sut, state.getTimeoutMinutes(), cluster)
state.resetTmpForNewRun()
code = createOneJob(state, sut, seed, setting, sol_name, budget, stoppingCriterion, cluster)
completedForSut += 1
if state.opened:
writeWithHeadAndFooter(code, state.port, sut, state.getTimeoutMinutes(), cluster)
print("Generated scripts: " + str(state.generated))
print("Max wait for a job: " + str(max(state.waits)) + " minutes")
print("Median wait for a job: " + str(statistics.median(state.waits)) + " minutes")
print("Budget left: " + str(state.budget))
print("Total time: " + str(sum(state.waits) / 60) + " hours")
print("Total budget: " + str(CPUS * sum(state.waits) / 60) + " hours")
def is_float(input):
try:
float(input)
except ValueError:
return False
return True
############################################################################
### Main
############################################################################
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--stoppingCriterion',
help='a criterion to terminate the search, i.e., TIME or FITNESS_EVALUATIONS. DEFAULT is TIME.',
type=str, required=False, default="TIME")
parser.add_argument('--budget',
help='a search budget. DEFAULT is 5 minutes (5m).',
type=str, required=False, default="5m")
parser.add_argument('--setting',
help='a predefined experiment setting.',
type=str, required=False, default="MIO_RESDEP")
parser.add_argument('--solution',
help='a specified solution (e.g., E1) for the employed experiment setting. DEFAULT is all.',
type=str, required=False, default=None)
parser.add_argument('--minSeed',
help="Experiments are repeated a certain number of times, with different seed for the random generator. This specify the starting seed. DEFAULT is 1.",
type=int, required=False, default=1)
parser.add_argument('--maxSeed',
help="Max seed, included. For example, if running min=10 and max=39, each experiment is going to be repeated 30 times, starting from seed 10 to seed 39 (both included). DEFAULT is 2.",
type=int, required=False, default=2)
# base seeds used for EM runs. TCP port bindings will be based on such seed.
# If running new experiments while some previous are still running, to avoid TCP port
# conflict, can use an higher base seed. Each EM run reserves 10 ports. So, if you run
# 500 jobs with starting seed 10000, you will end up using ports up to 15000
parser.add_argument('--portSeed',
help="port seed used for EM runs. TCP port bindings will be based on such seed. DEFAULT is 30000.",
type=int, required=False, default=30000)
parser.add_argument('--sut',
help="specifying including a sut in this experiment which can be all, sql, nsql or a name of the sut. DEFAULT is all.",
type=str, required=False, default="all")
parser.add_argument('--dir',
help="when creating a new set of experiments, all needed files will be saved in a folder. DEFAULT is all.",
type=str, required=False, default=DEFAULT_FOLDER)
parser.add_argument('--evomaster',
help="a folder where the evomaster.jar is",
type=str, required=False, default=None)
parser.add_argument('--emb',
help="a folder where jars of suts are",
type=str, required=False, default=None)
parser.add_argument('--cluster',
help="whether .sh are meant to run on cluster or locally. DEFAULT is False.",
type=bool, required=False, default=False)
# How many minutes we expect each EM run to last AT MOST.
# Warning: if this value is under-estimated, it will happen the cluster will kill jobs
# that are not finished withing the specified time.
parser.add_argument('--maxMinutesPerRun',
help="How many minutes we expect each EM run to last AT MOST",
type=int, required=False, default=None)
# How many scripts M we want the N jobs to be divided into.
# Note: on cluster we can at most submit 400 scripts.
# Also not that in the same .sh script there can be experiments only for a single SUT.
parser.add_argument('--njobs',
help="how many scripts M we want the N jobs to be divided into. If njobs is 1, there would be one script per sut. DEFAULT is 1.",
type=int, required=False, default="1")
args = parser.parse_args()
## global variable can only be changed with this method. This design might be modified later.
checkAndPrehandling(args)
createJobs(args.minSeed, args.maxSeed, args.njobs, args.portSeed, args.budget, args.stoppingCriterion, args.cluster)
createRunallScript(args.cluster)