<jupyter_start><jupyter_text>Analysis notebook for Class Project - Save data in CSV- Plot throughout figure with respect to bandwidth, latency, packet loss<jupyter_code>import os
import glob
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
base_datadir='/home/tkurihana/class/networking/NSD-Project-Rui/tf-benchmark/log'
def log_getter_fn(base_datadir, 
                  dataname, 
                  mtype, batch_sizes, losses, bandwidths, delays):
    """
    data : time, throughput
    """
    datalist = []
    header = ['delay', 'bandwidth', 'packet_loss', 'batch_size', 'throughput']
    for nbatch in batch_sizes:
        for loss in losses:
            for bandwidth in bandwidths:
                for delay in delays:
                    ifile = os.path.join(base_datadir,
                        dataname+'/'+str(mtype)+'_'+str(nbatch)+'-'+str(loss)+'ps-'+str(bandwidth)+'mbit-'+str(delay)+'ms.txt'
                    )
                    tmp_data = np.loadtxt(ifile,delimiter=',')
                    throughput = tmp_data[1]
                    data = np.asarray([int(delay), int(bandwidth), int(loss), int(nbatch), throughput])
                    datalist.append(data)
    array = np.asarray(datalist)
    df = pd.DataFrame(array)
    df.columns = header
    return df
### params 
datanames = ['mnist', 'imagenet']
mtypes = ['mlp', 'mobilenet', 'resnet']
batch_sizes = [32, 128, 1024]
losses = [0, 1, 10]
bandwidths = [1000, 500, 100]
delays = [1, 10, 100,]
mnist_dataset = []
for mtype in mtypes:
    mnist_dataset.append(
        log_getter_fn(
            base_datadir, 'mnist',mtype,batch_sizes, losses, bandwidths, delays
        )               
    )
mnist_dataset[0]
imagenet_dataset = []
for mtype in mtypes:
    imagenet_dataset.append(
        log_getter_fn(
            base_datadir, 'imagenet',mtype,batch_sizes, losses, bandwidths, delays
        )               
    )
imagenet_dataset[0]<jupyter_output><empty_output><jupyter_text>Save csv files<jupyter_code>base_savedir = '/home/tkurihana/class/networking/NSD-Project-Rui/tf-benchmark'
# mnist
for idx, m in enumerate(mtypes):
    mnist_dataset[idx].to_csv(os.path.join(base_savedir+'/mnist_benchmarks' , "tf_mnist_"+str(m)+".csv"))
# imagenet
for idx, m in enumerate(mtypes):
    imagenet_dataset[idx].to_csv(os.path.join(base_savedir+'/imagenet_benchmarks' , "tf_mnist_"+str(m)+".csv"))<jupyter_output><empty_output><jupyter_text>Load csv & VisualizeMemo: Resnet min value gets lower than 1 --> cannot use log y scale<jupyter_code>base_tfdir='/home/tkurihana/class/networking/NSD-Project-Rui/tf-benchmark/'<jupyter_output><empty_output><jupyter_text>- Load MNIST MLP<jupyter_code>data  = pd.read_csv(glob.glob(os.path.join(base_tfdir, 'mnist_benchmarks/*mlp*.csv'))[0], index_col=0)
data<jupyter_output><empty_output><jupyter_text>- search data<jupyter_code>tmp = data.query(" delay == 1 & batch_size == 32")
tmp
tmp = data[(data['delay']==1) & (data['batch_size']==32) & (data['bandwidth']==1000) & (data['packet_loss']==0) ]
tmp
throughput_list = []
for j in [32,128,1024]:
    tmp_list = []
    for i in [1,10,100]:
        _array = data[(data['delay']==i) & (data['batch_size']==j) & (data['bandwidth']==1000) & (data['packet_loss']==0)].values
        tmp_list.append(_array[0,-1])
    throughput_list.append(tmp_list)
