-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
359 lines (322 loc) · 11.7 KB
/
setup.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
#Homemade lib
import setup as s
#PYTHON lib
import time
import os
import json
# from subprocess import call
import subprocess
####################################################################
#
# CONSTANTS
#
####################################################################
#=========================================
# OS Name
# Values LINUX
# WINDOWS
#=========================================
OS_NAME = "LINUX"
#=========================================
# folders
#=========================================
FOLDER_RESULTS = "results"
FOLDER_ANALYSIS = "analysis"
FOLDER_ZIPPEDLOG = "gz"
FOLDER_PWA = "logpwa"
#=========================================
# PWA file catalog
#=========================================
URL_CATALOG_PWA = "https://www.cs.huji.ac.il/labs/parallel/workload/logs-list"
#=========================================
# to be exported with the result
#=========================================
EXP_INSTANCES = True
EXP_PARAMETERS = True
#=========================================
# generate integers rather than reals.
# arround with round method
# Used in MATRIX module __init__ method
# if True, generate a list of integers
#=========================================
INT_UNIFORM = True
INT_NON_UNIFORM = True
# not relevant and therefore not managed.
# INT_LAMBDA = False
# INT_BETA = False
# INT_EXPONENTIAL = False
# INT_PWA = False
####################################################################
#
# TOOLS
#
# sepDir / or \ ?
# folder folder f exists ? create it if not.
#
####################################################################
def sepDir():
"""
Directory separator
return "/" if OS_NAME = "LINUX
return "\" else
"""
linuxPrefix = "/"
winPrefix = "\\"
sep = linuxPrefix
if OS_NAME != "LINUX":
sep = winPrefix
# END IF
return sep
def folder(f):
"""
Verify if folder f exists.
if not create it
return the folder prefixed with the relative path. eg ./f (for linux) or .\f (for windows)
"""
# INIT
currentPath = os.getcwd()
# resFolder = "." + sepDir() + f
resFolder = currentPath + sepDir() + f
# Create folder if not exists
if not os.path.exists(resFolder):
os.makedirs(resFolder)
# END IF
return resFolder
def folderResult(name, user, date):
folder(FOLDER_RESULTS)
r = folder(FOLDER_RESULTS+ sepDir() + name+"_"+user+"_"+date)
return r
def folderResultMatrix(name, user, date):
folderReultCampaign = FOLDER_RESULTS+ sepDir() + name+"_"+user+"_"+date
folder(FOLDER_RESULTS)
folder(folderReultCampaign)
r = folder(folderReultCampaign + sepDir()+"instanceFiles")
return r
def campaignFileResultName(name=None, user=None, date=None):
# return name+"_"+user+"_"+date
return "result"
def campaignFileParametersName(name, user, date, ext = ".json"):
return "parameters_" + name + "_" + user + "_" + date + ext
####################################################################
#
# running an R script
#
####################################################################
def analysisExecute(rFileName, workDir):
currentDir = os.getcwd()
output = None
if OS_NAME == "LINUX":
command_lin = ["Rscript", rFileName] # "--vanilla",
print("####################")
print("run >>"+rFileName)
try:
os.chdir(workDir) # required to find the files (pdf) created by the R scripts
output = subprocess.call(command_lin, shell=False) # shell=False otherwise, do not execute the
print("OK", output)
except subprocess.CalledProcessError as e:
chemin = os.getcwd()
output = e.output
print("ERREUR", chemin, e)
# END TRY
else:
# !!!! not tested !!!!
os.chdir(workDir) # required to find the files (pdf) created by the R scripts
command_notLin = "cmd /k Rscript --vanilla < "+rFileName
os.system(command_notLin)
# END IF
# retrieve current directory
os.chdir(currentDir)
####################################################################
# CLASS ParamFile
# JSON Parameters files Management
#
####################################################################
class ParamFile:
# ==================================================================
# CONSTRUCTOR
# ==================================================================
def __init__(self):
# JSON PARAMETERS FILE
self.campaignDate = time.strftime("%d%m%Y")
# JSON content
self.fileObj = {}
# ==================================================================
# CREATE
# initialize values and JSON? content
# save file
# ==================================================================
def create(self,
campaignName, campaignUser,
seedForce,
N_NumberBegin,N_NumberEnd,N_List, M_NumberBegin,M_NumberEnd, M_List,
matUniformNumber,matNonUniformNumber,matGammaNumber,matBetaNumber,matExponentialNumber,
matRealFiles,
A, B,
Alpha,Beta,Lmbda,
useLPT,useSLACK,useLDM,useCOMBINE,useMULTIFIT):
# JSON PARAMETERS FILE
self.campaignName = campaignName
self.campaignUser = campaignUser
# complete file name
resDir = folderResult(self.campaignName, self.campaignUser, self.campaignDate)
self.completeFileName = resDir + s.sepDir() + campaignFileParametersName(campaignName, campaignUser, self.campaignDate)
# self.fileObj : json content
#
self.fileObj['campaign']=[]
self.fileObj['campaign'].append({
'campaignName' : self.campaignName,
'campaignUser' : self.campaignUser,
'campaignDate' : self.campaignDate})
#
self.fileObj['size']=[]
self.fileObj['size'].append({
'N_NumberBegin' : N_NumberBegin,
'N_NumberEnd' : N_NumberEnd,
'M_NumberBegin' : M_NumberBegin,
'M_NumberEnd' : M_NumberEnd,
'N_List' : N_List,
'M_List' : M_List})
#
self.fileObj['generation_methods']=[]
self.fileObj['generation_methods'].append({
'seedForce' : seedForce,
'matUniformNumber' :matUniformNumber,
'matNonUniformNumber' :matNonUniformNumber,
'matGammaNumber' : matGammaNumber ,
'matBetaNumber' : matBetaNumber,
'matExponentialNumber' : matExponentialNumber})
#
self.fileObj['generation_PWA']=[]
self.fileObj['generation_PWA'].append({
'matRealFiles' : matRealFiles})
#
self.fileObj['generation_properties']=[]
self.fileObj['generation_properties'].append({
'A' : A,
'B' : B,
'Alpha' : Alpha,
'Beta' : Beta,
'Lambda' : Lmbda})
#
self.fileObj['algorithms'] = []
self.fileObj['algorithms'].append({
'useLPT' : useLPT,
'useSLACK' : useSLACK,
'useLDM' : useLDM,
'useCOMBINE' : useCOMBINE,
'useMULTIFIT' : useMULTIFIT,})
# Save file
self.save()
# ==================================================================
# READ File
# open file
# read values
# return tuple
# ==================================================================
def read(self,completeFileName):
self.completeFileName = completeFileName
with open(self.completeFileName) as jsonFile:
dd = json.load(jsonFile)
newDict = {}
# read the json dict
for val in dd.values():
for i in range(len(val)):
for param,value in val[i].items():
newDict[param]= value
# END FOR
# END FOR
# END FOR
return newDict
# ==================================================================
# SAVE
# ==================================================================
def save(self):
with open(self.completeFileName,'w') as fileJSON:
json.dump(self.fileObj, fileJSON)
####################################################################
#
# JSON INSTANCE files Management
#
####################################################################
class InstanceFile:
# ==================================================================
# CONSTRUCTOR
# ==================================================================
def __init__(self):
# JSON PARAMETERS FILE
# JSON content
self.fileObj = {}
# ==================================================================
# CREATE
# initialize values and JSON? content
# save file
# ==================================================================
def create(self, campaignName, campaignUser, campaignDate,
generateMethode, seed, realFilesName, a, b, alpha,beta,lmbda, m, n, sType,
matTimes,
lowBound, matStatIndicators, optimal = None):
# complete file name
resDir = folderResultMatrix(campaignName, campaignUser, campaignDate)
print(resDir)
self.completeFileName = resDir + s.sepDir() + "instance_"+sType+"_"+generateMethode+"_"+str(seed)+"_"+str(n)+"_"+str(m)+".json"
print(self.completeFileName)
# self.fileObj : json content
#
self.fileObj['campaign']=[]
self.fileObj['campaign'].append({
'campaignName' : campaignName,
'campaignUser' : campaignUser,
'campaignDate' : campaignDate})
#
self.fileObj['generation_method']=[]
self.fileObj['generation_method'].append({
'generateMethode':generateMethode,
'n' : n,
'm' : m,
'type' : sType,
'seed' : seed,
'reelFileName' : realFilesName,
'a' : a,
'b' : b,
'alpha' : alpha,
'beta' : beta,
'lambda' : lmbda})
#
self.fileObj['features']=[]
self.fileObj['features'].append({
'lowBound' : lowBound,
'optimal' : optimal,
'indicators' : matStatIndicators})
#
self.fileObj['matrix']=[]
self.fileObj['matrix'].append({
'timeList' : matTimes})
# Save file
self.save()
# ==================================================================
# SAVE
# ==================================================================
def save(self):
with open(self.completeFileName,'w') as fileJSON:
json.dump(self.fileObj, fileJSON)
# ==================================================================
# READ File
# open file
# read values
# return tuple
# ==================================================================
def read(self,completeFileName):
self.completeFileName = completeFileName
with open(self.completeFileName) as jsonFile:
dd = json.load(jsonFile)
newDict = {}
# read the json dict
for val in dd.values():
for i in range(len(val)):
for param,value in val[i].items():
newDict[param]= value
# END FOR
# END FOR
# END FOR
print(newDict)
return newDict