def run_exp_without_base_util_gen():
    if PARAMS.GENERATE_NEW_TC:
        # generate taskset and write to file as pickle object
        print "Generating Taskset and Saving to Pickle file..."
        all_taskset = tgen.generate_all_tasksets()
        hf.write_object_to_file(all_taskset, PARAMS.TASKET_FILENAME)
    else:
        print "Loading Taskset from Pickle file..."
        all_taskset = hf.load_object_from_file(PARAMS.TASKET_FILENAME)

    eh.run_sched_exp(all_taskset)
示例#2
0
def plot_single_node():

    # change font to Arial
    plt.rcParams["font.family"] = "Arial"
    plt.rcParams['font.size'] = 15
    plt.rcParams['legend.fontsize'] = 12
    plt.rcParams['axes.titlesize'] = 15
    plt.rcParams['ytick.labelsize'] = 10
    plt.rcParams['xtick.labelsize'] = 10

    # filename = "../" + PARAMS.EXP_SINGLE_NODE_FILENAME
    filename = "exp_single_node.pickle.gzip"
    result = hf.load_object_from_file(filename)

    all_delay_dict = result.all_delay_dict

    # i = 5
    # j = 4
    # k = 2
    #
    # print(all_delay_dict[i][j][k])

    # n_flow_each_prio = 2
    # tag_flow_prio = 4
    # dl = []
    #
    # for count in range(result.N_SINGLE_NODE_EXP_SAMPLE_RUN):
    #     dl.append(all_delay_dict[n_flow_each_prio][tag_flow_prio][count])
    #
    # print("Trace:", dl)

    mean_delay = defaultdict(lambda: defaultdict(dict))
    std_delay = defaultdict(lambda: defaultdict(dict))

    for n_flow_each_prio in result.N_FLOW_EACH_PRIO_LIST:
        for tag_flow_prio in result.TAG_FLOW_PRIO_LIST:
            dl = []
            for count in range(result.N_SINGLE_NODE_EXP_SAMPLE_RUN):
                dl.append(
                    all_delay_dict[n_flow_each_prio][tag_flow_prio][count])
                # dl.append(all_delay_dict[n_flow_each_prio][tag_flow_prio][count]*1000.00)  # change to microsecond

            print("Trace:", dl)
            # mean_delay[n_flow_each_prio][tag_flow_prio] = np.mean(dl)  # millisecond
            # std_delay[n_flow_each_prio][tag_flow_prio] = np.std(dl)

            mean_delay[n_flow_each_prio][tag_flow_prio] = np.mean(dl)
            std_delay[n_flow_each_prio][tag_flow_prio] = np.std(dl)
            #

            # mean_delay[n_flow_each_prio][tag_flow_prio] = max(dl)  # millisecond
            # std_delay[n_flow_each_prio][tag_flow_prio] = np.std(dl)
            mean_delay[n_flow_each_prio][tag_flow_prio] = np.percentile(
                dl, 99)  # millisecond
            # std_delay[n_flow_each_prio][tag_flow_prio] = st.t.interval(0.95, len(dl) - 1, loc=np.mean(dl), scale=st.sem(dl))
            std_delay[n_flow_each_prio][tag_flow_prio] = st.sem(dl)
            # std_delay[n_flow_each_prio][tag_flow_prio] = np.var(dl)

    print(mean_delay)

    print("mean:", mean_delay[5][4])
    print("std:", std_delay[5][4])

    plt.subplot(2, 1, 1)

    y_pos = np.arange(len(result.N_FLOW_EACH_PRIO_LIST))
    y_delta = 0.25
    bar_width = 0.25

    tag_flow_prio = result.TAG_FLOW_PRIO_LIST[0]
    mean_delay_list = get_delay(result, mean_delay, tag_flow_prio)
    std_delay_list = get_delay(result, std_delay, tag_flow_prio)
    print(mean_delay_list)
    print(std_delay_list)
    plt.bar(y_pos,
            mean_delay_list,
            bar_width,
            yerr=std_delay_list,
            color=['gray'],
            edgecolor='k',
            alpha=0.9,
            label="High Priority")

    tag_flow_prio = result.TAG_FLOW_PRIO_LIST[1]
    mean_delay_list = get_delay(result, mean_delay, tag_flow_prio)
    std_delay_list = get_delay(result, std_delay, tag_flow_prio)
    print(mean_delay_list)
    print(std_delay_list)
    plt.bar(y_pos + y_delta,
            mean_delay_list,
            bar_width,
            yerr=std_delay_list,
            color=['gray'],
            alpha=0.6,
            edgecolor='k',
            label="Medium Priority",
            error_kw=dict(ecolor='black',
                          alpha=0.5,
                          lw=2,
                          capsize=5,
                          capthick=2))

    tag_flow_prio = result.TAG_FLOW_PRIO_LIST[2]
    mean_delay_list = get_delay(result, mean_delay, tag_flow_prio)
    std_delay_list = get_delay(result, std_delay, tag_flow_prio)
    print(mean_delay_list)
    print(std_delay_list)

    plt.bar(y_pos + 2 * y_delta,
            mean_delay_list,
            bar_width,
            yerr=std_delay_list,
            color=['gray'],
            alpha=0.3,
            edgecolor='k',
            label="Low Priority",
            error_kw=dict(ecolor='black',
                          alpha=0.5,
                          lw=2,
                          capsize=5,
                          capthick=2))

    plt.xticks(y_pos + bar_width, result.N_FLOW_EACH_PRIO_LIST)
    # label = [ r'3 $\times$ {} = {}'.format(result.N_FLOW_EACH_PRIO_LIST[i], 3*result.N_FLOW_EACH_PRIO_LIST[i]) for i in range(len(result.N_FLOW_EACH_PRIO_LIST))]
    label = [
        3 * result.N_FLOW_EACH_PRIO_LIST[i]
        for i in range(len(result.N_FLOW_EACH_PRIO_LIST))
    ]
    ax = plt.gca()  # grab the current axis
    ax.set_xticklabels(label)

    plt.xlabel('Total Number of Flows')
    plt.ylabel('Observed Delay (ms)')
    plt.legend()

    # plt.tight_layout()

    plt.savefig("delay_validation.pdf", pad_inches=0.1, bbox_inches='tight')
    plt.show()