throughput_list<jupyter_output><empty_output><jupyter_text>- visualization : Latency for mnist at bandwidth == 1000, packet loss ==0<jupyter_code>plt.figure(figsize=(6,4))
for idx, _th in enumerate(throughput_list):
    x = [i + idx*0.2 for i in range(len(_th))]
    plt.bar(x,_th, width=0.2, label=str(batch_sizes[idx]))
    if idx == 1:
        plt.xticks(x, ['1 ms', '10 ms', '100 ms'],fontsize=14)
plt.yscale('log')
plt.yticks(fontsize=14)
plt.grid(True, axis='y')
plt.legend(fontsize=12)
plt.show()<jupyter_output><empty_output><jupyter_text>Make automatic figure - MLP - Delay - Batch size<jupyter_code>data['throughput'].max()
### delay 
base_savedir = './fig/mnist/mlp/delay'
os.makedirs(base_savedir, exist_ok=True)
for iloss in [0, 1,10]:
    for ibandwidth in [1000, 500, 100]:
        
        # data query
        throughput_list = []
        for ibatch in [32,128,1024]:
            tmp_list = []
            for idelay in [1,10,100]:
                _array = data[(data['delay']==idelay) & (data['batch_size']==ibatch) & (data['bandwidth']==ibandwidth) & (data['packet_loss']==iloss)].values
                tmp_list.append(_array[0,-1])
            throughput_list.append(tmp_list)
            
        # data vis
        fig = plt.figure(figsize=(6,4))
        for idx, _th in enumerate(throughput_list):
            x = [i + idx*0.2 for i in range(len(_th))]
            plt.bar(x,_th, width=0.2, label=str(batch_sizes[idx]))
            if idx == 1:
                plt.xticks(x, ['1 ms', '10 ms', '100 ms'],fontsize=14)
        plt.yscale('log')
        plt.yticks(fontsize=14)
        plt.ylim(1,10**5)
        plt.ylabel("Throughput [Image/sec]", fontsize=14)
        plt.xlabel("Latency", fontsize=14)
        plt.grid(True, axis='y')
        plt.legend(fontsize=12)
        fig.tight_layout()
        plt.savefig(os.path.join(base_savedir, 'fig_delays_bandwidth-'+str(ibandwidth)+'_ps-'+str(iloss)+'.png'))
        plt.close()<jupyter_output><empty_output><jupyter_text>MLP - bandwidth Batch size<jupyter_code>### bandwidth
base_savedir = './fig/mnist/mlp/bandwidth'
os.makedirs(base_savedir, exist_ok=True)
for iloss in [0, 1,10]:
    for idelay in [1, 10, 100]:
        
        # data query
        throughput_list = []
        for ibatch in [32,128,1024]:
            tmp_list = []
            for ibandwidth in [1000, 500, 100]:
                _array = data[(data['delay']==idelay) & (data['batch_size']==ibatch) & (data['bandwidth']==ibandwidth) & (data['packet_loss']==iloss)].values
                tmp_list.append(_array[0,-1])
            throughput_list.append(tmp_list)
            
        # data vis
        fig= plt.figure(figsize=(6,4))
        for idx, _th in enumerate(throughput_list):
            x = [i + idx*0.2 for i in range(len(_th))]
            plt.bar(x,_th, width=0.2, label=str(batch_sizes[idx]))
            if idx == 1:
                plt.xticks(x, ['1000 mbit', '500 mbit', '100 mbit'],fontsize=14)
        plt.yscale('log')
        plt.yticks(fontsize=14)
        plt.ylim(1,10**5)
        plt.ylabel("Throughput [Image/sec]", fontsize=14)
        plt.xlabel("Bandwidth", fontsize=14)
        plt.grid(True, axis='y')
        plt.legend(fontsize=12)
        fig.tight_layout()
        plt.savefig(os.path.join(base_savedir, 'fig_bandwidth_delay-'+str(idelay)+'_ps-'+str(iloss)+'.png'))
        plt.close()<jupyter_output><empty_output><jupyter_text>MLP - packet loss -  Batch size<jupyter_code>### packet loss
