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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4523 - (download) (as text) (annotate)
Tue Sep 6 04:07:12 2016 UTC (2 years, 11 months ago) by cchiw
File size: 12248 byte(s)
updated backwards motion
import sys
import re
import os
import time

from obj_apply import *
from obj_ex import  *
from obj_field import *
from obj_counter import *
from obj_frame import  *
from obj_counter import *

from iter import *
from fold import *
# unu save -f nrrd -e ascii -i out.nrrd | less
##################################################################################################
# possible commands
# unu grid -i inputfile.nrrd | unu save -f text
# ^ where all the points are.

##############################################################################################
def cmd(layer, testing_frame, cnt, shift, args):
    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==0): #run all the programs
        embed2_iter_inner(testing_frame, cnt)
        writeCumulative(cnt)

    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, testing_frame, cnt)
                writeResults_inner(opr_inner, testing_frame, cnt)
            writeCumulative(cnt)
        elif (args==1):
            # iterate over single layer
            t_inner= int(sys.argv[shift+1])
            opr_inner = id_toOpr(t_inner)
            writeTitle_inner(opr_inner)
            single_all_ops(opr_inner, testing_frame, cnt)
            writeResults_inner(opr_inner, testing_frame, cnt)
        elif (args==2):
            t_inner= int(sys.argv[shift+1])
            opr_inner = id_toOpr(t_inner)
            t_num= int(sys.argv[shift+2])
            single_specific_ex(opr_inner,t_num, testing_frame, cnt)
            writeResults_inner(opr_inner, testing_frame, cnt)
    elif (layer==2):
        if(args==0):
            #run all the programs
            embed2_iter_inner(testing_frame, cnt)
            writeCumulative(cnt)
        elif(args==1):
            # iterate over double layer with unary operator
            t_inner = int(sys.argv[shift+1])
            opr_inner = id_toOpr(t_inner)
            ex = oprToEx(opr_inner, testing_frame, cnt)
            embed_base_iter_outer(ex, opr_inner, testing_frame, cnt)
            writeCumulative(cnt)
        elif(args==5):
            t_outer = int(sys.argv[shift+1])
            opr_outer = id_toOpr(t_outer)
            writeTitle_outer2(opr_outer)
            embed2_iter_inner_gotouter(opr_outer, testing_frame, cnt)
            writeCumulative(cnt)
        elif (args==2):
            t_inner = int(sys.argv[shift+1])
            t_outer = int(sys.argv[shift+2])#outer  operator
            opr_outer = id_toOpr(t_outer)
            opr_inner = id_toOpr(t_inner)
            writeTitle_outer(opr_inner, opr_outer)
            ex = oprToEx(opr_inner, testing_frame, cnt)
            embed_base_iter_ty2(ex, opr_inner, opr_outer, testing_frame, cnt)
            writeResults_outer(opr_inner, opr_outer, testing_frame, cnt)
        elif (args==20):
            t_inner = int(sys.argv[shift+1])
            t_num = int(sys.argv[shift+2])#outer binary operator
            opr_inner = id_toOpr(t_inner)
            writeTitle_inner(opr_inner)
            embed_base_iter_outer2(opr_inner, t_num, testing_frame, cnt)
            writeResults_inner(opr_inner, testing_frame, cnt)
        elif(args==3):
            #  run a specific iterate over double layer with unary operator
            t_inner = int(sys.argv[shift+1])
            t_outer= int(sys.argv[shift+2])
            t_num = int(sys.argv[shift+3])
            t_ty2 = None
            opr_outer = id_toOpr(t_outer)
            opr_inner = id_toOpr(t_inner)
            writeTitle_outer(opr_inner, opr_outer)
            ex = oprToEx(opr_inner, testing_frame, cnt)
            embed_base_iter_ty2_wihty1(ex, opr_inner, opr_outer, t_num, testing_frame, cnt)
            writeResults_outer(opr_inner, opr_outer, testing_frame, cnt)
        elif(args==4):
            #  run a specific iterate over double layer with unary operator
            t_inner = int(sys.argv[shift+1])
            t_outer= int(sys.argv[shift+2])
            t_num = int(sys.argv[shift+3])
            t_ty2 = int(sys.argv[shift+4])
            opr_outer = id_toOpr(t_outer)
            opr_inner = id_toOpr(t_inner)
            writeTitle_outer(opr_inner, opr_outer)
            # get example
            ex = oprToEx(opr_inner, testing_frame, cnt)
            embed_base_specific_ex(ex, opr_inner, opr_outer, t_num, t_ty2, testing_frame, cnt)
            writeResults_outer(opr_inner, opr_outer, testing_frame, cnt)

    else:
      raise "unsupported"

#ends with Clean up
def clean():
    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")

# iterating over the different types
def main_Standard():
    print "standard"
    n_frame =0# int(sys.argv[1])
    args = int(sys.argv[2])
    shift = 2 # how many commands used so far
    # get testing framework
    testing_frame = get_testing_frame(n_frame)
    # get counter
    cnt = get_counter()
    # writing heading based on framework
    write_heading(testing_frame)
    # constants (decides layer of testing)
    layer = 2
    # layer, and shift from constants (decides layer of testing)
    start_standard = time.time()
    #choose testing range based on commands
    cmd(layer, testing_frame, cnt, shift, args)
    clean()
    end_standard = time.time()
    tt_standard  = " time all _standard "+str(end_standard  - start_standard )
    writeall(tt_standard )
    print (tt_standard )

