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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4429 - (download) (as text) (annotate)
Thu Aug 18 21:01:59 2016 UTC (2 years, 9 months ago) by cchiw
File size: 19945 byte(s)
updated compare
import sys
import re
import os
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 obj_apply import *
from obj_ex import  *
from obj_field import *
from set import  *
from core import *
from write import *
# unu save -f nrrd -e ascii -i out.nrrd | less
isVis15 = true
args_types = int(sys.argv[1])
layer = int(sys.argv[2])
args = int(sys.argv[3])

#args_types = 1

print ("\n\n**** starting:",layer , args,args_types)

##################################################################################################
#global vars
#rtn = []
rst_cnt = 0
rst_total = 0
rst_total_compile = 0
rst_total_terrible = 0
rst_total_check= 0
rst_total_good =0
rst_total_eh= 0

rst_good = 0
rst_eh = 0
rst_terrible = 0
rst_check = 0
rst_compile = 0
rst_cumulative = 0
runtimepath  =  "" #path to branch testing
branch=""
if isVis15:
    runtimepath  = "/Users/chariseechiw/diderot/vis15/bin/diderotc --exec --double "
    branch ="vis15"
else:
    #runtimepath  = "/Users/chariseechiw/diderot/ein16/bin/diderotc  --double "
    #branch = "ein16"
    runtimepath  = "/Users/chariseechiw/diderot/branch/ein16-3682/bin/diderotc  --double "
    branch = "ein16"
print "runtimepath ", runtimepath

r =runtimepath+" r4428"
writeall(r)
writesummary(r)
write_terrible(r)

# unu grid -i inputfile.nrrd | unu save -f text
# ^ where all the points are.

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

def clean():
    # Clean up
    os.system("rm *.o")
    os.system("rm *.pyc")
    os.system("rm *.h")
    os.system("rm *.nrrd")
    os.system("rm *.cxx")
    os.system("rm *.diderot")
    os.system("rm fs3d-vec2")
    os.system("rm fs3d-vec2")

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

# add to global results
def analyze(pre, rtn, names, x, observed_data, correct_data, branch, extraname):
    (rtn_1, rst_good_1, rst_eh_1, rst_check_1, rst_terrible_1, rst_compile_1) =  rtn
    global rst_compile
    global rst_good
    global rst_eh
    global rst_check
    global rst_terrible
    global rst_cnt
    global rst_cumulative
    global rst_total_check
    global rst_total_compile
    global rst_total_eh
    global rst_total_good
    global rst_total_terrible
    
    x = ("\n\t-"+x+"\n\t-"+rtn_1)
    writeall(x)
    print (x)
    if (rst_compile_1==1):
        rst_compile += 1
        rst_total_compile  += 1
        #writeToRst(pre+"c__"+names, observed_data, correct_data, branch, x)

        write_terrible("\n\n***"+pre+"c__"+names)
        write_terrible("\n\t - did not compile: ")
        write_terrible(extraname)
        write_terrible(x)

        return
    else:
        # collect results
        rst_good +=  rst_good_1
        rst_total_good +=  rst_good_1
        rst_eh += rst_eh_1
        rst_total_eh += rst_eh_1
        rst_terrible += rst_terrible_1
        rst_total_terrible += rst_terrible_1
        rst_check  += rst_check_1
        rst_total_check+=rst_check_1
        rst_compile += rst_compile_1
        rst_cnt += 1
        rst_cumulative +=1
        if (rst_check_1==1):
            writesummary(x)
            writeToRst(pre+"k__"+names, observed_data, correct_data, branch, x)
            write_terrible("\n\n***"+pre+"k__"+names)
            write_terrible("\n\t - check: ")
            write_terrible(extraname)
            write_terrible(x)
        if (rst_terrible_1==1):
            writesummary(x)
            writeToRst(pre+"t__"+names, observed_data, correct_data, branch, x)
            write_terrible("\n\n***"+pre+"t__"+names)
            write_terrible("\n\t - terrible: ")
            write_terrible(extraname)
            write_terrible(x)
        clean()
        return
    return