# __author__ = "Monowar Hasan"
# __email__ = "*****@*****.**"

import helper_functions as hf
import taskset_generator as tgen
import experiment_handler as eh
from config import *

if __name__ == "__main__":

    if PARAMS.GENERATE_NEW_TC:
        # generate taskset and write to file as pickle object
        print "Generating Taskset and Saving to Pickle file..."
        # all_taskset = tgen.generate_all_tasksets()
        all_taskset = tgen.generate_all_tasksets_base_util()
        hf.write_object_to_file(all_taskset, PARAMS.TASKET_FILENAME)
    else:
        print "Loading Taskset from Pickle file..."
        all_taskset = hf.load_object_from_file(PARAMS.TASKET_FILENAME)

    # all_taskset = None

    # eh.dummy_run_period_selection_exp()

    # eh.do_run_sched_exp_all_global(tcconfig=None)

    eh.run_sched_exp_all_global_fftmax(all_taskset)

    print "Script finished"
示例#4
0
        plt.xticks(np.arange(0, PARAMS.CORE_LIST[corelist_index] + 0.5, 0.5))

    # plt.legend(loc='upper left')
    plt.tight_layout()

    plt.savefig(filename, pad_inches=0.05, bbox_inches='tight')
    plt.cla()
    # plt.show()


if __name__ == '__main__':
    print "hello"
    print PARAMS.EXP_RES_FILENAME_PROP

    # load result from file
    output_prop = HF.load_object_from_file("../" +
                                           PARAMS.EXP_RES_FILENAME_PROP)
    output_ref = HF.load_object_from_file("../" + PARAMS.EXP_RES_FILENAME_REF)
    # output_ref = HF.load_object_from_file("../" + PARAMS.EXP_RES_FILENAME_BF)

    # change font to Arial
    # change font to Arial
    plt.rcParams["font.family"] = "Arial"
    plt.rcParams['font.size'] = 15
    plt.rcParams['legend.fontsize'] = 13
    plt.rcParams['axes.titlesize'] = 15
    plt.rcParams['ytick.labelsize'] = 10
    plt.rcParams['xtick.labelsize'] = 10

    plt.hold(False)

    # for 2 cores

