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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3945, Thu Jun 9 20:00:15 2016 UTC revision 3946, Sat Jun 11 00:39:19 2016 UTC
# Line 19  Line 19 
19  vispath = "/Users/chariseechiw/diderot/vis15/bin/diderotc --exec "  vispath = "/Users/chariseechiw/diderot/vis15/bin/diderotc --exec "
20  einpath =  "/Users/chariseechiw/diderot/ein16/bin/diderotc "  einpath =  "/Users/chariseechiw/diderot/ein16/bin/diderotc "
21  runtimepath  =  ""  runtimepath  =  ""
22  isVis15 = true  isVis15 = false
23  if isVis15:  if isVis15:
24      runtimepath  = vispath      runtimepath  = vispath
25  else:  else:
# Line 33  Line 33 
33      os.system("rm *.h")      os.system("rm *.h")
34      os.system("rm *.nrrd")      os.system("rm *.nrrd")
35    
36    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  # already created app object  # already created app object
73  def central(app, coeffs, dimF):  def central(app, coeffs, dimF):
74        print "inside central"
75        os.system("rm data/*.txt")
76      print app.name      print app.name
77      # testing positions      # testing positions
78      positions = get_positions(dimF)      positions = get_positions(dimF)
79      print "positions",positions      #print "positions",positions
80      # samples      # samples
81      outSize = get_size(dimF)      outSize = get_size(dimF)
82      #create synthetic field data with diderot      #create synthetic field data with diderot
# Line 50  Line 88 
88      else:      else:
89          #read observed data          #read observed data
90          observed_data = observed(app, output)          observed_data = observed(app, output)
91          print "observed data from python",observed_data          #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          #correct values from python          #correct values from python
95          correct_data = eval(app , positions)          correct_data = eval(app , positions)
96          print "correct data from python", correct_data          #print "correct data from python", correct_data
97          #--------------------Comparison          #--------------------Comparison
98          #compare observed and correct data          #compare observed and correct data
99          rtn = compare(app, observed_data, correct_data)          rtn = compare(app, observed_data, correct_data)
100            (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          clean()          clean()
106          return rtn          return rtn
107    
   
108  # get example from list of examples  # get example from list of examples
109  def single1_specific_ex(ex_opr, ex_num):  def single1_specific_ex(ex_opr, ex_num):
110      print "single specific ex"      #print "single specific ex"
111      (name,opr,ishape)= get_single_example(int(ex_opr), int(ex_num))      (name,opr,ishape)= get_single_example(int(ex_opr), int(ex_num))
112      print name      #print name
113      #create app object      #create app object
114      (app, coeffs, dimF,_) = mkApply_fld(name, opr, ishape, inputfile)      (app, coeffs, dimF,_) = mkApply_fld(name, opr, ishape, inputfile)
115      # main      # main
116      return central(app, coeffs, dimF)      (rtn,_,_,_,_) = central(app, coeffs, dimF)
117        return rtn
118    
119  #run all examples for a specific operator  #run all examples for a specific operator
120  def single1_all_ops(ex_opr):  def single1_all_ops(ex_opr):
121      print "single all ops"      #print "single all ops"
122      ex = get_ex(ex_opr)      ex = get_ex(ex_opr)
123      #print(example.get_oprname(ex))      #print(example.get_oprname(ex))
124      n = len(ex.tys)      n = len(ex.tys)
# Line 81  Line 126 
126      for ex_num  in range(n):      for ex_num  in range(n):
127          #print (example.toStr(ex,ex_num))          #print (example.toStr(ex,ex_num))
128          x =  example.toStr(ex,ex_num)+" "+str(ex_opr)+"-"+str(ex_num)+":"          x =  example.toStr(ex,ex_num)+" "+str(ex_opr)+"-"+str(ex_num)+":"
129          print x          #print x
130          y = single1_specific_ex(ex_opr, ex_num)          y = single1_specific_ex(ex_opr, ex_num)
131          rtn.append(x+y)          rtn.append(x+y)
132      return rtn      return rtn
# Line 95  Line 140 
140          for j in i:          for j in i:
141              print j              print j
142    
143  #get all the names  ##################################################################################################
144  def get_names():  # get result after applying operators
     for ex_opr in range(opr_max+1):  
         ex = get_ex(ex_opr)  
         n = len(ex.tys)  
         print ("cmd:(1 "+str(ex_opr)+") opr "+example.get_oprname(ex))  
         for ex_num  in range(n):  
             print ("\tcmd:(-1 "+str(ex_opr)+","+str(ex_num)+")"+example.toStr(ex,ex_num))  
   
 def depth2_main(opr_outer, opr_inner, ishape):  
     #create app object  
     (app, coeffs, dimF) = mkApply_twice(opr_inner.name+"("+opr_outer.name+")", opr_inner,opr_outer, ishape, inputfile)  
     # main part  
     return central(app, coeffs, dimF)  
   
145  def get_tshape(opr_inner,ishape):  def get_tshape(opr_inner,ishape):
146      arity=opr_inner.arity      arity=opr_inner.arity
147        #print "checking for first time in rum.py"
148        #print ("checking second layers", opr_inner.name,"ishape",ishape[0].name)
149      if(arity==1):      if(arity==1):
150          return applyUnaryOp(opr_inner,ishape)          return applyUnaryOp(opr_inner,ishape)
151      elif(arity==2):      elif(arity==2):
152            #print ("-", ishape[1].name)
153          return applyBinaryOp(opr_inner,ishape)          return applyBinaryOp(opr_inner,ishape)
154    
 def write(e):  
     print (e)  
     # if it works continue  
     f = open("results_tmp.txt", 'a+')  
     f.write(e)  
     f.close()  
   
155  # checks to see if specific ex works  # checks to see if specific ex works
156  def embed2_specific_ex(ex_opr, ex_num, opr_outer):  def embed2_specific_ex(ex_opr, ex_num, opr_outer, fty):
157      # current example      # current example
158      (name,opr_inner,ishape)= get_single_example(ex_opr, ex_num)      (name,opr_inner,ishape)= get_single_example(ex_opr, ex_num)
159      print ("name:", name, "outer",opr_outer.name)      #print ("name:", name, "outer",opr_outer.name)
160        # first layer
161      (_,tshape) = get_tshape(opr_inner,ishape)      (_,tshape) = get_tshape(opr_inner,ishape)
162      (tf, _) = applyUnaryOp(opr_outer,[tshape])      #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      if(tf==true):# if it works continue      if(tf==true):# if it works continue
167          write("\n\t\tpassed ")          write("\n\t\tpassed ")
168          return depth2_main(opr_outer, opr_inner, ishape)          #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      else:      else:
177          x = "\n\t\tskipped did not apply "+opr_outer.name+" to "+tshape.name          x = "\n\t\tskipped did not apply "+opr_outer.name+" to ("+tshape.name+","
178          write(x)          write(x)
179          return x          return (0, x, 0, 0, 0,0)
180    
181  #apply all possible unary operators to a specific inside example  #apply all possible unary operators to a specific inside example
182  def embed2_all_outer(ex_opr, ex_num):  def embed2_outer(ex_opr, ex_num, opr_outer,ftyname, es):
183      n = len(op_unary)      #write("\n*******:"+name+" len("+str(n)+")******")
184      (name,opr_inner,ishape)= get_single_example(ex_opr, ex_num)      x = "-i_opr#("+idToStr(ex_opr)
185      write("\n*******:"+name+" len("+str(n)+")******")      x +=")type#("+str(ex_num)+","+ftyname
186      rtn = []      x+=")\no_opr#("+opr_outer.name
187      for  i in range(n):      x+=" between that and "+ftyname
         opr_outer= op_unary[i]  
         x = "-i_opr#("+str(ex_opr)+")type#("+str(ex_num)+")o_opr#("+str(i)+"):"+opr_outer.name  
188          write("\n"+x)          write("\n"+x)
189          rtn.append(x+embed2_specific_ex(ex_opr, ex_num, opr_outer))      return embed2_specific_ex(ex_opr, ex_num, opr_outer, es)
190      return rtn  
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        rtn = []
211        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    
227  #run all examples for a specific operator  #run all examples for a specific operator
228  def embed2_all_ops(ex_opr):  def embed2_iter_tys(ex_opr, gty):
229      ex = get_ex(ex_opr)      n = len(get_ex(ex_opr).tys)
     op1=(example.get_oprname(ex))  
     n = len(ex.tys)  
     star="**********************"  
     write("\n"+star+"i_opr:"+op1+"("+str(ex_opr)+") len: "+str(n)+ star)  
230      rtn = []      rtn = []
231        cnt = 0
232        total = 0
233        rst_good = 0
234        rst_eh = 0
235        rst_terrible = 0
236        rst_compile = 0
237      for ex_num  in range(n):      for ex_num  in range(n):
238          rtn.append(embed2_all_outer(ex_opr, ex_num))          (cnt1, rtn1, rst_good1, rst_eh1, rst_terrible1, rst_compile1, total1) = embed2_iter_outer(ex_opr, ex_num, gty)
239      return rtn          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    
248  #run all possible examples  #run all possible examples
249  def embed2_all_exs():  def embed2_iter_inner(gty):
250        n = opr_max+1
251      rtn = []      rtn = []
252      for ex_opr in range(opr_max+1):      cnt = 0
253          rtn.append(embed2_all_ops(ex_opr))#run all possible examples      total = 0
254      return rtn      rst_good = 0
255        rst_eh = 0
256  def depth2_hardcoded(ex_num):      rst_terrible = 0
257      ex0 = (op_divergence,op_add, [ty_vec2F_d2,ty_vec2F_d2])      rst_compile = 0
258      ex1 = (op_negation,op_divergence,[ty_vec2F_d2])      for ex_opr in range(n):
259      ex2 = (op_negation, op_gradient, [ty_scalarF_d2])          (cnt1, rtn1, rst_good1, rst_eh1, rst_terrible1, rst_compile1, total1) = embed2_iter_tys(ex_opr, gty)
260      exs = [ex0,ex1,ex2]          rtn.append(rtn1)
261      #create app object          cnt+=int(cnt1)
262      (opr_outer, opr_inner, ishape)=exs[ex_num]          total +=total1
263      # main part          rst_good +=rst_good1
264      depth2_main(opr_outer, opr_inner, ishape)          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    
269    
270  n = int(todo) #command  n = int(todo) #command
# Line 191  Line 276 
276      depth1_all_exs()      depth1_all_exs()
277  elif (n==-1):  elif (n==-1):
278      #run all the programs      #run all the programs
279      rtn= embed2_all_exs()      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      for i in rtn:      for i in rtn:
283          for j in i:          for j in i:
284              for k in j:              for k in j:
# Line 205  Line 292 
292      os.system("open results_tmp.txt")      os.system("open results_tmp.txt")
293  elif(n==-2):  elif(n==-2):
294      ex_opr = int(sys.argv[2])      ex_opr = int(sys.argv[2])
295      rtn = embed2_all_ops(ex_opr)      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      for i in rtn:      for i in rtn:
299          for j in i:          for j in i:
300              print j              print j
# Line 224  Line 313 
313      # and all possible outer operators      # and all possible outer operators
314      ex_opr = int(sys.argv[2])      ex_opr = int(sys.argv[2])
315      ex_num = int(sys.argv[3])      ex_num = int(sys.argv[3])
316      rtn = embed2_all_outer(ex_opr, ex_num)      gty = -1
317        (cnt, rtn, rst_good, rst_eh, rst_terrible, rst_compile, total) = embed2_iter_outer(ex_opr, ex_num, gty)
318      for i in rtn:      for i in rtn:
319          print i          print i
320  elif (n==4): # run a specific single layer example with type and opr  elif (n==4): # run a specific single layer example with type and opr
# Line 235  Line 325 
325      ex_num = int(sys.argv[3])      ex_num = int(sys.argv[3])
326      ex_outer= int(sys.argv[4])      ex_outer= int(sys.argv[4])
327      opr_outer= op_unary[ ex_outer]      opr_outer= op_unary[ ex_outer]
328      rtn = embed2_specific_ex(ex_opr, ex_num,  opr_outer)      rtn = embed2_specific_ex(ex_opr, ex_num,  opr_outer,[])
329      print rtn      print rtn
330    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  else:  else:
436    raise "unsupported"    raise "unsupported"

Legend:
Removed from v.3945  
changed lines
  Added in v.3946

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