Ejemplo n.º 1
0
def generateGraph_for_all(valueList, xName, yName, benchmark_name, graph_title="pareto comparison for", name = "various_inputs", graph_dim = "2d", graph_type ="Q_vs_E", n_graphs="one"):
    assert(1==0, "this graph generation tool can not be used b/c it uses meani")

    name_counter = 0 
    fig = plt.figure(figsize=plt.figaspect(0.5)) 
    #--- sanity check 
    if (graph_dim == "3d"): 
        if (graph_type == "Q_E_product"): 
            print "ERROR: graph_teyp and graph_dim are incompatible"
            sys.exit()
        ax = fig.gca(projection='3d')
        #ax = fig.add_subplot(111, projection='3d') 
        ax.set_xlabel('Quality')
        ax.set_ylabel('mean')
        ax.set_zlabel('Energy')
    else: 
        fig, ax = plt.subplots()
        if (graph_type == "Q_E_product"):
            plt.ylabel("Q_E_product")
            plt.xlabel("mean")
        else: 
            #plt.xscale('log')
            plt.xlabel("mean")
            plt.ylabel("Quality")
#            plt.ylabel(yName)
#            plt.xlabel(xName)
    
    #here
    #----comment if not proving th s4 pont
    symbolsToChooseFrom = ['*', 'x', "o", "+","^", '1', '2', "3"] 
    color =['g', 'y', 'r', 'm']
    
    lOf_run_input_list = input_list.lOf_run_input_list
    number_of_inputs_used = len(lOf_run_input_list)
    input_results = map(list, [[]]*number_of_inputs_used) 
    base_dir = "/home/local/bulkhead/behzad/usr/local/apx_tool_chain/inputPics/"
    counter = 0
    energy_list_to_be_drawn = []
    quality_list_to_be_drawn = []
    std_list_to_be_drawn = []
    image_list_to_be_drawn = [] 
    z_vals = [] 
    

    for val in valueList:
        input_results = map(list, [[]]*number_of_inputs_used) 
        zipped = zip(*val[:-1])  
        for el in zipped:
            input_results[el[2]].append(el)
        for index,res in enumerate(input_results):
            """ 
            if (counter > 50 ):
                break
            """ 
            print counter 
            if len(res) > 0:
                image_addr =  base_dir+lOf_run_input_list[index][0] + ".ppm"
                mR, mG, mB, stdR, stdG, stdB = cluster_images.calc_image_mean_std(image_addr)
                if (int(np.mean([mR,mG,mB]))) in z_vals:
                    continue
                el = map(lambda x: list(x), zip(*res))
                quality_values_shifted = map(lambda x: x+1, el[0]) 
                #--here 
                #---un comment the next line whenever you want to provide the resuls t professor, 
                

                #--- sort based on the quality
                Q = quality_values_shifted
                E = el[1]
#                Q_index_sorted = sorted(enumerate(Q), key=lambda x: x[1])
#                index_of_Q_sorted = map(lambda y: y[0], Q_index_sorted)
                
                E_index_sorted = sorted(enumerate(E), key=lambda x: x[1])
                index_of_E_sorted = map(lambda y: y[0], E_index_sorted)
                
#                
#                Q_sorted = [Q[i] for i in index_of_Q_sorted]
#                E_sorted = [E[i] for i in index_of_Q_sorted]

                Q_sorted = [Q[i] for i in index_of_E_sorted]
                E_sorted = [E[i] for i in index_of_E_sorted]

                quality_list_to_be_drawn.append(Q_sorted)
                energy_list_to_be_drawn.append(E_sorted)
                
