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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4483 - (download) (as text) (annotate)
Fri Sep 2 05:07:01 2016 UTC (2 years, 6 months ago) by cchiw
File size: 7861 byte(s)
shape based iteration
import sys
import re
import os
from obj_apply import *
from obj_ex import  *
from obj_field import *
from obj_counter import *
from obj_frame import *

from test_createField import createField
from test_writeDiderot import writeDiderot
from test_eval import eval
from test_compare import compare
from test_observed import observed

from gut_check import *
from write import *
from var_ty import *
from frame import  *

# results from testing
def analyze(names, x, extraname, cnt, rtn, observed_data, correct_data, branch):
    (rtn_1, rst_good_1, rst_eh_1, rst_check_1, rst_terrible_1, rst_compile_1, rst_NA_1) =  rtn
    #print "X", x
    x = ("\n\t\t-"+x+" "+rtn_1)
    writeall(x)
    #print (x)
    # collect results
    counter.inc_locals(cnt, rtn)
    counter.inc_cumulative(cnt)
    counter.inc_cnt(cnt)
    # check results
    if (rst_check_1==7):
        rst_check(names, x, extraname, branch, observed_data, correct_data)
    elif (rst_terrible_1==7):
        rst_terrible(names, x, extraname, branch, observed_data, correct_data)
    elif (rst_NA_1==1):
         rst_NA(names, x, extraname,  branch)
    return

##################################################################################################
##################################################################################################

# already created app object
def core(app, coeffs, dimF, names, testing_frame, cnt):
    #print "############################################inside central############################################"
    writetys("\n\t-"+apply.get_all_FieldTys(app)+"|"+  names)
    
    # get global variables from testing framework
    g_lpos = frame.get_lpos(testing_frame)
    g_upos = frame.get_upos(testing_frame)
    g_num_pos = frame.get_num_pos(testing_frame)
    g_p_Observ = frame.get_p_Observ(testing_frame)
    g_output = frame.get_output(testing_frame)
    g_samples = frame.get_samples(testing_frame)
    g_branch = frame.get_branch(testing_frame)
    # transform from global variables
    t_isNrrd = frame.transform_isNrrd(testing_frame)
    t_nrrdbranch = frame.transform_nrrdpath(testing_frame)
    t_runtimepath = frame.transform_runtimepath(testing_frame)
    
    #print "*******************************************"
    x = "_"+(apply.get_all_FieldTys(app)+" |"+names)
    #print x
    extraname = "\n\t-"+app.name

    # testing positions
    positions = get_positions(dimF, g_lpos, g_upos, g_num_pos)
    # samples
    #create synthetic field data with diderot
    createField(app, g_samples, coeffs, t_nrrdbranch)
    #create diderot program with operator
    #print "about to write program"
    writeDiderot(g_p_Observ, app, positions, g_output, t_runtimepath, t_isNrrd)
    #read observed data
    #print "about to observe"
    observed_data = observed(app, g_output)
    #print observed_data
    
    if (len(observed_data)<1):
        rtn1 = "diderot could not handle program"
        #print "thinks could not handle program"
        return rst_compile(names, x, extraname, cnt)
    else:
        if(check(app, observed_data)):
            correct_data = eval(app , positions)
            #print "correct data", correct_data
            rtn = compare(app, observed_data, correct_data)
            return analyze(names, x, extraname, cnt, rtn, observed_data, correct_data, g_branch)
        else:
            counter.inc_NA(cnt)
            return rst_NA(names, x, extraname, g_branch)
##################################################################################################
##################################################################################################