base_savedir = './fig/mnist/mlp/packet_loss'
os.makedirs(base_savedir, exist_ok=True)
for ibandwidth in [1000, 500, 100]:
    for idelay in [1, 10, 100]:
        
        # data query
        throughput_list = []
        for ibatch in [32,128,1024]:
            tmp_list = []
            for iloss in [0, 1, 10]:
                _array = data[(data['delay']==idelay) & (data['batch_size']==ibatch) & (data['bandwidth']==ibandwidth) & (data['packet_loss']==iloss)].values
                tmp_list.append(_array[0,-1])
            throughput_list.append(tmp_list)
            
        # data vis
        fig = plt.figure(figsize=(6,4))
        for idx, _th in enumerate(throughput_list):
            x = [i + idx*0.2 for i in range(len(_th))]
            plt.bar(x,_th, width=0.2, label=str(batch_sizes[idx]))
            if idx == 1:
                plt.xticks(x, ['0 %', '1 %', '10 %'],fontsize=14)
        plt.yscale('log')
        plt.yticks(fontsize=14)
        plt.ylim(1,10**5)
        plt.ylabel("Throughput [Image/sec]", fontsize=14)
        plt.xlabel("Packet Loss", fontsize=14)
        plt.grid(True, axis='y')
        plt.legend(fontsize=12)
        fig.tight_layout()
        plt.savefig(os.path.join(base_savedir, 'fig_PacketLoss_delay-'+str(idelay)+'_bandwidth-'+str(ibandwidth)+'.png'))
        plt.close()<jupyter_output><empty_output><jupyter_text>- MNIST Mobilenet<jupyter_code>data  = pd.read_csv(glob.glob(os.path.join(base_tfdir, 'mnist_benchmarks/*mobilenet*.csv'))[0], index_col=0)
data['throughput'].max(), data['throughput'].min()<jupyter_output><empty_output><jupyter_text>Mobilenet - Delay - Batch size<jupyter_code>### delay 
base_savedir = './fig/mnist/mobilenet/delay'
os.makedirs(base_savedir, exist_ok=True)
for iloss in [0, 1,10]:
    for ibandwidth in [1000, 500, 100]:
        
        # data query
        throughput_list = []
        for ibatch in [32,128,1024]:
            tmp_list = []
            for idelay in [1,10,100]:
                _array = data[(data['delay']==idelay) & (data['batch_size']==ibatch) & (data['bandwidth']==ibandwidth) & (data['packet_loss']==iloss)].values
                tmp_list.append(_array[0,-1])
            throughput_list.append(tmp_list)
            
        # data vis
        fig = plt.figure(figsize=(6,4))
        for idx, _th in enumerate(throughput_list):
            x = [i + idx*0.2 for i in range(len(_th))]
            plt.bar(x,_th, width=0.2, label=str(batch_sizes[idx]))
            if idx == 1:
                plt.xticks(x, ['1 ms', '10 ms', '100 ms'],fontsize=14)
        plt.yscale('log')
        plt.yticks(fontsize=14)
        plt.ylim(1,10**5)
        plt.ylabel("Throughput [Image/sec]", fontsize=14)
        plt.xlabel("Latency", fontsize=14)
        plt.grid(True, axis='y')
        plt.legend(fontsize=12)
        fig.tight_layout()
        plt.savefig(os.path.join(base_savedir, 'fig_delays_bandwidth-'+str(ibandwidth)+'_ps-'+str(iloss)+'.png'))
        plt.close()