#                std_list_to_be_drawn.append([int(np.mean([stdR,stdG,stdB]))]*len(E_sorted))
#                z_vals.append( int(np.mean([stdR,stdG,stdB])))

                std_list_to_be_drawn.append([int(np.mean([mR,mG,mB]))]*len(E_sorted))
                image_list_to_be_drawn.append([lOf_run_input_list[index][0]]*len(E_sorted))

                z_vals.append( int(np.mean([mR,mG,mB])))

                counter +=1
        
        reminder(True,"the following lines which creates a new image every len(symbolsToChooseFrom) should be commented if we use any flag but various_inputs")
        
        
        #--sorting the data. This is necessary for wire frame 
        zvals_index_sorted = sorted(enumerate(z_vals), key=lambda x: x[1])
        index_of_zvals_sorted = map(lambda y: y[0], zvals_index_sorted)
        quality_list_sorted_based_on_z = [quality_list_to_be_drawn[i] for i in index_of_zvals_sorted]                
        std_list_sorted_based_on_z = [std_list_to_be_drawn[i] for i in index_of_zvals_sorted]                
        energy_list_sorted_based_on_z = [energy_list_to_be_drawn[i] for i in index_of_zvals_sorted]                
        
        image_list_sorted_based_on_z = [image_list_to_be_drawn[i] for i in index_of_zvals_sorted]                
        
        #--- generate a spectrum of colors  
        #colors = ['b', 'g'] 
        n_energy_levels = 4
        #colors = gen_color_spec.gen_color(len(quality_list_sorted_based_on_z[0]), 'seismic') 
        colors = gen_color_spec.gen_color(n_energy_levels, 'seismic') 
        
                     
        print "here is the list of (images in the z_order, quality in z order, energy in z order)" 
        print zip([i[0] for i in image_list_sorted_based_on_z], [i[0] for i in quality_list_sorted_based_on_z], [i[0] for i in  std_list_sorted_based_on_z])
        print zip([i[0] for i in image_list_sorted_based_on_z], [i[1] for i in quality_list_sorted_based_on_z], [i[0] for i in  std_list_sorted_based_on_z])

        for x in range(len(energy_list_sorted_based_on_z[0][:n_energy_levels])):
        #for x in range(len(quality_list_sorted_based_on_z)):
            #my_label =  'mean:' + str(int(std_list_sorted_based_on_z[x][0]))
            my_label =  'En:' + str(float(energy_list_sorted_based_on_z[0][x]))
            if (graph_dim == "3d"): 
                """ the following is for plotting a wire_frame or surface plot
        surf = ax.plot_surface(np.asarray(energy_list_sorted_based_on_z), np.asarray(quality_list_sorted_based_on_z), np.asarray(std_list_sorted_based_on_z), rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=0, antialiased=False)
        fig.colorbar(surf, shrink=0.5, aspect=5)
        #ax.plot_wireframe(np.asarray(quality_list_sorted_based_on_z), np.asarray(std_list_sorted_based_on_z), np.asarray(energy_list_sorted_based_on_z))
        """ 
                ax.scatter(quality_list_sorted_based_on_z[x], std_list_sorted_based_on_z[x] , energy_list_sorted_based_on_z[x], c=colors[x], marker = symbolsToChooseFrom[x%len(symbolsToChooseFrom)], depthshade=False)
            else:
                #my_label +=  lOf_run_input_list[index][0] 
                #--- note: get rid of linestyle='None' if you want a line through the graph 
                #line_style = 'None'
                line_style = '-'
                if (graph_type == "Q_E_product") :
                    Q_E_list = [a*b for a,b in zip(quality_list_sorted_based_on_z[x],energy_list_sorted_based_on_z[x])]
                    ax.plot(std_list_sorted_based_on_z[x], Q_E_list, marker = symbolsToChooseFrom[x%len(symbolsToChooseFrom)], c= colors[x], label=my_label, linestyle=line_style)
                else:
                    #ax.plot(quality_list_sorted_based_on_z[x], energy_list_sorted_based_on_z[x], marker = symbolsToChooseFrom[x%len(symbolsToChooseFrom)], c= colors[x], label=my_label, linestyle=line_style)
                    quality_as_w_diff_mean = map(lambda y: y[x], quality_list_sorted_based_on_z)


                    #--- if no quality value under 150, it is possibly the acc\
                    #    setUP. The accurate set up make seeing other setUPs difficult
                    """ 
                    found_one = False 
                    for el in quality_as_w_diff_mean:
                        if el < 150:
                            found_one = True
                            break
                    if not(found_one):
                        continue
                    """

                    l_mean = map(lambda y: y[x], std_list_sorted_based_on_z)
                    
                    ax.plot(l_mean, quality_as_w_diff_mean, marker = symbolsToChooseFrom[x%len(symbolsToChooseFrom)], c= colors[x], label=my_label)
                            #, linestyle=line_style)
                if (n_graphs  == "multiple"):
                    finish_up_making_graph(ax, name, graph_title, benchmark_name, name_counter) 
                    fig = plt.figure(figsize=plt.figaspect(0.5)) 
                    #--- sanity check 
                    if (graph_dim == "3d"): 
                        ax = fig.gca(projection='3d')
                        #ax = fig.add_subplot(111, projection='3d') 
                        ax.set_xlabel('1/Q')
                        ax.set_ylabel('mean')
                        ax.set_zlabel('Energy')
                    else: 
                        fig, ax = plt.subplots()
                        if (graph_type == "Q_E_product"):
                            plt.ylabel("Q_E_product")
                            plt.xlabel("mean")
                        else: 
                            #plt.xscale('log')
                            plt.xlabel("mean")
                            plt.ylabel("Quality")