if __name__ == '__main__':

    n_core = 2

    # decide load from file or generate new taskset
    if PARAMS.GENERATE_NEW_TC_ESEARCH:
        # generate taskset and write to file as pickle object
        print "Generating Taskset and Saving to Pickle file..."
        tc, util_list = TGEN.generate_exsearch_tasksets(n_core)
        HF.write_object_to_file(tc, PARAMS.ESEARCH_TASKET_FILENAME)
        HF.write_object_to_file(util_list, PARAMS.ESEARCH_UTIL_FILENAME)
    else:
        print "Loading Taskset from Pickle file..."
        tc = HF.load_object_from_file(PARAMS.ESEARCH_TASKET_FILENAME)
        util_list = HF.write_object_to_file(PARAMS.ESEARCH_UTIL_FILENAME)

    xi_esearch, eta_esearch = run_experimet(tc, util_list,
                                            PARAMS.EXPERIMENT_NAME_ESEARCH)
    xi_prop, eta_prop = run_experimet(tc, util_list,
                                      PARAMS.EXPERIMENT_NAME_PROP)

    # print "Ex"
    # print xi_esearch
    #
    # print "prop"
    # print xi_prop

    result = ER.EXSearchResult(util_list=util_list,
                               xi_prop=xi_prop,
示例#6
0
# __email__ = "*****@*****.**"

from __future__ import division
from config import *
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import numpy as np
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import helper_functions as HF
import task_generator as TGEN

if __name__ == '__main__':
    # load result from file
    result = HF.load_object_from_file("../" + PARAMS.EXP_ESEARCH_FILENAME)
    # result_prop = result.xi_prop
    # result_esearch = result.xi_esearch

    result_prop = result.eta_prop
    result_esearch = result.eta_esearch

    util_prop = [x[0] for x in result_prop]
    xi_prop = [x[1] for x in result_prop]

    util_esearch = [x[0] for x in result_esearch]
    xi_esearch = [x[1] for x in result_esearch]

    # p = e - k*e
    # k = (e-p)/e
示例#7
0
                             xi_list_per_core, xi_std_list_per_core,
                             rt_sched_list_per_core, se_sched_list_per_core)
    return output


if __name__ == "__main__":

    # decide load from file or generate new taskset
    if PARAMS.GENERATE_NEW_TC:
        # generate taskset and write to file as pickle object
        print "Generating Taskset and Saving to Pickle file..."
        tc = TGEN.generate_all_tasksets()
        HF.write_object_to_file(tc, PARAMS.TASKET_FILENAME)
    else:
        print "Loading Taskset from Pickle file..."
        tc = HF.load_object_from_file(PARAMS.TASKET_FILENAME)

    # output_prop = run_experiment(tc, PARAMS.EXPERIMENT_NAME_PROP)
    #
    # # saving results to pickle file
    # print PARAMS.EXPERIMENT_NAME_PROP, "--> Saving result to file..."
    # HF.write_object_to_file(output_prop, PARAMS.EXP_RES_FILENAME_PROP)

    output_bf = run_experiment(tc, PARAMS.EXPERIMENT_NAME_BF)

    # saving results to pickle file
    print PARAMS.EXPERIMENT_NAME_REF, "--> Saving result to file..."
    HF.write_object_to_file(output_bf, PARAMS.EXP_RES_FILENAME_BF)

    print "Script finished!!"
示例#8
0
    plt.xlim([0, 50000])

    plt.legend(loc='lower right')
    plt.tight_layout()

    plt.savefig(filename, pad_inches=0.05, bbox_inches='tight')

    # plt.show()
    plt.cla()