### bandwidth
base_savedir = './fig/mnist/mobilenet/bandwidth'
os.makedirs(base_savedir, exist_ok=True)
for iloss in [0, 1,10]:
    for idelay in [1, 10, 100]:
        
        # data query
        throughput_list = []
        for ibatch in [32,128,1024]:
            tmp_list = []
            for ibandwidth in [1000, 500, 100]:
                _array = data[(data['delay']==idelay) & (data['batch_size']==ibatch) & (data['bandwidth']==ibandwidth) & (data['packet_loss']==iloss)].values
                tmp_list.append(_array[0,-1])
            throughput_list.append(tmp_list)
            
        # data vis
        fig= plt.figure(figsize=(6,4))
        for idx, _th in enumerate(throughput_list):
            x = [i + idx*0.2 for i in range(len(_th))]
            plt.bar(x,_th, width=0.2, label=str(batch_sizes[idx]))
            if idx == 1:
                plt.xticks(x, ['1000 mbit', '500 mbit', '100 mbit'],fontsize=14)
        plt.yscale('log')
        plt.yticks(fontsize=14)
        plt.ylim(1,10**5)
        plt.ylabel("Throughput [Image/sec]", fontsize=14)
        plt.xlabel("Bandwidth", fontsize=14)
        plt.grid(True, axis='y')
        plt.legend(fontsize=12)
        fig.tight_layout()
        plt.savefig(os.path.join(base_savedir, 'fig_bandwidth_delay-'+str(idelay)+'_ps-'+str(iloss)+'.png'))
        plt.close()
### packet loss
base_savedir = './fig/mnist/mobilenet/packet_loss'
os.makedirs(base_savedir, exist_ok=True)
for ibandwidth in [1000, 500, 100]:
    for idelay in [1, 10, 100]:
        
        # data query
        throughput_list = []
        for ibatch in [32,128,1024]:
            tmp_list = []
            for iloss in [0, 1, 10]:
                _array = data[(data['delay']==idelay) & (data['batch_size']==ibatch) & (data['bandwidth']==ibandwidth) & (data['packet_loss']==iloss)].values
                tmp_list.append(_array[0,-1])
            throughput_list.append(tmp_list)
            
        # data vis
        fig = plt.figure(figsize=(6,4))
        for idx, _th in enumerate(throughput_list):
            x = [i + idx*0.2 for i in range(len(_th))]
            plt.bar(x,_th, width=0.2, label=str(batch_sizes[idx]))
            if idx == 1:
                plt.xticks(x, ['0 %', '1 %', '10 %'],fontsize=14)
        plt.yscale('log')
        plt.yticks(fontsize=14)
        plt.ylim(1,10**5)
        plt.ylabel("Throughput [Image/sec]", fontsize=14)
        plt.xlabel("Packet Loss", fontsize=14)
        plt.grid(True, axis='y')
        plt.legend(fontsize=12)
        fig.tight_layout()
        plt.savefig(os.path.join(base_savedir, 'fig_PacketLoss_delay-'+str(idelay)+'_bandwidth-'+str(ibandwidth)+'.png'))
        plt.close()<jupyter_output><empty_output><jupyter_text>Resnet - mnist<jupyter_code>data  = pd.read_csv(glob.glob(os.path.join(base_tfdir, 'mnist_benchmarks/*resnet*.csv'))[0], index_col=0)
data['throughput'].max(), data['throughput'].min()
### delay 
base_savedir = './fig/mnist/resnet/delay'
os.makedirs(base_savedir, exist_ok=True)
for iloss in [0, 1,10]:
    for ibandwidth in [1000, 500, 100]:
        
        # data query
        throughput_list = []
        for ibatch in [32,128,1024]:
            tmp_list = []
            for idelay in [1,10,100]:
                _array = data[(data['delay']==idelay) & (data['batch_size']==ibatch) & (data['bandwidth']==ibandwidth) & (data['packet_loss']==iloss)].values
                tmp_list.append(_array[0,-1])
            throughput_list.append(tmp_list)
            
        # data vis
        fig = plt.figure(figsize=(6,4))
        for idx, _th in enumerate(throughput_list):
            x = [i + idx*0.2 for i in range(len(_th))]
            plt.bar(x,_th, width=0.2, label=str(batch_sizes[idx]))
            if idx == 1:
                plt.xticks(x, ['1 ms', '10 ms', '100 ms'],fontsize=14)
        #plt.yscale('log')
        plt.yticks(fontsize=14)
        plt.ylim(0,400)
        plt.ylabel("Throughput [Image/sec]", fontsize=14)
        plt.xlabel("Latency", fontsize=14)
        plt.grid(True, axis='y')
        plt.legend(fontsize=12)
        fig.tight_layout()
        plt.savefig(os.path.join(base_savedir, 'fig_delays_bandwidth-'+str(ibandwidth)+'_ps-'+str(iloss)+'.png'))
        plt.close()