# single(inner->outer) iter ->shape
def main5():
    #n_frame = int(sys.argv[1])
    #args = int(sys.argv[2])
    #shift = 2 # how many commands used so far
    n_frame = 0
    shift = 1

    # get testing framework
    testing_frame = get_testing_frame(n_frame)
    # get counter
    cnt = get_counter()
    # writing heading based on framework
    #write_heading(testing_frame)

    #choose testing range based on commands
    t_inner = int(sys.argv[shift+1])
    t_outer = int(sys.argv[shift+2])#outer  operator
    opr_outer = id_toOpr(t_outer)
    opr_inner = id_toOpr(t_inner)
    writeTitle_outer(opr_inner, opr_outer)
    
    #choose testing range based on commands
    pick_inner(opr_inner, opr_outer, testing_frame, cnt)
    clean()

# single(inner->outer) iter ->shape
def main_backwards():
    #n_frame = int(sys.argv[1])
    #args = int(sys.argv[2])
    #shift = 2 # how many commands used so far
    n_frame = 0
    shift = 1
    
    # get testing framework
    testing_frame = get_testing_frame(n_frame)
    # get counter
    cnt = get_counter()
    # writing heading based on framework
    #write_heading(testing_frame)
    
    #choose testing range based on commands
    #t_inner = int(sys.argv[shift+1])
    #t_outer = int(sys.argv[shift+2])#outer  operator
    #opr_outer = id_toOpr(t_outer)
    #opr_inner = id_toOpr(t_inner)
    #writeTitle_outer(opr_inner, opr_outer)
    #choose testing range based on commands
    n = len(op_all)
    startall = time.time()
    for t_inner in range(n):
        startx = time.time()
        opr_inner = id_toOpr(t_inner)
        for  t_outer in range(n):
            starty = time.time()
            opr_outer = id_toOpr(t_outer)
            counter.zero_locals(cnt)
            counter.zero_total(cnt)
            writeTitle_outer(opr_inner, opr_outer)
            pick_backwards(opr_inner, opr_outer, testing_frame, cnt)
            clean()
            endy = time.time()
            tt = "done inner: "+opr_inner.name+" outer: "+opr_outer.name+" time: "+str(endy - starty)
            tmp = "time: all-snapshot"+str(endy - startall)
            writeall(tt+tmp)
            print (tt+tmp)
        endx = time.time()
        tx = "done inner: "+opr_inner.name+" time: "+str(endx - startx)
        writeall(tx)
        print (tx)
        tsnap = "time: all-snapshot"+str(endx - startall)
        writeall(tsnap)
        print (tsnap)
    endall = time.time()
    tall = "time: all"+str(endall - startall)
    writeall(tall)
    print (tall)

# inner->outer->shape
def main_iter2():
    #n_frame = int(sys.argv[1])
    #args = int(sys.argv[2])
    #shift = 2 # how many commands used so far
    n_frame = 0
    # get testing framework
    testing_frame = get_testing_frame(n_frame)
    # get counter
    cnt = get_counter()
    # writing heading based on framework
    write_heading(testing_frame)
    
    #choose testing range based on commands
    n = len(op_all)
    startall = time.time()
    for t_inner in range(n):
        startx = time.time()
        opr_inner = id_toOpr(t_inner)
        for  t_outer in range(n):
            starty = time.time()
            opr_outer = id_toOpr(t_outer)
            counter.zero_locals(cnt)
            counter.zero_total(cnt)
            writeTitle_outer(opr_inner, opr_outer)
            #choose testing range based on commands
            pick_inner(opr_inner, opr_outer, testing_frame, cnt)
            clean()
            endy = time.time()
            tt = "done inner: "+opr_inner.name+" outer: "+opr_outer.name+" time: "+str(endy - starty)
            tmp = "time: all-snapshot"+str(endy - startall)
            writeall(tt+tmp)
            print (tt+tmp)

        endx = time.time()
        tx = "done inner: "+opr_inner.name+" time: "+str(endx - startx)
        writeall(tx)
        print (tx)
        tsnap = "time: all-snapshot"+str(endx - startall)
        writeall(tsnap)
        print (tsnap)

    endall = time.time()
    tall = "time: all"+str(endall - startall)
    writeall(tall)
    print (tall)


# shape->inner->outer
def main_iter1():
    #n_frame = int(sys.argv[1])
    #args = int(sys.argv[2])
    #shift = 2 # how many commands used so far
    n_frame = 0
    # get testing framework
    testing_frame = get_testing_frame(n_frame)
    # get counter
    cnt = get_counter()
    # writing heading based on framework
    write_heading(testing_frame)
    startall = time.time()
    #choose testing range based on commands
    pick_shape(testing_frame, cnt)
    endall = time.time()
    tall = "time: all"+str(endall - startall)
    writeall(tall)
    print (tall)



start = time.time()
x = int(sys.argv[1])
name = ""
if(x==0):
    main_Standard()
    name ="previous"
elif(x==1):
    main_iter1()
    name= " shape->inner->outer"
elif(x==2):
    # inner->outer->shape
    main_iter2()
    name = "inner->outer->shape"
elif(x==5):
    # backwards
    # specifiy two arguments
    main5()
elif(x==6):
    main_backwards()
    name = "backwards"
end = time.time()
t = "  time:"+str(end - start)
writeall(t)
print (t)

e= "\ntime for: "+str(x)+" "+name+"-"+t
print(e)
f = open("time.txt", 'a+')
f.write(e)
f.close()

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