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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : cchiw 4252 import sys
2 :     import re
3 :     import os
4 : cchiw 4457 from obj_apply import *
5 :     from obj_ex import *
6 :     from obj_field import *
7 :     from obj_counter import *
8 :     from obj_frame import *
9 :    
10 : cchiw 4252 from test_createField import createField
11 :     from test_writeDiderot import writeDiderot
12 :     from test_eval import eval
13 :     from test_compare import compare
14 :     from test_observed import observed
15 : cchiw 4457
16 : cchiw 4455 from gut_check import *
17 : cchiw 4457 from write import *
18 : cchiw 4481 from var_ty import *
19 :     from frame import *
20 : cchiw 4252
21 : cchiw 4457 # results from testing
22 :     def analyze(names, x, extraname, cnt, rtn, observed_data, correct_data, branch):
23 :     (rtn_1, rst_good_1, rst_eh_1, rst_check_1, rst_terrible_1, rst_compile_1, rst_NA_1) = rtn
24 : cchiw 4483 #print "X", x
25 : cchiw 4481 x = ("\n\t\t-"+x+" "+rtn_1)
26 : cchiw 4457 writeall(x)
27 : cchiw 4483 #print (x)
28 : cchiw 4457 # collect results
29 :     counter.inc_locals(cnt, rtn)
30 :     counter.inc_cumulative(cnt)
31 :     counter.inc_cnt(cnt)
32 :     # check results
33 :     if (rst_check_1==7):
34 :     rst_check(names, x, extraname, branch, observed_data, correct_data)
35 :     elif (rst_terrible_1==7):
36 :     rst_terrible(names, x, extraname, branch, observed_data, correct_data)
37 :     elif (rst_NA_1==1):
38 :     rst_NA(names, x, extraname, branch)
39 :     return
40 :    
41 : cchiw 4481 ##################################################################################################
42 :     ##################################################################################################
43 :    
44 : cchiw 4252 # already created app object
45 : cchiw 4457 def core(app, coeffs, dimF, names, testing_frame, cnt):
46 : cchiw 4481 #print "############################################inside central############################################"
47 :     writetys("\n\t-"+apply.get_all_FieldTys(app)+"|"+ names)
48 :    
49 : cchiw 4457 # get global variables from testing framework
50 :     g_lpos = frame.get_lpos(testing_frame)
51 :     g_upos = frame.get_upos(testing_frame)
52 :     g_num_pos = frame.get_num_pos(testing_frame)
53 :     g_p_Observ = frame.get_p_Observ(testing_frame)
54 :     g_output = frame.get_output(testing_frame)
55 :     g_samples = frame.get_samples(testing_frame)
56 :     g_branch = frame.get_branch(testing_frame)
57 :     # transform from global variables
58 :     t_isNrrd = frame.transform_isNrrd(testing_frame)
59 :     t_nrrdbranch = frame.transform_nrrdpath(testing_frame)
60 :     t_runtimepath = frame.transform_runtimepath(testing_frame)
61 :    
62 : cchiw 4483 #print "*******************************************"
63 : cchiw 4268 x = "_"+(apply.get_all_FieldTys(app)+" |"+names)
64 : cchiw 4483 #print x
65 : cchiw 4457 extraname = "\n\t-"+app.name
66 :    
67 :     # testing positions
68 :     positions = get_positions(dimF, g_lpos, g_upos, g_num_pos)
69 : cchiw 4252 # samples
70 :     #create synthetic field data with diderot
71 : cchiw 4457 createField(app, g_samples, coeffs, t_nrrdbranch)
72 : cchiw 4252 #create diderot program with operator
73 :     #print "about to write program"
74 : cchiw 4457 writeDiderot(g_p_Observ, app, positions, g_output, t_runtimepath, t_isNrrd)
75 : cchiw 4252 #read observed data
76 : cchiw 4483 #print "about to observe"
77 : cchiw 4457 observed_data = observed(app, g_output)
78 : cchiw 4483 #print observed_data
79 : cchiw 4457
80 : cchiw 4308 if (len(observed_data)<1):
81 : cchiw 4252 rtn1 = "diderot could not handle program"
82 : cchiw 4483 #print "thinks could not handle program"
83 : cchiw 4458 return rst_compile(names, x, extraname, cnt)
84 : cchiw 4252 else:
85 : cchiw 4455 if(check(app, observed_data)):
86 :     correct_data = eval(app , positions)
87 : cchiw 4483 #print "correct data", correct_data
88 : cchiw 4455 rtn = compare(app, observed_data, correct_data)
89 : cchiw 4457 return analyze(names, x, extraname, cnt, rtn, observed_data, correct_data, g_branch)
90 : cchiw 4455 else:
91 : cchiw 4457 counter.inc_NA(cnt)
92 : cchiw 4481 return rst_NA(names, x, extraname, g_branch)
93 :     ##################################################################################################
94 :     ##################################################################################################
95 :    
96 :    
97 :     ##################################################################################################
98 :     # functions create app objects
99 :     # get example from list of examples
100 :     def create_single_app(opr_inner, t_num, testing_frame, cnt):
101 :     # global variables needed from testing framework
102 :     g_inputfile = frame.get_inputfile(testing_frame)
103 :     g_ucoeff = frame.g_ucoeff(testing_frame)
104 :     g_coeff_style = frame.get_coeff_style(testing_frame) # global variable from set
105 :     g_rst_ty = frame.get_rst_ty(testing_frame)
106 :     g_krn = frame.get_krn(testing_frame)
107 : cchiw 4483 #print "single specific ex"
108 : cchiw 4481 (name,opr,ishape)= get_single_example(opr_inner, t_num, g_rst_ty)
109 :     # get k value of tshape from kernels
110 :     set_ks(g_krn, ishape)
111 : cchiw 4483 #print "calling tshape"
112 : cchiw 4481 (tf1, tshape1) = get_tshape(opr_inner,ishape)
113 :     if(not tf1):
114 :     write_terrible("\n apply blocked from attempting: "+"b__"+name+str(opr_inner.id)+"_"+str(t_num))
115 :     return None
116 : cchiw 4483 #print "after calling tshape"
117 : cchiw 4481 #create app object
118 :    
119 :     (app, coeffs, _) = mkApply_fld(name, opr, ishape, g_inputfile, tshape1, g_coeff_style, g_ucoeff, g_krn)
120 :    
121 :     dimF = tshape1.dim
122 : cchiw 4483 # print "creating app"
123 :     #print "app oty", app.oty
124 : cchiw 4481 # main
125 :     names= "s_"+str(opr_inner.id)+"__"+"n_"+str(t_num)+"_"
126 :     return (app, coeffs, dimF, names)
127 :    
128 :     # checks to see if specific ex works
129 :     def create_embed_app_passed(ishape, tshape1, tshape2, opr_inner, opr_outer, title, testing_frame, cnt):
130 :     # break
131 : cchiw 4483 #y = Title_outer(opr_inner, opr_outer)
132 :     #x = "\n -- shapes:"
133 :     #for i in ishape:
134 :     # x+=i.name+","
135 : cchiw 4481 #writeall(x)
136 :     #print(x)
137 : cchiw 4483 #counter.inc_cumulative(cnt)
138 :     #counter.inc_cnt(cnt)
139 :     #write_results(y, testing_frame, cnt)
140 :     #return
141 : cchiw 4481
142 :     # global variables needed from testing framework
143 :     g_inputfile = frame.get_inputfile(testing_frame)
144 :     g_ucoeff = frame.g_ucoeff(testing_frame)
145 :     g_coeff_style = frame.get_coeff_style(testing_frame) # global variable from set
146 :     g_krn = frame.get_krn(testing_frame)
147 :    
148 :     # if it works continue
149 :     #create app object
150 : cchiw 4483 #print "opr_outer", opr_outer.name
151 :     #print "tshape2", tshape2.name
152 : cchiw 4481 appname = opr_outer.name+"("+opr_inner.name+")"
153 :    
154 :     (app, coeffs) = mkApply_twice(appname, opr_inner,opr_outer, ishape, g_inputfile, tshape1, tshape2, g_coeff_style, g_ucoeff, g_krn)
155 :     dimF = tshape2.dim
156 :     # main part
157 : cchiw 4483 #print title
158 : cchiw 4481 #return (app, coeffs, dimF, title)
159 :     return core(app, coeffs, dimF, title, testing_frame, cnt)
160 :    
161 :     def convert_fields(ishape,testing_frame):
162 :     g_krn = frame.get_krn(testing_frame)
163 :     set_ks(g_krn, ishape)
164 :    
165 :     # checks to see if specific ex works
166 :     def create_embed_app(name, ishape0, opr_inner, opr_outer, fty, title, testing_frame, cnt):
167 : cchiw 4483 #print "current embed inner: "+opr_inner.name+"("+str(opr_inner.id)+") outer: " +opr_outer.name+"("+str(opr_outer.id)+")#"
168 : cchiw 4481 # get value of k from kernels
169 :     ishape = ishape0+fty
170 :     # get value of k from kernels
171 :     convert_fields(ishape,testing_frame)
172 :     # first layer
173 :     # get result after applying operators
174 :     (tf1, tshape1) = get_tshape(opr_inner,ishape)
175 : cchiw 4483 #print "tf1",tf1, tshape1
176 : cchiw 4481 if(tf1==false):
177 : cchiw 4483 #print "found false at tf1"
178 : cchiw 4481 #return None
179 : cchiw 4483 #print "found none after create embed app"
180 : cchiw 4481 return
181 :     else:
182 : cchiw 4483 #print "tshape1", tshape1.name
183 : cchiw 4481 #second layer, adds second field type
184 :     (tf2, tshape2) = get_tshape(opr_outer,[tshape1]+fty)
185 : cchiw 4483 #print "tf2", tf2, tshape2
186 : cchiw 4481
187 :     if(tf2==true):# if it works continue
188 :     #create app object
189 :     #print "appoty",app.oty.name
190 :     #writetys("\n\t-"+apply.get_all_FieldTys(app)+"|"+ title)
191 :     #writetys("\t ("+ishape[0].name)
192 :     #if(len(ishape0)>1):
193 :     # writetys(","+ishape[1].name)
194 :     #writetys(") -> ("+ tshape1.name)
195 :     #if(len(fty)==1):
196 :     # writetys(","+fty[0].name)
197 :     #writetys(") -> "+ tshape2.name)
198 :    
199 :     create_embed_app_passed(ishape, tshape1, tshape2, opr_inner, opr_outer, title, testing_frame, cnt)
200 :     return
201 :     else:
202 :     # "\n\t\tskipped did not apply "+opr_outer.name+" to ("+str(tshape2)+","
203 : cchiw 4483 #print "tf2 found false at this point"
204 : cchiw 4481 return
205 :    
206 :    
207 :    

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