# already created app object
def central(app, coeffs, dimF, names):
    #print "############################################inside central############################################"
    writetys("\n\t-"+apply.get_all_FieldTys(app)+"|"+  names)
    print "pre-core"
    (rtn, x, observed_data, correct_data) = core(app, coeffs, dimF, names, runtimepath, isVis15)
    # add to global results
    pre = ""
    return analyze(pre, rtn, names, x, observed_data, correct_data, branch,"\n\t-"+app.name)


# already created app object
def central22(app, coeffs, dimF, names):
    #print "############################################inside central############################################"
    writetys("\n\t-"+apply.get_all_FieldTys(app)+"|"+  names)
    
    #in vis15
    runtimepath  = "/Users/chariseechiw/diderot/vis15/bin/diderotc --exec "
    branch = "vis15"
    isVis15 = false
    (rtn, x, observed_data, correct_data) = core(app, coeffs, dimF, names, runtimepath, isVis15)
    analyze(branch, rtn, names, x, observed_data, correct_data, branch)
    # ein 16
    runtimepath  = "/Users/chariseechiw/diderot/ein16/bin/diderotc "
    branch="ein16"
    isVis15 = true
    (rtn, x, observed_data, correct_data) = core(app, coeffs, dimF, names, runtimepath, isVis15)
    return analyze(branch, rtn, names, x, observed_data, correct_data, branch)

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


# functions create app objects
# get example from list of examples
def create_single_app(opr_inner, t_num):
    print "single specific ex"
    (name,opr,ishape)= get_single_example(opr_inner, t_num, args_types)
    print "callign 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, inputfile, tshape1)
    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(opr_inner, opr_outer, t_num, fty, title):
    print "current embed inner: "+opr_inner.name+"("+str(opr_inner.id)+") outer: " +opr_outer.name+"("+str(opr_outer.id)+")#"+str(t_num)
    # current example
    (name,opr_inner,ishape)= get_single_example(opr_inner, t_num, args_types)
    # 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
    else:
        print "tshape1", tshape1.name
        #second layer, adds second field type
        ishape = ishape+fty
        (tf2, tshape2) = get_tshape(opr_outer,[tshape1]+fty)
        print "tf2", tf2, tshape2
        if(tf2==true):# 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, inputfile, tshape1, tshape2)
            dimF = tshape2.dim
            # main part
            print title
            print "appoty",app.oty.name
            return (app, coeffs, dimF, title)
        else:
            # "\n\t\tskipped did not apply "+opr_outer.name+" to ("+str(tshape2)+","
            print "tf2 found false at this point"
            return None
##################################################################################################
# get example from list of examples
def single_specific_ex(opr_inner, t_num):
    global rst_total
    rst_total+= 1
    # main
    rtn = create_single_app(opr_inner, t_num)
    if (rtn==None):
        return
    else:
        (app, coeffs, dimF, names) = rtn
        print "names",names
        return central(app, coeffs, dimF, names)

def get_all_types():
    if(args_types==0):
        return l_all_T
    elif(args_types==1):
        return l_all_F
    else:
        return l_all

def get_extra(ex_ty2):
    l = get_all_types()
    return (len(l), l[ex_ty2])


def embed_base_specific_ex(opr_inner, opr_outer, t_num, t_ty2):
    global rst_total
    rst_total+= 1
    # get specific outer operator
    print "inside embed base specific "
    print "inner", opr_inner.id, "outer", opr_outer.id, "t-num", t_num
    def get_fty(ex_ty2):
        if(needextratype(opr_inner, opr_outer)):
            (_, x) = get_extra(ex_ty2)
            print "gets extra type @", ex_ty2, x.name
            return ([x], "_fty"+ str(t_ty2))
        else:
            return ([], "")
    (fty, s) = get_fty(t_ty2)
    names="p_aty"+str(args_types)+"_i"+str(opr_inner.id)+"_o"+str(opr_outer.id)+"_n"+str(t_num)+s
    print "names",names
    rtn = create_embed_app(opr_inner, opr_outer, t_num, fty, names)
    if(rtn==None):
        print "found none after create embed app"
        return
    else:
        print "found something after create embed app"
        (app, coeffs, dimF, names) = rtn

        return central (app, coeffs, dimF, names)