#                            plt.ylabel(yName)
#                            plt.xlabel(xName)

                    
                    name_counter += 1
        
        if (n_graphs  == "one"):
            finish_up_making_graph(ax, name, graph_title, benchmark_name,  0) 
Ejemplo n.º 2
0
def main():

    os.system("rm *.png")
    #--- parameters to set
    clk_period = .7  #clk period that we ran the DC with
    num_of_bins = 10  #number of bins for the histogram
    lower_bound = 28  #lower bound for the output bit you want to make histogram for
    upper_bound = 32  #upper bound for the output bit you want to make histogram for
    histogram_type = "2d"  #2d
    #3d histogram will be generated regardless
    output_bit_to_make_histogram_for = 31  #only for 2d histogram

    print "clk_period:" + str(clk_period)
    print "number_of_bins for histogram:" + str(num_of_bins)
    #--- parse the results and collect slacks
    data = sourceFileParse("int_add_acc_ff_0_timing1.rpt", clk_period)

    #sorting for printing purposes
    my_list = data.keys()
    my_list.sort(key=lambda x: x[0])
    my_list.sort(key=lambda x: x[1])
    for key in my_list:
        print str("pin_tuple:") + str(key) + " ---- slack_values" + str(
            data[key])

    #--- preparing to draw a histogram
    output_slack_dic = {}
    for i in range(0, 32):
        output_slack_dic[i] = []

    for key in data.keys():
        output_slack_dic[key[1]].append(data[key])

    #flattening
    for key in output_slack_dic.keys():
        output_slack_dic[key] = list(
            itertools.chain.from_iterable(output_slack_dic[key]))

    #--- draw a 2d histogram
    if (histogram_type == "2d"):
        plt.hist(output_slack_dic[output_bit_to_make_histogram_for],
                 30,
                 range=[0, clk_period])
        print output_slack_dic[output_bit_to_make_histogram_for]
        plt.title("slack Histogram for " +
                  str(output_bit_to_make_histogram_for) + "thbit")
        plt.xlabel("Value")
        plt.ylabel("Frequency")
        pylab.savefig(
            str(output_bit_to_make_histogram_for) +
            "th_bit_slack_histogram.png"
        )  #saving the figure generated by generateGraph
        #plt.show()

    #--- draw a 3d histogram
    fig = plt.figure()
    ax1 = fig.add_subplot(111, projection='3d')
    x = []  #list of output bits (stamped to the number of slack value)
    y = []  #list of slack value
    for key in output_slack_dic.keys():
        x += len(output_slack_dic[key]) * [key]
        y += output_slack_dic[key]
    xedges = []
    for i in range(0, 33):
        xedges.append(i)
    yedges = []
    for el in range(num_of_bins):
        yedges.append((el + 1) * float(clk_period) / float(num_of_bins))
    H, xedges, yedges = np.histogram2d(x, y, bins=(xedges, yedges))

    new_yedges = []
    for i in range(0, len(xedges[:-1])):
        for el in yedges[:-1]:
            new_yedges.append(float(el))

    new_xedges = []
    for j in range(0, len(xedges[:-1])):
        for i in range(0, len(yedges[:-1])):
            new_xedges.append(j)

    dx = np.ones(len(new_xedges))
    dy = np.ones(len(new_xedges)) * .1

    colors = gen_color_spec.gen_color(33, 'prism')
    for x in range(lower_bound, upper_bound):
        ax1.bar3d([x] * len(yedges[:-1]),
                  yedges[:-1],
                  np.zeros(len(yedges[:-1])),
                  dx,
                  dy,
                  H[x],
                  alpha=.5,
                  color=colors[x])

        print "x and y for hisogram:"
        print "y:" + str(np.array(yedges))
        print "x " + str(xedges)
        print "histogram:"
        print H
        """ 
        H_list = (H.tolist())
        H_list_flattened = list(itertools.chain.from_iterable(H_list))
        dz = H_list_flattened
        zpos =[0]*len(H_list_flattened)
        ax1.bar3d(new_xedges, new_yedges, zpos, dx, dy, dz, alpha =.1, color='#00ceaa')
        """
        pylab.savefig("3d_slack_histogram.png"
                      )  #saving the figure generated by generateGraph