if __name__ == '__main__':

    print "hello"
    output_ds = HF.load_object_from_file("../" + PARAMS.EXP_CS_FILENAME)

    # change font to Arial
    plt.rcParams["font.family"] = "Arial"
    plt.rcParams['font.size'] = 15
    plt.rcParams['legend.fontsize'] = 13
    plt.rcParams['axes.titlesize'] = 15
    plt.rcParams['ytick.labelsize'] = 10
    plt.rcParams['xtick.labelsize'] = 10

    # draw_plot(core_index=0, output_ds=output_ds, filename="cs_2.pdf")
    # draw_plot(core_index=1, output_ds=output_ds, filename="cs_4.pdf")
    # draw_plot(core_index=2, output_ds=output_ds, filename="cs_8.pdf")

    draw_plot(core_index=1, output_ds=output_ds, filename="cs_4_v2.pdf")
示例#9
0
def plot_3d_bar(in_filename, out_filename, nw_diameter, fig_num):
    # change font to Arial
    plt.rcParams["font.family"] = "Arial"
    plt.rcParams['font.size'] = 15
    plt.rcParams['legend.fontsize'] = 13
    plt.rcParams['axes.titlesize'] = 15
    plt.rcParams['ytick.labelsize'] = 10
    plt.rcParams['xtick.labelsize'] = 10

    result = hf.load_object_from_file(in_filename)

    NUMBER_OF_SWITCHES = result.NUMBER_OF_SWITCHES
    NUM_HOST_PER_SWITCH = result.NUM_HOST_PER_SWITCH
    N_PRIO_LEVEL = result.N_PRIO_LEVEL
    N_FLOW_EACH_PRIO_LIST = result.N_FLOW_EACH_PRIO_LIST
    BASE_E2E_BETA_LIST = result.BASE_E2E_BETA_LIST
    SCHED_EXP_EACH_TRIAL_COUNT = result.SCHED_EXP_EACH_TRIAL_COUNT
    sched_count_dict = result.sched_count_dict

    BASE_E2E_BETA_LIST.reverse()  # for test

    data = []
    for n in N_FLOW_EACH_PRIO_LIST:
        val = []
        for d in BASE_E2E_BETA_LIST:
            val.append(
                (sched_count_dict[n][d] / SCHED_EXP_EACH_TRIAL_COUNT) * 100)

        data.append(val)

    data = np.array(data)

    print(data)

    column_names = [
        int(BASE_E2E_BETA_LIST[i] * 1000 * nw_diameter)
        for i in range(len(BASE_E2E_BETA_LIST))
    ]  #convert to microsecond
    row_names = [
        N_FLOW_EACH_PRIO_LIST[i] * N_PRIO_LEVEL
        for i in range(len(N_FLOW_EACH_PRIO_LIST))
    ]

    print("NFLOW EACH PRIo", N_FLOW_EACH_PRIO_LIST)
    print("N_PRIO_LEV", N_PRIO_LEVEL)
    print("Row name:", row_names)

    fig = plt.figure(fig_num)
    ax = Axes3D(fig)

    # following code is taken from
    # https://goo.gl/u7gAqR

    lx = len(data[0])  # Work out matrix dimensions
    ly = len(data[:, 0])
    xpos = np.arange(0, lx, 1)  # Set up a mesh of positions
    ypos = np.arange(0, ly, 1)
    xpos, ypos = np.meshgrid(xpos + 0.25, ypos + 0.25)

    xpos = xpos.flatten()  # Convert positions to 1D array
    ypos = ypos.flatten()
    zpos = np.zeros(lx * ly)

    dx = 0.5 * np.ones_like(zpos)
    dy = dx.copy()
    dz = data.flatten()

    cs = plt.cm.gray(data.flatten() / float(data.max()))

    ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color=cs, edgecolor='k', alpha=0.7)

    ax.w_xaxis.set_ticklabels(column_names)
    ax.w_yaxis.set_ticklabels(row_names)
    ax.set_xlabel('End To End Deadline')
    ax.set_ylabel('Total Number of Flows')
    ax.set_zlabel('Acceptance Ratio (%)')

    ax.set_zlim(0, 100)

    # ax.view_init(azim=50, elev=15)
    ax.view_init(azim=61, elev=27)

    ticksx = np.arange(0.5, len(column_names), 1)
    plt.xticks(ticksx, column_names)

    ticksy = np.arange(0.6, len(row_names), 1)
    plt.yticks(ticksy, row_names)

    # plt.tight_layout()

    plt.savefig(out_filename, pad_inches=-0.1, bbox_inches='tight')
    plt.show()