##################################################################################################
def writeCumulativeS():
    x= "\n\n # cumulative break down  # "+str(rst_cumulative)
    x+= " A# "+str(rst_total_good )+" B # "+str(rst_total_eh )+" C# "+str( rst_total_check  )+" D# "+str(rst_total_terrible )+" did not run  # "+str( rst_total_compile)
    return x


def writeCumulative():
    x=writeCumulativeS()
    print (x)
    writeall(x)
    writesummary(x)


def write_results(pre):
    global rst_compile
    global rst_good
    global rst_eh
    global rst_terrible
    global rst_check
    global rst_cnt
    global rst_total
    global layer
    global args
    #    global rst_cumulative
    x= "\n"
    if(rst_good==rst_cnt):
        x+="PASS:"
    else:
        x+="CHECK:"
    x+= "cmd: "+str(layer)+" "+str(args)+" "+"- "+pre+"- "+branch
    if(rst_good>0):
        x+=" A:"+str(rst_good)+"|"+str(rst_cnt)
    if(rst_eh>0):
        x+=" B:"+str( rst_eh)+"|"+str(rst_cnt)
    if(rst_check>0):
        x+=" C:"+str( rst_terrible)+"|"+str(rst_cnt)
    if(rst_terrible>0):
        x+=" D:"+str( rst_terrible)+"|"+str(rst_cnt)
    if(rst_compile>0):
        x+=" did not run :"+str( rst_compile)+"|"+str(rst_total)
    x+= " ran: "+str(rst_cnt)+"|" +str(rst_total)+" cumulative: "+str(rst_cumulative)
    #x+=writeCumulativeS()
    x+="\n***************************************************\n"
    writeall(x)
    writesummary(x)


def writeResults_inner(opr_inner):
    y = Title_inner(opr_inner)
    write_results(y)
    writeCumulative()

def writeResults_outer(opr_inner, opr_outer):
    y = Title_outer(opr_inner, opr_outer)
    write_results(y)
    writeCumulative()

################################################## iterating ###############################################
def iter_num(opr_inner, opr_outer, n_num, t_ty2):
    print "inside iter num"
    for t_num  in range(n_num):
        embed_base_specific_ex(opr_inner, opr_outer, t_num, t_ty2)

#iterates over extra type and ex_num type
def embed_base_iter_ty2(opr_inner, opr_outer):
    print "inside embed base iter -ty 2 "
    ex_outer = oprToEx(opr_inner, args_types)
    n_num = len(ex_outer.tys)
    print(" "+str(opr_inner.name)+"-"+str(opr_outer.name)+" tys length:" +str(n_num))
    if(needextratype(opr_inner, opr_outer)):
        (n_ty2, _) = get_extra(0)  # use all field types as extra types
        
        for t_ty2 in range(n_ty2):  #extra type
            print "as extra type using ", t_ty2
            iter_num(opr_inner, opr_outer, n_num, t_ty2)
    else:
         iter_num(opr_inner, opr_outer, n_num,  None)
    return

#iterating ex_outer from 0...l
# iterate over outer operator and extra type
def embed_base_iter_outer2(opr_inner, t_num):
    # print "\nembed_base_iter_outer: ex_opr",ex_opr
    n_outer = getN()
    #writeall(y)
    #writesummary(y)
    #have ex_opr iterating over ex_outer
    global rst_cnt
    rst_cnt = 0
    global rst_total
    rst_total = 0
    global rst_compile
    rst_compile = 0
    global rst_good
    rst_good = 0
    global rst_eh
    rst_eh = 0
    global rst_check
    rst_check = 0
    global rst_terrible
    rst_terrible = 0
    for  t_outer in range(n_outer):
        opr_outer = id_toOpr(t_outer)
        writeTitle_outer(opr_inner, opr_outer)
        if(needextratype(opr_inner, opr_outer)):
            # use all field types as extra types
            (n_ty2, _) = get_extra(0)
            for t_ty2 in range(n_ty2):  #extra type
                embed_base_specific_ex(opr_inner, opr_outer, t_num, t_ty2)
        else:
            embed_base_specific_ex(opr_inner, opr_outer, t_num,  None)
            writeResults_outer(opr_inner, opr_outer)
    return