Ejemplo n.º 3
0
def generateGraph_for_all_simplified(valueList,xlabel, ylabel, benchmark_name, ax, fig,  graph_title="pareto comparison for", name = "various_inputs", post_pone_saving_graph = False, use_prev_ax_fig = False, n_graphs="one", valueList_promised=[]):

    name_counter = 0 
    #fig = plt.figure(figsize=plt.figaspect(0.5)) 
    #--- sanity check 
    if not(use_prev_ax_fig):
        fig, ax = plt.subplots()

    plt.autoscale(enable=True, axis='both', tight=True)
    """ 
    if (graph_type == "Q_E_product"):
        plt.ylabel("Q_E_product")
        plt.xlabel("mean")
    else: 
        #plt.xscale('log')
        plt.xlabel("mean")
        plt.ylabel("Energy")
#            plt.ylabel(yName)
#            plt.xlabel(xName)
    """
    #here
    #----comment if not proving th s4 pont
    symbolsToChooseFrom = ['*', 'x', "o", "+","^", '1', '2', "3"] 
    color =['g', 'y', 'r', 'm']
    quality_list_sorted_based_on_z, std_list_sorted_based_on_z, energy_list_sorted_based_on_z = sort_values(valueList)
    quality_list_promised_sorted_based_on_z, std_list_promised_sorted_based_on_z, energy_list_promised_sorted_based_on_z = sort_values(valueList_promised)


    """ 
    lOf_run_input_list = input_list.lOf_run_input_list
    number_of_inputs_used = len(lOf_run_input_list)
    input_results = map(list, [[]]*number_of_inputs_used) 
    base_dir = "/home/local/bulkhead/behzad/usr/local/apx_tool_chain/inputPics/"
    counter = 0
    energy_list_to_be_drawn = []
    setup_list_to_be_drawn = [] 
    quality_list_to_be_drawn = []
    std_list_to_be_drawn = []
    image_list_to_be_drawn = [] 
    z_vals = [] 

    for val in valueList:
        input_results = map(list, [[]]*number_of_inputs_used) 
        zipped = zip(*val[:-1])  
        for el in zipped:
            input_results[el[2]].append(el)
        for index,res in enumerate(input_results):
            print counter 
            if len(res) > 0:
                image_addr =  base_dir+lOf_run_input_list[index][0] + ".ppm"
                mR, mG, mB, stdR, stdG, stdB = cluster_images.calc_image_mean_std(image_addr)
                if (int(np.mean([mR,mG,mB]))) in z_vals:
                    continue
                el = map(lambda x: list(x), zip(*res))
                quality_values_shifted = map(lambda x: x+1, el[0]) 
                
                print "mean of image : " + (lOf_run_input_list[index][0]) + " is: " +  str(np.mean([mR,mG,mB]))
                #--- sort based on the quality
                Q = quality_values_shifted
                E = el[1]
                SetUps =  el[2]
                E_index_sorted = sorted(enumerate(E), key=lambda x: x[1])
                index_of_E_sorted = map(lambda y: y[0], E_index_sorted)
                Q_sorted = [Q[i] for i in index_of_E_sorted]
                E_sorted = [E[i] for i in index_of_E_sorted]
                SetUp_sorted = [SetUps[i] for i in index_of_E_sorted]
                quality_list_to_be_drawn.append(Q_sorted)
                energy_list_to_be_drawn.append(E_sorted)
                setup_list_to_be_drawn.append(SetUp_sorted)
                std_list_to_be_drawn.append([int(np.mean([mR,mG,mB]))]*len(E_sorted))
                image_list_to_be_drawn.append([lOf_run_input_list[index][0]]*len(E_sorted))
                z_vals.append( int(np.mean([mR,mG,mB])))
                counter +=1
        
        reminder(True,"the following lines which creates a new image every len(symbolsToChooseFrom) should be commented if we use any flag but various_inputs")
        
        #--sorting the data. This is necessary for wire frame 
        zvals_index_sorted = sorted(enumerate(z_vals), key=lambda x: x[1])
        index_of_zvals_sorted = map(lambda y: y[0], zvals_index_sorted)
        quality_list_sorted_based_on_z = [quality_list_to_be_drawn[i] for i in index_of_zvals_sorted]                
        std_list_sorted_based_on_z = [std_list_to_be_drawn[i] for i in index_of_zvals_sorted]                
        energy_list_sorted_based_on_z = [energy_list_to_be_drawn[i] for i in index_of_zvals_sorted]                
        
        image_list_sorted_based_on_z = [image_list_to_be_drawn[i] for i in index_of_zvals_sorted]                
        
        SetUp_list_sorted_based_on_z = [setup_list_to_be_drawn[i] for i in index_of_zvals_sorted]                
        print quality_list_sorted_based_on_z
        print std_list_sorted_based_on_z
        print energy_list_sorted_based_on_z
        
    """        
    if (post_pone_saving_graph): 
        line_style = ':'
    else:
        line_style = '-'
    #--- generate a spectrum of colors  
    #colors = ['b', 'g'] 
    
    plt.xscale('log')
    if (name == "same_Q_vs_input"):
        plt.xlabel("mean")
        plt.ylabel("Energy")
        Qs, Es, stds, QSs = adjust.adjust_vals_2(quality_list_sorted_based_on_z, energy_list_sorted_based_on_z, std_list_sorted_based_on_z)
        second_axis = Es; 
        third_axis = QSs; 
        third_axis_name = "quality" 
        
        #---limiting
        #third_axis= QSs[:10]
        n_lines = len(third_axis)
        colors = gen_color_spec.gen_color(max(n_lines,2), 'seismic')
        #---limiting 
        
        #--- printing the the Qstates (Q attempted) and the Q found
        for input_index in range(len(Qs)): 
            print "true Qs for input with mean:" + str(stds[input_index]) + "is:"
            for x in range(len(third_axis)):
                print "Q state:" + str(third_axis[x]) + "  found Q:" + str(Qs[input_index][x]) + "En is: " + str(Es[input_index][x]) 

        for x in range(len(third_axis)):
            my_label =  third_axis_name +": " + str(float(third_axis[x]))
            second_axis_as_w_diff_mean = map(lambda y: y[x], second_axis)
            l_mean = map(lambda y: y[x], stds)
            ax.plot(l_mean, second_axis_as_w_diff_mean, marker = symbolsToChooseFrom[x%len(symbolsToChooseFrom)], c= colors[x], label=my_label, linestyle=line_style)
        #finish_up_making_graph(ax, graph_title, graph_title, benchmark_name,  0) 
    elif (name == "same_E_vs_input"):
         plt.xlabel("mean")
         plt.ylabel("quality")
         sys.stdout.flush()  
         third_axis= energy_list_sorted_based_on_z[0]; 
         third_axis_name = "energy" 
         second_axis = quality_list_sorted_based_on_z; 
         n_lines = len(third_axis)
         colors = gen_color_spec.gen_color(n_lines, 'seismic') 
         for x in range(len(third_axis)):
             #--- limiting