##################################################################################################
# functions create app objects
# get example from list of examples
def create_single_app(opr_inner, t_num, testing_frame, cnt):
    # global variables needed from testing framework
    g_inputfile = frame.get_inputfile(testing_frame)
    g_ucoeff = frame.g_ucoeff(testing_frame)
    g_coeff_style = frame.get_coeff_style(testing_frame) # global variable from set
    g_rst_ty = frame.get_rst_ty(testing_frame)
    g_krn = frame.get_krn(testing_frame)
    #print "single specific ex"
    (name,opr,ishape)= get_single_example(opr_inner, t_num, g_rst_ty)
    # get k value of tshape from kernels
    set_ks(g_krn, ishape)
    #print "calling tshape"
    (tf1, tshape1) = get_tshape(opr_inner,ishape)
    if(not tf1):
        write_terrible("\n apply blocked from attempting: "+"b__"+name+str(opr_inner.id)+"_"+str(t_num))
        return None
    #print "after calling tshape"
    #create app object

    (app, coeffs, _) = mkApply_fld(name, opr, ishape, g_inputfile, tshape1, g_coeff_style, g_ucoeff, g_krn)
    
    dimF = tshape1.dim
    # print  "creating app"
    #print "app oty", app.oty
    # main
    names= "s_"+str(opr_inner.id)+"__"+"n_"+str(t_num)+"_"
    return (app, coeffs, dimF, names)

# checks to see if specific ex works
def create_embed_app_passed(ishape, tshape1, tshape2, opr_inner, opr_outer, title, testing_frame, cnt):
    # break
    #y = Title_outer(opr_inner, opr_outer)
    #x = "\n -- shapes:"
    #for i in ishape:
    #    x+=i.name+","
    #writeall(x)
    #print(x)
    #counter.inc_cumulative(cnt)
    #counter.inc_cnt(cnt)
    #write_results(y, testing_frame, cnt)
    #return
    
    # global variables needed from testing framework
    g_inputfile = frame.get_inputfile(testing_frame)
    g_ucoeff = frame.g_ucoeff(testing_frame)
    g_coeff_style = frame.get_coeff_style(testing_frame) # global variable from set
    g_krn = frame.get_krn(testing_frame)

    # if it works continue
    #create app object
    #print "opr_outer", opr_outer.name
    #print "tshape2", tshape2.name
    appname  = opr_outer.name+"("+opr_inner.name+")"

    (app, coeffs) = mkApply_twice(appname, opr_inner,opr_outer, ishape, g_inputfile, tshape1, tshape2, g_coeff_style, g_ucoeff, g_krn)
    dimF = tshape2.dim
    # main part
    #print title
    #return (app, coeffs, dimF, title)
    return core(app, coeffs, dimF, title, testing_frame, cnt)

def convert_fields(ishape,testing_frame):
    g_krn = frame.get_krn(testing_frame)
    set_ks(g_krn, ishape)

# checks to see if specific ex works
def create_embed_app(name, ishape0, opr_inner, opr_outer, fty, title, testing_frame, cnt):
    #print "current embed inner: "+opr_inner.name+"("+str(opr_inner.id)+") outer: " +opr_outer.name+"("+str(opr_outer.id)+")#"
    # get value of k from kernels
    ishape = ishape0+fty
    # get value of k from kernels
    convert_fields(ishape,testing_frame)
    # first layer
    # get result after applying operators
    (tf1, tshape1) = get_tshape(opr_inner,ishape)
    #print "tf1",tf1, tshape1
    if(tf1==false):
        #print "found false at tf1"
        #return None
        #print "found none after create embed app"
        return
    else:
        #print "tshape1", tshape1.name
        #second layer, adds second field type
        (tf2, tshape2) = get_tshape(opr_outer,[tshape1]+fty)
        #print "tf2", tf2, tshape2
        
        if(tf2==true):# if it works continue
            #create app object
            #print "appoty",app.oty.name
            #writetys("\n\t-"+apply.get_all_FieldTys(app)+"|"+  title)
            #writetys("\t  ("+ishape[0].name)
            #if(len(ishape0)>1):
            #    writetys(","+ishape[1].name)
            #writetys(") -> ("+ tshape1.name)
            #if(len(fty)==1):
            #    writetys(","+fty[0].name)
            #writetys(") -> "+ tshape2.name)
                
            create_embed_app_passed(ishape, tshape1, tshape2, opr_inner, opr_outer, title, testing_frame, cnt)
            return
        else:
            # "\n\t\tskipped did not apply "+opr_outer.name+" to ("+str(tshape2)+","
            #print "tf2 found false at this point"
            return




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