def embed_base_iter_ty2_wihty1(opr_inner, opr_outer, t_num):
    
    ex_outer = oprToEx(opr_inner, args_types)
    
    if(needextratype(opr_inner, opr_outer)):
        # use all field types as extra types
        (n_ty2, _) = get_extra(0)
        for t_ty2 in range(n_ty2):  #extra type
            
            print "as extra type using ", t_ty2
            
            embed_base_specific_ex(opr_inner, opr_outer, t_num, t_ty2)
    
    else:
        
        embed_base_specific_ex(opr_inner, opr_outer, t_num, None)
    
    return

#iterating ex_outer from 0...length(potential outer_operators)
def embed_base_iter_outer(opr_inner):
    writeTitle_inner(opr_inner)
    #have ex_opr iterating over ex_outer
    n_outer = getN()
    for  t_outer in range(n_outer):

        global rst_cnt
        rst_cnt = 0
        global rst_total
        rst_total = 0
        global rst_compile
        rst_compile = 0
        global rst_good
        rst_good = 0
        global rst_eh
        rst_eh = 0
        global rst_check
        rst_check = 0
        global rst_terrible
        rst_terrible = 0
        opr_outer = id_toOpr(t_outer)
        writeTitle_outer(opr_inner, opr_outer)
        embed_base_iter_ty2(opr_inner, opr_outer)
        writeResults_outer(opr_inner, opr_outer)
    return

#run all possible examples from 0...n
def embed2_iter_inner():
    n_opr = getN()
    for t_opr in range(n_opr):
        embed_base_iter_outer(id_toOpr(t_opr))
    return


#specify outer operator
def embed2_iter_inner_gotouter(opr_outer):
    n_opr = getN()
    global rst_total
    rst_total = 0
    #iterate over inner operator
    for t_opr in range(n_opr):
        global rst_cnt
        rst_cnt = 0
        global rst_compile
        rst_compile = 0
        global rst_good
        rst_good = 0
        global rst_eh
        rst_eh = 0
        global rst_check
        rst_check = 0
        global rst_terrible
        rst_terrible = 0
        opr_inner = id_toOpr(t_opr)
        writeTitle_outer(opr_inner, opr_outer)
        embed_base_iter_ty2(opr_inner, opr_outer)
        writeResults_outer(opr_inner, opr_outer)
    return


#run all examples for a specific operator
def single_all_ops(opr_inner):
    ex = oprToEx(opr_inner, args_types)

    n_num = len(ex.tys)
    if (n_num==0):
        return
    writeTitle_inner(opr_inner)
    global rst_cnt
    rst_cnt = 0
    global rst_compile
    rst_compile = 0
    global rst_good
    rst_good = 0
    global rst_eh
    rst_eh = 0
    global rst_terrible
    rst_terrible = 0
    global rst_check
    rst_check= 0
    for t_num  in range(n_num):
        single_specific_ex(opr_inner, t_num)
    return

##################################################################################################
##################################################################################################
if (layer==0):
    #does nothing
    print "******************************************"
    print "List of commands"
    print "*** single layered program"
    print "Ex. (A+B). operation (+) has id \"i\" and types to arguments ([A,B]) are specificed with \"t\""
    print "cmd: 1 2 i t \t single program with specific operator(i) and argument(s) (t)"
    print "cmd: 1 1 i \t specifies operator(i) and iterates over applicable argument types"
    print "cmd: 1 0 \t iterates over all possibilities"
    print "***  double layered programs -(A+B)"
    print "Ex. -(A+B).  outer operator(-) is specified with \"o\""
    print "cmd: 2 3 i o m \t  specifies inner operator(i), outer operator(o) and args (t)"
    print "cmd: 2 2 i o   \t  specifies inner operator(i), outer operator(o) and iterates over args"
    print "cmd: 2 20 i m  \t  specifies inner operator(i), args(t) and iterates over outer operations (o)"
    print "cmd: 2 1 i     \t  specifies inner operator(i) and iterates over outer operator, and args"
    print "cmd: 2 0       \t  iterate over all possibilities"

    print "ex. cmd: 2 2 1 3  => normalize (-F)"
    print "ex. cmd: 2 2 24 3 => normalize(F0+F1)"
    print "ex. cmd: 2 2 _ n => n must be less than <24"
    print "ex. cmd: 3 2 1 24  => (-F)+F1"
    print "ex. cmd: 3 2 25 24 => (F-F)+F"
    print "******************************************"