### bandwidth
base_savedir = './fig/mnist/resnet/bandwidth'
os.makedirs(base_savedir, exist_ok=True)
for iloss in [0, 1,10]:
    for idelay in [1, 10, 100]:
        
        # data query
        throughput_list = []
        for ibatch in [32,128,1024]:
            tmp_list = []
            for ibandwidth in [1000, 500, 100]:
                _array = data[(data['delay']==idelay) & (data['batch_size']==ibatch) & (data['bandwidth']==ibandwidth) & (data['packet_loss']==iloss)].values
                tmp_list.append(_array[0,-1])
            throughput_list.append(tmp_list)
            
        # data vis
        fig= plt.figure(figsize=(6,4))
        for idx, _th in enumerate(throughput_list):
            x = [i + idx*0.2 for i in range(len(_th))]
            plt.bar(x,_th, width=0.2, label=str(batch_sizes[idx]))
            if idx == 1:
                plt.xticks(x, ['1000 mbit', '500 mbit', '100 mbit'],fontsize=14)
        #plt.yscale('log')
        plt.yticks(fontsize=14)
        #plt.ylim(1,10**5)
        plt.ylim(0,400)
        plt.ylabel("Throughput [Image/sec]", fontsize=14)
        plt.xlabel("Bandwidth", fontsize=14)
        plt.grid(True, axis='y')
        plt.legend(fontsize=12)
        fig.tight_layout()
        plt.savefig(os.path.join(base_savedir, 'fig_bandwidth_delay-'+str(idelay)+'_ps-'+str(iloss)+'.png'))
        plt.close()
### packet loss
base_savedir = './fig/mnist/resnet/packet_loss'
os.makedirs(base_savedir, exist_ok=True)
for ibandwidth in [1000, 500, 100]:
    for idelay in [1, 10, 100]:
        
        # data query
        throughput_list = []
        for ibatch in [32,128,1024]:
            tmp_list = []
            for iloss in [0, 1, 10]:
                _array = data[(data['delay']==idelay) & (data['batch_size']==ibatch) & (data['bandwidth']==ibandwidth) & (data['packet_loss']==iloss)].values
                tmp_list.append(_array[0,-1])
            throughput_list.append(tmp_list)
            
        # data vis
        fig = plt.figure(figsize=(6,4))
        for idx, _th in enumerate(throughput_list):
            x = [i + idx*0.2 for i in range(len(_th))]
            plt.bar(x,_th, width=0.2, label=str(batch_sizes[idx]))
            if idx == 1:
                plt.xticks(x, ['0 %', '1 %', '10 %'],fontsize=14)
        #plt.yscale('log')
        plt.yticks(fontsize=14)
        #plt.ylim(1,10**5)
        plt.ylim(0,400)
        plt.ylabel("Throughput [Image/sec]", fontsize=14)
        plt.xlabel("Packet Loss", fontsize=14)
        plt.grid(True, axis='y')
        plt.legend(fontsize=12)
        fig.tight_layout()
        plt.savefig(os.path.join(base_savedir, 'fig_PacketLoss_delay-'+str(idelay)+'_bandwidth-'+str(ibandwidth)+'.png'))
        plt.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16305580423754104, 'fraction_numerical': 0.03772008355714712, 'mean_word_length': 2.704620826884811, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '264770', 'license': 'MIT', 'n_tokens_mistral': 6432, 'n_tokens_neox': 5907, 'n_words': 1012, 'path': 'tf-benchmark/100_TF-Benchmark_Figures.ipynb', 'repo_name': 'csruiliu/NSD-Project', 'size': '16755'}