Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/ein16/synth/d2/run.py
ViewVC logotype

Annotation of /branches/ein16/synth/d2/run.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3946 - (view) (download) (as text)

1 : cchiw 3865 import sys
2 :     import re
3 :     import os
4 :     from test_createField import createField
5 :     from test_writeDiderot import writeDiderot
6 : cchiw 3915 from test_eval import eval
7 : cchiw 3865 from test_compare import compare
8 :     from test_observed import observed
9 : cchiw 3939 from obj_apply import *
10 :     from obj_ex import *
11 :     from obj_field import *
12 :     from set import *
13 :    
14 : cchiw 3915 # unu grid -i inputfile.nrrd | unu save -f text
15 :     # ^ where all the points are.
16 : cchiw 3865
17 : cchiw 3939 opr_max = 11
18 :     todo = sys.argv[1]
19 : cchiw 3940 vispath = "/Users/chariseechiw/diderot/vis15/bin/diderotc --exec "
20 :     einpath = "/Users/chariseechiw/diderot/ein16/bin/diderotc "
21 :     runtimepath = ""
22 : cchiw 3946 isVis15 = false
23 : cchiw 3940 if isVis15:
24 :     runtimepath = vispath
25 :     else:
26 :     runtimepath = einpath
27 : cchiw 3915
28 : cchiw 3940
29 : cchiw 3939 def clean():
30 :     # Clean up
31 :     os.system("rm *.o")
32 :     os.system("rm *.pyc")
33 :     os.system("rm *.h")
34 :     os.system("rm *.nrrd")
35 : cchiw 3874
36 : cchiw 3946 def write(e):
37 :     print (e)
38 :     # if it works continue
39 :     # f = open("results_tmp.txt", 'a+')
40 :     #f.write(e)
41 :     #f.close()
42 :     def write2(e):
43 :     print (e)
44 :     # if it works continue
45 :     f = open("results_Final.txt", 'a+')
46 :     f.write(e)
47 :     f.close()
48 :     def pnt1(pre, cnt, total,rst_good, rst_eh, rst_terrible, rst_compile):
49 :     x= "\n"+pre+" good:"+str(rst_good)+" eh:"+str( rst_eh)+" terrible:"+str(rst_terrible)+" didn't compile:"+str(rst_compile)
50 :     print (x)
51 :     write2(x)
52 :     def pnt2(pre, cnt, total,rst_good, rst_eh, rst_terrible, rst_compile):
53 :     x= "\n"+pre+" good:"+str(rst_good)+" eh:"+str( rst_eh)+" terrible:"+str(rst_terrible)+" didn't compile:"+str(rst_compile)
54 :     x+= " Number of tests ran: "+str(cnt)+" Total iterations attempted: " +str(total)
55 :     print (x)
56 :     write2(x)
57 :     def pnt3(pre, cnt, total,rst_good, rst_eh, rst_terrible, rst_compile):
58 :     x= "\n"+pre+" good:"+str(rst_good)+" eh:"+str( rst_eh)+" terrible:"+str(rst_terrible)+" didn't compile:"+str(rst_compile)
59 :     x+= " Number of tests ran: "+str(cnt)+" Total iterations attempted:" +str(total)
60 :     print (x)
61 :     write2(x)
62 :    
63 :     #get all the names
64 :     def get_names():
65 :     for ex_opr in range(opr_max+1):
66 :     ex = get_ex(ex_opr)
67 :     n = len(ex.tys)
68 :     print ("cmd:(1 "+str(ex_opr)+") opr "+example.get_oprname(ex))
69 :     for ex_num in range(n):
70 :     print ("\tcmd:(-1 "+str(ex_opr)+","+str(ex_num)+")"+example.toStr(ex,ex_num))
71 :    
72 : cchiw 3939 # already created app object
73 :     def central(app, coeffs, dimF):
74 : cchiw 3946 print "inside central"
75 :     os.system("rm data/*.txt")
76 : cchiw 3939 print app.name
77 :     # testing positions
78 :     positions = get_positions(dimF)
79 : cchiw 3946 #print "positions",positions
80 : cchiw 3939 # samples
81 :     outSize = get_size(dimF)
82 :     #create synthetic field data with diderot
83 :     createField(app, outSize, coeffs)
84 :     #create diderot program with operator
85 : cchiw 3940 writeDiderot(p_Observ, app, positions, output, runtimepath, isVis15)
86 :     if(isVis15):
87 :     return "compiled"
88 :     else:
89 :     #read observed data
90 :     observed_data = observed(app, output)
91 : cchiw 3946 #print "observed data from python",observed_data
92 :     if (len(observed_data)<2):
93 :     return ("diderot could not handle program",0,0,0,1)
94 : cchiw 3940 #correct values from python
95 :     correct_data = eval(app , positions)
96 : cchiw 3946 #print "correct data from python", correct_data
97 : cchiw 3940 #--------------------Comparison
98 :     #compare observed and correct data
99 :     rtn = compare(app, observed_data, correct_data)
100 : cchiw 3946 (rtn_1, rst_good, rst_eh, rst_terrible, rst_compile) = rtn
101 :     if (rst_terrible==1):
102 :     print "terrible-data"
103 :     print "observed data from python",observed_data
104 :     print "correct data from python", correct_data
105 : cchiw 3940 clean()
106 :     return rtn
107 : cchiw 3874
108 : cchiw 3939 # get example from list of examples
109 :     def single1_specific_ex(ex_opr, ex_num):
110 : cchiw 3946 #print "single specific ex"
111 : cchiw 3939 (name,opr,ishape)= get_single_example(int(ex_opr), int(ex_num))
112 : cchiw 3946 #print name
113 : cchiw 3939 #create app object
114 :     (app, coeffs, dimF,_) = mkApply_fld(name, opr, ishape, inputfile)
115 :     # main
116 : cchiw 3946 (rtn,_,_,_,_) = central(app, coeffs, dimF)
117 :     return rtn
118 : cchiw 3874
119 : cchiw 3939 #run all examples for a specific operator
120 :     def single1_all_ops(ex_opr):
121 : cchiw 3946 #print "single all ops"
122 : cchiw 3939 ex = get_ex(ex_opr)
123 :     #print(example.get_oprname(ex))
124 :     n = len(ex.tys)
125 :     rtn = [str(ex_opr)+": length "+str(n)]
126 :     for ex_num in range(n):
127 :     #print (example.toStr(ex,ex_num))
128 :     x = example.toStr(ex,ex_num)+" "+str(ex_opr)+"-"+str(ex_num)+":"
129 : cchiw 3946 #print x
130 : cchiw 3939 y = single1_specific_ex(ex_opr, ex_num)
131 :     rtn.append(x+y)
132 :     return rtn
133 :    
134 :     #run all possible examples
135 :     def depth1_all_exs():
136 :     rtn = []
137 :     for ex_opr in range(opr_max+1):
138 :     rtn.append(single1_all_ops(ex_opr))
139 :     for i in rtn:
140 :     for j in i:
141 :     print j
142 :    
143 : cchiw 3946 ##################################################################################################
144 :     # get result after applying operators
145 : cchiw 3939 def get_tshape(opr_inner,ishape):
146 :     arity=opr_inner.arity
147 : cchiw 3946 #print "checking for first time in rum.py"
148 :     #print ("checking second layers", opr_inner.name,"ishape",ishape[0].name)
149 : cchiw 3939 if(arity==1):
150 :     return applyUnaryOp(opr_inner,ishape)
151 :     elif(arity==2):
152 : cchiw 3946 #print ("-", ishape[1].name)
153 : cchiw 3939 return applyBinaryOp(opr_inner,ishape)
154 :    
155 :     # checks to see if specific ex works
156 : cchiw 3946 def embed2_specific_ex(ex_opr, ex_num, opr_outer, fty):
157 : cchiw 3939 # current example
158 :     (name,opr_inner,ishape)= get_single_example(ex_opr, ex_num)
159 : cchiw 3946 #print ("name:", name, "outer",opr_outer.name)
160 :     # first layer
161 :     (_, tshape) = get_tshape(opr_inner,ishape)
162 :     #second layer, adds second field type
163 :     ishape = ishape+fty
164 :     (tf, _) = get_tshape(opr_outer,[tshape]+fty)
165 :     #print ("checking second layers", opr_outer.name,"ishape",ishape[0].name,ishape[1].name)
166 : cchiw 3939 if(tf==true):# if it works continue
167 :     write("\n\t\tpassed ")
168 : cchiw 3946 #create app object
169 :     name = opr_outer.name+"("+opr_inner.name+")"
170 :     #print "before mkapply twice"
171 :     (app, coeffs, dimF) = mkApply_twice(name, opr_inner,opr_outer, ishape, inputfile)
172 :     #print "\nafter mk apply twice:\n",apply.toStr(app,0 )
173 :     # main part
174 :     (rtn, rst_good, rst_eh, rst_terrible, rst_compile) = central(app, coeffs, dimF)
175 :     return (1, rtn, rst_good, rst_eh, rst_terrible, rst_compile)
176 : cchiw 3939 else:
177 : cchiw 3946 x = "\n\t\tskipped did not apply "+opr_outer.name+" to ("+tshape.name+","
178 : cchiw 3939 write(x)
179 : cchiw 3946 return (0, x, 0, 0, 0,0)
180 : cchiw 3939
181 :     #apply all possible unary operators to a specific inside example
182 : cchiw 3946 def embed2_outer(ex_opr, ex_num, opr_outer,ftyname, es):
183 :     #write("\n*******:"+name+" len("+str(n)+")******")
184 :     x = "-i_opr#("+idToStr(ex_opr)
185 :     x +=")type#("+str(ex_num)+","+ftyname
186 :     x+=")\no_opr#("+opr_outer.name
187 :     x+=" between that and "+ftyname
188 :     write("\n"+x)
189 :     return embed2_specific_ex(ex_opr, ex_num, opr_outer, es)
190 :    
191 :     def embed2_apply_outer(ex_opr, ex_num, ex_outer, gty):
192 :     if(gty==-1):
193 :     #apply all possible unary operators to a specific inside example
194 :     opr_outer = op_unary[ex_outer]
195 :     return embed2_outer(ex_opr, ex_num, opr_outer, "_",[])
196 :     else:
197 :     #apply all possible binary operators to a specific inside example
198 :     fty =l_all_F[gty]
199 :     opr_outer= op_binary[ex_outer]
200 :     return embed2_outer(ex_opr, ex_num, opr_outer, fty.name, [fty])
201 :    
202 :     #apply all possible unary operators to a specific inside example
203 :     def embed2_iter_outer(ex_opr, ex_num, gty):
204 :     def getN():
205 :     if(gty==-1):
206 :     return len(op_unary)
207 :     else:
208 :     return len(op_binary)
209 :     n = getN()
210 : cchiw 3939 rtn = []
211 : cchiw 3946 cnt = 0
212 :     total = n
213 :     rst_good = 0
214 :     rst_eh = 0
215 :     rst_terrible = 0
216 :     rst_compile = 0
217 :     for ex_outer in range(n):
218 :     (cnt1, rtn1, rst_good1, rst_eh1, rst_terrible1, rst_compile1) = embed2_apply_outer(ex_opr, ex_num, ex_outer, gty)
219 :     rtn.append(rtn1)
220 :     cnt+=int(cnt1)
221 :     rst_good +=rst_good1
222 :     rst_eh += rst_eh1
223 :     rst_terrible += rst_terrible1
224 :     rst_compile += rst_compile1
225 :     return (cnt, rtn, rst_good, rst_eh, rst_terrible, rst_compile, total)
226 : cchiw 3939
227 :     #run all examples for a specific operator
228 : cchiw 3946 def embed2_iter_tys(ex_opr, gty):
229 :     n = len(get_ex(ex_opr).tys)
230 : cchiw 3939 rtn = []
231 : cchiw 3946 cnt = 0
232 :     total = 0
233 :     rst_good = 0
234 :     rst_eh = 0
235 :     rst_terrible = 0
236 :     rst_compile = 0
237 : cchiw 3939 for ex_num in range(n):
238 : cchiw 3946 (cnt1, rtn1, rst_good1, rst_eh1, rst_terrible1, rst_compile1, total1) = embed2_iter_outer(ex_opr, ex_num, gty)
239 :     rtn.append(rtn1)
240 :     cnt+=int(cnt1)
241 :     total +=total1
242 :     rst_good +=rst_good1
243 :     rst_eh += rst_eh1
244 :     rst_terrible += rst_terrible1
245 :     rst_compile += rst_compile1
246 :     return (cnt, rtn, rst_good, rst_eh, rst_terrible, rst_compile, total)
247 : cchiw 3939
248 :     #run all possible examples
249 : cchiw 3946 def embed2_iter_inner(gty):
250 :     n = opr_max+1
251 : cchiw 3939 rtn = []
252 : cchiw 3946 cnt = 0
253 :     total = 0
254 :     rst_good = 0
255 :     rst_eh = 0
256 :     rst_terrible = 0
257 :     rst_compile = 0
258 :     for ex_opr in range(n):
259 :     (cnt1, rtn1, rst_good1, rst_eh1, rst_terrible1, rst_compile1, total1) = embed2_iter_tys(ex_opr, gty)
260 :     rtn.append(rtn1)
261 :     cnt+=int(cnt1)
262 :     total +=total1
263 :     rst_good +=rst_good1
264 :     rst_eh += rst_eh1
265 :     rst_terrible += rst_terrible1
266 :     rst_compile += rst_compile1
267 :     return (cnt, rtn, rst_good, rst_eh, rst_terrible, rst_compile, total)
268 : cchiw 3939
269 :    
270 :     n = int(todo) #command
271 :     if (n==0):
272 :     #write all the names
273 :     get_names()
274 :     elif (n==1):
275 :     #run all the programs
276 :     depth1_all_exs()
277 :     elif (n==-1):
278 :     #run all the programs
279 : cchiw 3946 gty = -1
280 :     (cnt, rtn, rst_good, rst_eh, rst_terrible, rst_compile, total) = embed2_iter_inner(gty)
281 :     pnt2("-1 cmd:", cnt, total, rst_good, rst_eh, rst_terrible, rst_compile)
282 : cchiw 3939 for i in rtn:
283 :     for j in i:
284 :     for k in j:
285 :     print k
286 :     elif (n==2):
287 :     #run specific operators
288 :     ex_opr = int(sys.argv[2])
289 :     rtn = single1_all_ops(ex_opr)
290 :     for i in rtn:
291 :     print i
292 :     os.system("open results_tmp.txt")
293 :     elif(n==-2):
294 :     ex_opr = int(sys.argv[2])
295 : cchiw 3946 gty = -1
296 :     (cnt, rtn, rst_good, rst_eh, rst_terrible, rst_compile, total) = embed2_iter_tys(ex_opr, gty)
297 :     pnt2("-2 cmd:", cnt, total, rst_good, rst_eh, rst_terrible, rst_compile)
298 : cchiw 3939 for i in rtn:
299 :     for j in i:
300 :     print j
301 :     elif (n==3):
302 :     # run one example
303 :     # with a specific operator
304 :     # number from generated list of types (not type id).
305 :     ex_opr = int(sys.argv[2])
306 :     ex_num = int(sys.argv[3])
307 :     rtn = single1_specific_ex(ex_opr, ex_num)
308 :     print rtn
309 :     elif (n==-3):
310 :     # run n examples
311 :     # with a specific operator,
312 :     # number from generated list of types (not type id.)
313 :     # and all possible outer operators
314 :     ex_opr = int(sys.argv[2])
315 :     ex_num = int(sys.argv[3])
316 : cchiw 3946 gty = -1
317 :     (cnt, rtn, rst_good, rst_eh, rst_terrible, rst_compile, total) = embed2_iter_outer(ex_opr, ex_num, gty)
318 : cchiw 3939 for i in rtn:
319 :     print i
320 :     elif (n==4): # run a specific single layer example with type and opr
321 :     raise "unsupported"
322 :     elif(n==-4):
323 :     # run a specific double layer example
324 :     ex_opr = int(sys.argv[2])
325 :     ex_num = int(sys.argv[3])
326 :     ex_outer= int(sys.argv[4])
327 : cchiw 3946 opr_outer= op_unary[ex_outer]
328 :     rtn = embed2_specific_ex(ex_opr, ex_num, opr_outer,[])
329 : cchiw 3939 print rtn
330 : cchiw 3946 elif (n==-5):
331 :     #ex_opr)+","+str(ex_outer2)+","+str(ex_ty2)+","+str( ex_num
332 :     # run n examples
333 :     # with a specific operator,
334 :     # number from generated list of types (not type id.)
335 :     # and all possible outer operators
336 :     ex_opr = int(sys.argv[2]) #inside operator
337 :     ex_outer = int(sys.argv[3])#outer binary operator
338 :     ex_num = int(sys.argv[5])#inside type on list
339 :     ex_ty2 = int(sys.argv[4]) #extra type
340 :     (cnt, rtn, rst_good1, rst_eh1, rst_terrible1, rst_compile1) = embed2_apply_outer(ex_opr, ex_num, ex_outer, ex_ty2)
341 :     print rtn
342 :     elif (n==-6):
343 :     # run n examples
344 :     # with a specific operator,
345 :     # number from generated list of types (not type id.)
346 :     # and all possible outer operators
347 :     ex_opr = int(sys.argv[2]) #inside operator
348 :     #ex_num = int(sys.argv[2])#inside type on list
349 :     ex_outer2 = int(sys.argv[3])#outer binary operator
350 :     if(ex_outer2>6):
351 :     raise "outer2 needs to be less than 6"
352 :     # ex_ty2 = int(sys.argv[4])
353 :     rtn=[]
354 :     #ex_opr=10
355 :     cnt = 0
356 :     total = 0
357 :     rst_good = 0
358 :     rst_eh = 0
359 :     rst_terrible = 0
360 :     rst_compile = 0
361 :     #for ex_opr in range(len(op_binary)):
362 :     ex = get_ex(ex_opr)
363 :     n = len(ex.tys)
364 :     m = len(l_all_F)
365 :     write2("\n\n starting: " +str(ex_opr)+" outer range: 6, allF: "+str(m)+ " n: "+str(n))
366 :     for ex_ty2 in range(m): #extra type
367 :     rst_good2 = 0
368 :     rst_eh2 = 0
369 :     rst_terrible2 = 0
370 :     rst_compile2 = 0
371 :     for ex_num in range(n):
372 :     print("current : "+str(ex_opr)+" "+str(ex_outer2)+" "+str(ex_ty2)+" "+str( ex_num))
373 :     #write2("\n"+str(ex_opr)+","+str(ex_outer2)+","+str(ex_ty2)+","+str( ex_num))
374 :     (cnt1, _, rst_good1, rst_eh1, rst_terrible1, rst_compile1) = embed2_apply_outer(ex_opr, ex_num, ex_outer2, ex_ty2)
375 :     # rtn.append(rtn1)
376 :     cnt+=int(cnt1)
377 :     total +=1
378 :     rst_good +=rst_good1
379 :     rst_eh += rst_eh1
380 :     rst_terrible += rst_terrible1
381 :     rst_compile += rst_compile1
382 :     rst_good2 +=rst_good1
383 :     rst_eh2 += rst_eh1
384 :     rst_terrible2 += rst_terrible1
385 :     rst_compile2 += rst_compile1
386 :     pnt1("onerun:"+str(ex_opr)+","+str(ex_outer2)+","+str(ex_ty2),cnt, total,rst_good2, rst_eh2, rst_terrible2, rst_compile2)
387 :     pnt3("Final for " +str(ex_opr)+":", cnt, total,rst_good, rst_eh, rst_terrible, rst_compile)
388 :     elif (n==-7):
389 :     # run n examples
390 :     # with a specific operator,
391 :     # number from generated list of types (not type id.)
392 :     # and all possible outer operators
393 :     ex_opr = int(sys.argv[2]) #inside operator
394 :     #ex_num = int(sys.argv[2])#inside type on list
395 :     # ex_outer2 = int(sys.argv[3])#outer binary operator
396 :     # ex_ty2 = int(sys.argv[4])
397 :     rtn=[]
398 :     #ex_opr=10
399 :     cnt = 0
400 :     total = 0
401 :     rst_good = 0
402 :     rst_eh = 0
403 :     rst_terrible = 0
404 :     rst_compile = 0
405 :     #for ex_opr in range(len(op_binary)):
406 :     ex = get_ex(ex_opr)
407 :     n = len(ex.tys)
408 :     m = len(l_all_F)
409 :     write2("\n\n starting: " +str(ex_opr)+" outer range: 6, allF: "+str(m)+ " n: "+str(n))
410 :     for ex_outer2 in range(6):
411 :     #write2("outer op"+str(ex_outer2)+"-"+idToStr(ex_outer2+6))
412 :     for ex_ty2 in range(m): #extra type
413 :     rst_good2 = 0
414 :     rst_eh2 = 0
415 :     rst_terrible2 = 0
416 :     rst_compile2 = 0
417 :     for ex_num in range(n):
418 :     print("current : "+str(ex_opr)+" "+str(ex_outer2)+" "+str(ex_ty2)+" "+str( ex_num))
419 :     #write2("\n"+str(ex_opr)+","+str(ex_outer2)+","+str(ex_ty2)+","+str( ex_num))
420 :     (cnt1, _, rst_good1, rst_eh1, rst_terrible1, rst_compile1) = embed2_apply_outer(ex_opr, ex_num, ex_outer2, ex_ty2)
421 :     # rtn.append(rtn1)
422 :     cnt+=int(cnt1)
423 :     total +=1
424 :     rst_good +=rst_good1
425 :     rst_eh += rst_eh1
426 :     rst_terrible += rst_terrible1
427 :     rst_compile += rst_compile1
428 :     rst_good2 +=rst_good1
429 :     rst_eh2 += rst_eh1
430 :     rst_terrible2 += rst_terrible1
431 :     rst_compile2 += rst_compile1
432 :     pnt1("onerun:"+str(ex_opr)+","+str(ex_outer2)+","+str(ex_ty2),cnt, total,rst_good2, rst_eh2, rst_terrible2, rst_compile2)
433 :     pnt2("cumulative:"+str(ex_opr)+","+sstr(ex_outer2),cnt, total,rst_good, rst_eh, rst_terrible, rst_compile)
434 :     pnt3("Final for " +str(ex_opr)+":", cnt, total,rst_good, rst_eh, rst_terrible, rst_compile)
435 : cchiw 3939 else:
436 :     raise "unsupported"

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0