elif (layer==1):
    if(args==0):
        # iterate over single layer
        rtn = []
        for t_inner in range(getN()):
            opr_inner = id_toOpr(t_inner)
            writeTitle_inner(opr_inner)
            single_all_ops(opr_inner)
            writeResults_inner(opr_inner)
        writeCumulative()
    elif (args==1):
        # iterate over single layer
        t_inner= int(sys.argv[4])
        opr_inner = id_toOpr(t_inner)
        writeTitle_inner(opr_inner)
        single_all_ops(opr_inner)
        writeResults_inner(opr_inner)
    elif (args==2):
        t_inner= int(sys.argv[4])
        opr_inner = id_toOpr(t_inner)
        t_num= int(sys.argv[5])
        single_specific_ex(opr_inner,t_num)
        writeResults_inner(opr_inner)
elif (layer==2):
    if(args==0):
        #run all the programs
        embed2_iter_inner()
        writeCumulative()
    elif(args==1):
        # iterate over double layer with unary operator
        t_inner = int(sys.argv[4])
        opr_inner = id_toOpr(t_inner)
        embed_base_iter_outer(opr_inner)
        writeCumulative()
    elif(args==5):
        t_outer = int(sys.argv[4])
        opr_outer = id_toOpr(t_outer)
        writeTitle_outer2(opr_outer)
        embed2_iter_inner_gotouter(opr_outer)
        writeCumulative()
    elif (args==2):
        t_inner = int(sys.argv[4])
        t_outer = int(sys.argv[5])#outer  operator
        opr_outer = id_toOpr(t_outer)
        opr_inner = id_toOpr(t_inner)
        writeTitle_outer(opr_inner, opr_outer)
        print "about to call embed base iter ty 2 "
        embed_base_iter_ty2(opr_inner, opr_outer)
        writeResults_outer(opr_inner, opr_outer)
    elif (args==20):
        t_inner = int(sys.argv[4])
        t_num = int(sys.argv[5])#outer binary operator
        opr_inner = id_toOpr(t_inner)
        writeTitle_inner(opr_inner)
        embed_base_iter_outer2(opr_inner, t_num)
        writeResults_inner(opr_inner)
    elif(args==3):
        #  run a specific iterate over double layer with unary operator
        t_inner = int(sys.argv[4])
        t_outer= int(sys.argv[5])
        t_num = int(sys.argv[6])
        t_ty2 = None
        opr_outer = id_toOpr(t_outer)
        opr_inner = id_toOpr(t_inner)
        writeTitle_outer(opr_inner, opr_outer)
        embed_base_iter_ty2_wihty1(opr_inner, opr_outer, t_num)
        writeResults_outer(opr_inner, opr_outer)
    elif(args==4):
        #  run a specific iterate over double layer with unary operator
        t_inner = int(sys.argv[4])
        t_outer= int(sys.argv[5])
        t_num = int(sys.argv[6])
        t_ty2 = int(sys.argv[7])
        opr_outer = id_toOpr(t_outer)
        opr_inner = id_toOpr(t_inner)
        writeTitle_outer(opr_inner, opr_outer)
        embed_base_specific_ex(opr_inner, opr_outer, t_num, t_ty2)
        writeResults_outer(opr_inner, opr_outer)

else:
  raise "unsupported"

clean()

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