#                 if x > 10:
#                     break;
             my_label =  third_axis_name +": " + str(float(third_axis[x]))
             second_axis_as_w_diff_mean = map(lambda y: y[x], second_axis)
             l_mean = map(lambda y: y[x], std_list_sorted_based_on_z)
             print "asdf" + str(second_axis_as_w_diff_mean )
             ax.plot(l_mean, second_axis_as_w_diff_mean, marker = symbolsToChooseFrom[x%len(symbolsToChooseFrom)], c= colors[x], label=my_label, linestyle=line_style)
         #finish_up_making_graph(ax, graph_title, graph_title, benchmark_name,  0) 
    elif(name == "E_vs_Q_adjusted"): 
        plt.xlabel("Quality")
        plt.ylabel("Energy")
        Qs, Es, stds, QSs = adjust.adjust_vals_2(quality_list_sorted_based_on_z, energy_list_sorted_based_on_z, std_list_sorted_based_on_z)
        second_axis = Es; 
        third_axis = std_list_sorted_based_on_z; 
        third_axis_name = "input" 
        n_lines = len(std_list_sorted_based_on_z)
        colors = gen_color_spec.gen_color(n_lines, 'seismic') 
        for x in range(len(third_axis)):
            my_label =  third_axis_name +": " + str(float(third_axis[x][0]))
            #if (third_axis[x][0] == 97): 
            ax.plot(QSs, Es[x], marker = symbolsToChooseFrom[x%len(symbolsToChooseFrom)], c= colors[x], label=my_label, linestyle=line_style)
    elif (name == "E_vs_Q"):
        #---line_style = ''  uncomment for all_points
        plt.xlabel("Quality")
        plt.ylabel("Energy")
        third_axis = std_list_sorted_based_on_z; 
        third_axis_name = "input" 
        n_lines = len(std_list_sorted_based_on_z)
        colors = gen_color_spec.gen_color(n_lines, 'seismic') 
        if (graph_title == "E_vs_Q_all_points"): 
            line_style = "None" #for no lines
        for x in range(len(third_axis)):
            my_label =  third_axis_name +": " + str(float(third_axis[x][0]))
            ax.plot(quality_list_sorted_based_on_z[x],
                        energy_list_sorted_based_on_z[x], marker =
                        symbolsToChooseFrom[x%len(symbolsToChooseFrom)], c=
                        colors[x], label=my_label, linestyle=line_style)
            if (graph_title == "E_vs_Q_all_points"): 
                #.n  the counter would be an incremented version of the input
                #value  n.    
                finish_up_making_graph(ax, graph_title, graph_title,
                        benchmark_name, x+1) 
                fig, ax = plt.subplots()
                plt.xscale('log')
                plt.xlabel("Quality")
                plt.ylabel("Energy")
     



    elif (name == "Qstd_vs_E_imposed"):
        plt.ylabel("Quality_std")
        plt.xlabel("Energy")
        n_lines = 1
        colors = gen_color_spec.gen_color(n_lines, 'seismic') 
        my_label =  "nolabel"
        Q_diff = [] 
        for E_index in range(len(energy_list_sorted_based_on_z[0])):
            all_Qs_as_w_index = map(lambda x: x[E_index], quality_list_sorted_based_on_z)
            Q_diff.append(numpy.std(all_Qs_as_w_index))
        ax.plot(energy_list_sorted_based_on_z[0], Q_diff, marker = symbolsToChooseFrom[0%len(symbolsToChooseFrom)], c= colors[0], label=my_label, linestyle=line_style)
    elif (name == "Qmean_normalized_to_Q_promissed"):
        
        plt.ylabel("Quality_mean_normalized_to_Q_promised")
        plt.xlabel("Energy")
        n_lines = 1
        colors = gen_color_spec.gen_color(max(n_lines,2), 'seismic') 
        Q_diff_1 = [] 
        Q_diff_2 = [] 
        for E_index in range(len(energy_list_sorted_based_on_z[0])):
            all_Qs_as_w_index = map(lambda x: x[E_index], quality_list_sorted_based_on_z)
            print "all_Qs" + str(all_Qs_as_w_index) 
            Q_diff_1.append(numpy.mean(all_Qs_as_w_index))
            print "quality_promiseed" + str(quality_list_promised_sorted_based_on_z[0]) 
            imposed_vs_got_diff =  map(operator.sub,  [quality_list_promised_sorted_based_on_z[0][E_index]]*len(all_Qs_as_w_index), all_Qs_as_w_index)
            Q_diff_2.append(numpy.mean(imposed_vs_got_diff))
        print "Q_diff_2)" + str(Q_diff_2) 
        #ax.plot(energy_list_sorted_based_on_z[0], Q_diff_1, marker = symbolsToChooseFrom[0%len(symbolsToChooseFrom)], c= colors[0], label="Q_mean", linestyle=line_style)
        ax.plot(energy_list_sorted_based_on_z[0], Q_diff_2, marker = symbolsToChooseFrom[0%len(symbolsToChooseFrom)], c= colors[1], label="Q_mean_"+"normalized", linestyle=line_style)
    elif (name == "Q_satisfaction_success_rate"):
        plt.ylabel("Q_satisfaction_success_rate")
        plt.xlabel("Energy")
        n_lines = 1
        colors = gen_color_spec.gen_color(max(n_lines,2), 'seismic') 
        my_label =  "nolabel"
        Q_diff_2 = [] 
        for E_index in range(len(energy_list_sorted_based_on_z[0])):
            all_Qs_as_w_index = map(lambda x: x[E_index], quality_list_sorted_based_on_z)
            imposed_vs_got_diff =  map(operator.sub, all_Qs_as_w_index, [quality_list_promised_sorted_based_on_z[0][E_index]]*len(all_Qs_as_w_index))
            print "sub_is2" + str(imposed_vs_got_diff)
            success_rate =  float(len(filter(lambda x: x >= 000, imposed_vs_got_diff)))/float(len(imposed_vs_got_diff))
            Q_diff_2.append(success_rate)
      
        ax.get_yaxis().get_major_formatter().set_useOffset(False)
        ax.plot(energy_list_sorted_based_on_z[0], Q_diff_2, marker = symbolsToChooseFrom[0%len(symbolsToChooseFrom)], c= colors[1], label="Q_satisfaction_success_rate", linestyle=line_style)

    
    else:
        print "this name : " + name + " is not defined" 
        sys.exit()

    if not(post_pone_saving_graph): 
        finish_up_making_graph(ax, graph_title, graph_title, benchmark_name,  0) 
    return ax, fig