示例#10
0
def plot_3d_surface(in_filename, out_filename, nw_diameter, fig_num):

    # change font to Arial
    plt.rcParams["font.family"] = "Arial"
    plt.rcParams['font.size'] = 15
    plt.rcParams['legend.fontsize'] = 13
    plt.rcParams['axes.titlesize'] = 15
    plt.rcParams['ytick.labelsize'] = 10
    plt.rcParams['xtick.labelsize'] = 10

    result = hf.load_object_from_file(in_filename)

    NUMBER_OF_SWITCHES = result.NUMBER_OF_SWITCHES
    NUM_HOST_PER_SWITCH = result.NUM_HOST_PER_SWITCH
    N_PRIO_LEVEL = result.N_PRIO_LEVEL
    N_FLOW_EACH_PRIO_LIST = result.N_FLOW_EACH_PRIO_LIST
    BASE_E2E_BETA_LIST = result.BASE_E2E_BETA_LIST
    SCHED_EXP_EACH_TRIAL_COUNT = result.SCHED_EXP_EACH_TRIAL_COUNT
    sched_count_dict = result.sched_count_dict

    BASE_E2E_BETA_LIST.reverse()  # for better view

    N_FLOW = [
        N_FLOW_EACH_PRIO_LIST[i] * N_PRIO_LEVEL
        for i in range(len(N_FLOW_EACH_PRIO_LIST))
    ]

    column_names = [
        int(BASE_E2E_BETA_LIST[i] * 1000 * nw_diameter)
        for i in range(len(BASE_E2E_BETA_LIST))
    ]  #convert to microsecond
    # column_names = [r'{}$\times\delta$'.format(int(BASE_E2E_BETA_LIST[i] * 1000)) for i in
    #                 range(len(BASE_E2E_BETA_LIST))]  # convert to microsecond
    # row_names = [N_FLOW_EACH_PRIO_LIST[i] * N_PRIO_LEVEL for i in range(len(N_FLOW_EACH_PRIO_LIST))]
    row_names = N_FLOW

    column_names.reverse()

    fig = plt.figure(fig_num)
    ax = Axes3D(fig)

    X, Y = np.meshgrid(N_FLOW, BASE_E2E_BETA_LIST)

    # Z = np.zeros((len(N_FLOW_EACH_PRIO_LIST), (len(BASE_E2E_BETA_LIST)))  # initialize

    Z = np.zeros(
        (len(BASE_E2E_BETA_LIST), len(N_FLOW_EACH_PRIO_LIST)))  # initialize

    for row in range(len(BASE_E2E_BETA_LIST)):
        for col in range(len(N_FLOW_EACH_PRIO_LIST)):
            vv = sched_count_dict[N_FLOW_EACH_PRIO_LIST[col]][
                BASE_E2E_BETA_LIST[row]]
            Z[row][col] = (vv / SCHED_EXP_EACH_TRIAL_COUNT) * 100  # in percent

    print("X:", X)
    print("Y:", Y)
    print("Z:", Z)
    ax.plot_surface(X,
                    Y,
                    Z,
                    linewidth=1.0,
                    cmap=plt.cm.gray,
                    rstride=1,
                    cstride=1,
                    alpha=0.7,
                    edgecolors='k')
    # ax.plot_surface(X, Y, Z)

    ax.set_ylabel('End To End Deadline ($\mu$s)')
    ax.set_xlabel('Total Number of Flows')
    ax.set_zlabel('Acceptance Ratio (%)')

    ax.set_zlim(0, 100)
    # ax.set_xlim(1, max(N_FLOW)+ 2)

    ax.view_init(azim=-17, elev=25)
    ax.set_xticklabels(row_names)
    ax.set_yticklabels(column_names)

    # this two comment out if we don't want to show diameter
    # plt.yticks(rotation=20)
    # ax.yaxis.labelpad = 10

    ax.tick_params(direction='out', pad=1)

    # plt.tight_layout()

    plt.savefig(out_filename, pad_inches=0.1, bbox_inches='tight')
    plt.show()