Ejemplo n.º 4
0
def main():

    os.system("rm *.png")
    #--- parameters to set
    #result_type = "slack"
    result_type = "delay"

    clk_period = .55  #clk period that we ran the DC with
    num_of_bins = 10  #number of bins for the histogram
    lower_bound = 28  #lower bound for the bit you want to make histogram for
    upper_bound = 32  #upper bound for the bit you want to make histogram for
    histogram_type = "2d"  #2d
    #3d histogram will be generated regardless

    histogram_var = "input"  #if input, slack of ass/w  input pins are shown
    #histogram_type = "ouput"
    bit_to_make_histogram_for = 0  #only for 2d histogram

    print "clk_period:" + str(clk_period)
    print "number_of_bins for histogram:" + str(num_of_bins)
    data_2 = {}
    #--- parse the results and collect slacks
    #data = sourceFileParse("int_add_acc_ff_0_timing1.rpt", clk_period)
    #file_to_parse =  "unconfig_int_add_32Bit_timing.rpt"
    file_to_parse = "config_int_add_inMux_truncation_16_timing.rpt"
    print colored("ensure clk_period validity" + str(clk_period), 'blue')
    print colored("ensure parsed timing file " + file_to_parse, "blue")
    data = sourceFileParse(file_to_parse, clk_period)
    if (result_type == "delay"):
        for el in data.keys():
            temporary_list = data[el]
            temporary_list_2 = []
            for value in temporary_list:
                temporary_list_2.append(clk_period - value)
            data[el] = temporary_list_2
    """ 
    for el in data.keys():
        print data[el]
        print data_2[el]
        sys.exit()
    """

    #sorting for printing purposes
    my_list = data.keys()
    my_list.sort(key=lambda x: x[0])
    my_list.sort(key=lambda x: x[1])
    for key in my_list:
        print str("pin_tuple:") + str(
            key) + " ---- " + result_type + "_values" + str(data[key])

    #--- preparing to draw a histogram
    result_dic = {}
    for i in range(0, 32):
        result_dic[i] = []

    for key in data.keys():
        if histogram_var == "input":
            result_dic[key[0]].append(data[key])
        elif histogram_var == "output":
            result_dic[key[1]].append(data[key])
        else:
            print "This histogram_var not defined"
            sys.exit()

    ##--- flattening
    for key in result_dic.keys():
        result_dic[key] = list(itertools.chain.from_iterable(result_dic[key]))

    #--- draw a 2d histogram of
    #--- the folowing is if we want to have a cumulitive histogram
    all_results = []
    for i in range(0, 32):  #which bits to show histogram for
        all_results += result_dic[i]
    print all_results

    if (histogram_type == "2d"):
        #        plt.hist(result_dic[bit_to_make_histogram_for], 30,
        #                range=[0, clk_period])
        plt.hist(all_results, 30, range=[0, clk_period])
        #

        print result_dic[bit_to_make_histogram_for]
        plt.title(result_type + " Histogram Associated With the " +
                  str(bit_to_make_histogram_for) +
                  "th bit (and lower) of the " + histogram_var)
        plt.xlabel(result_type + "Value")
        plt.ylabel("Frequency")
        pylab.savefig(
            result_type + "_histogram_" + histogram_var +
            str(bit_to_make_histogram_for) +
            "th_bit.png")  #saving the figure generated by generateGraph
        #plt.show()

    #--- draw a 3d histogram
    fig = plt.figure()
    ax1 = fig.add_subplot(111, projection='3d')
    x = []  #list of bits (stamped to the number of result value)
    y = []  #list of result value
    for key in result_dic.keys():
        x += len(result_dic[key]) * [key]
        y += result_dic[key]
    xedges = []
    for i in range(0, 33):
        xedges.append(i)
    yedges = []
    for el in range(num_of_bins):
        yedges.append((el + 1) * float(clk_period) / float(num_of_bins))
    H, xedges, yedges = np.histogram2d(x, y, bins=(xedges, yedges))

    new_yedges = []
    for i in range(0, len(xedges[:-1])):
        for el in yedges[:-1]:
            new_yedges.append(float(el))

    new_xedges = []
    for j in range(0, len(xedges[:-1])):
        for i in range(0, len(yedges[:-1])):
            new_xedges.append(j)

    dx = np.ones(len(new_xedges))
    dy = np.ones(len(new_xedges)) * .1

    colors = gen_color_spec.gen_color(33, 'prism')
    for x in range(lower_bound, upper_bound):
        ax1.bar3d([x] * len(yedges[:-1]),
                  yedges[:-1],
                  np.zeros(len(yedges[:-1])),
                  dx,
                  dy,
                  H[x],
                  alpha=.5,
                  color=colors[x])

        print "x and y for hisogram:"
        print "y:" + str(np.array(yedges))
        print "x " + str(xedges)
        print "histogram:"
        print H
        """ 
        H_list = (H.tolist())
        H_list_flattened = list(itertools.chain.from_iterable(H_list))
        dz = H_list_flattened
        zpos =[0]*len(H_list_flattened)
        ax1.bar3d(new_xedges, new_yedges, zpos, dx, dy, dz, alpha =.1, color='#00ceaa')
        """
        pylab.savefig(
            "3d_" + result_type +
            "_histogram.png")  #saving the figure generated by generateGraph