<jupyter_start><jupyter_text>Ускорение и закон Амдаля<jupyter_code>for myproc in df_all.myproc.unique():
    for n in df_all.n.unique():
        for p in df_all.p.unique():
            df_all.loc[(df_all.p==p)&(df_all.n==n),'mean_time'] = df_all[(df_all.p==p)&(df_all.n==n)]['time'].mean()
# TODO: should be always named as `df`
df = df_all[df_all.myproc == 0]
for n in df.n.unique():
    for p in df.p.unique():
        p_1_time = (df[(df.n==n)&(df.p==1)]['mean_time']).iloc[0]
        own_time = df[(df.p==p)&(df.n==n)]['mean_time'].iloc[0]
        df.loc[(df.p==p)&(df.n==n),'accel'] = p_1_time/own_time
df['eff'] = df['accel']/df['p']
def amdal(p, f):
    return 1/(f + (1-f)/p)
def plot_save_graphs(x_label, y_label, fixed='p'):
    
    def _appr_accel(n, p):
        return 6*n/(6*n/p + 6 + np.log2(p))
    
    def _appr_eff(n, p):
        return _appr_accel(n, p)/p
    
    def _appr_amdal(n, p, accels):
        if len(np.array(p).reshape(-1)) == 1:
            p = np.array([p]*len(accels))
        elif len(np.array(accels).reshape(-1)) == 1:
            accels = np.array([accels]*len(p))
        from scipy.optimize import curve_fit
        popt, pcov = curve_fit(amdal, p, accels)
        return amdal(p, popt[0])
    
    def _routine(data, x_label, y_label, fixed_value):
        x_data, y_data = data[x_label], data[y_label]
        result = dict()
        result['real'] = (x_data, y_data)
        p, n = (fixed_value, x_data)
        if x_label == 'p':
            p, n = (n, p)
        # Approximation
        if y_label == 'accel':
            # NOTE: approximation for acceleration
            result['appr_accel'] = (x_data, _appr_accel(n, p))
            if x_label == 'p':
                result['appr_amdal'] = (x_data, _appr_amdal(n, p, y_data))
                #plt.scatter(x_data, _appr_amdal(n, p, y_data), color='green', label='amdal')
        elif y_label == 'eff':
            #plt.scatter(x_data, _appr_eff(n, p), color='red', label='theor')
            result['appr_eff'] = (x_data, _appr_eff(n, p))
        #plt.xlabel(x_label)
        #plt.ylabel(y_label)
        #plt.legend()
        #plt.title(f'{y_label}, {fixed}={fixed_value}')
        #plt.savefig(f'{y_label}_{fixed}_{fixed_value}', dpi=120)
        #plt.show()
        return result
    if fixed == 'n':
        for n in df.n.unique():
            data = df[df.n==n]
            return _routine(data, x_label, y_label, n)
    elif fixed == 'p':
        for p in df.p.unique():
            data = df[df.p==p]
            return _routine(data, x_label, y_label, p)
    else:
        raise ValueError('Not implemented')
#plot_save_graphs('p', 'accel', fixed='n')['appr_eff'][0]
#plot_save_graphs('n', 'accel', fixed='p')
plot_save_graphs('p', 'eff', fixed='n')['appr_eff']
#plot_save_graphs('n', 'eff', fixed='p')<jupyter_output><empty_output><jupyter_text>Распределение времени работы каждого процесса<jupyter_code>for n in df_all.n.unique():
    for p in df_all.p.unique():
        for myproc in df_all.myproc.unique():
            own_time = df_all.loc[(df_all.p == p)&(df_all.n == n)&(df_all.myproc == myproc),'time']
            if len(own_time) == 0:
                continue
            own_time = own_time.iloc[0]
            p0_time = df_all.loc[(df_all.p == p)&(df_all.n == n)&(df_all.myproc == 0),'time'].iloc[0]
            df_all.loc[(df_all.p == p)&(df_all.n == n)&(df_all.myproc == myproc),'delay'] = p0_time - own_time
for p in df_all.myproc.unique():
    if p == 0:
        continue
    plt.xlabel('delay time, s')
    plt.ylabel('total number')
    plt.title(f'Histgram')
    plt.hist(df_all[df_all.myproc == p]['delay'], alpha=0.6, label=f'p={p}')
    plt.legend()
plt.savefig('delay_histogram.png', dpi=120)<jupyter_output><empty_output><jupyter_text>Время задержки - примерно 0.1 секунда.<jupyter_code>plt.xlabel('p')
plt.ylabel('time, s')
plt.scatter(df_all['p'].unique(), [df_all.loc[df_all.p == p,'time'].mean() for p in df_all.p.unique()])
plt.title('Time distribution')
plt.grid()<jupyter_output><empty_output><jupyter_text>Сравнение для двух способов разбиения<jupyter_code>df_circle = pd.read_csv('results_circle.csv', sep=';')
df_parts = pd.read_csv('results.csv', sep=';')
df_circle.head()
df_delta = df_circle.copy()
for myproc in df_circle.myproc.unique():
    for p in df_circle.p.unique():
        for n in df_circle.n.unique():
            df_circle_time = df_circle.loc[(df_circle.n == n)&(df_circle.p == p)&(df_circle.myproc == myproc),'time'].mean()
            df_parts_time = df_parts.loc[(df_parts.n == n)&(df_parts.p == p)&(df_parts.myproc == myproc),'time'].mean()
            df_delta.loc[(df_delta.n == n)&(df_delta.p == p)&(df_delta.myproc == myproc),'delta'] = df_circle_time - df_parts_time
print('From circle to parts')
print('time increased: {} times'.format(np.count_nonzero(df_delta.delta >= 0)))
print('time decreased: {} times'.format(np.count_nonzero(df_delta.delta < 0)))<jupyter_output>From circle to parts
time increased: 1310 times
time decreased: 594 times
{'fraction_non_alphanumeric': 0.1847934544003193, 'fraction_numerical': 0.008780682498503292, 'mean_word_length': 3.1627906976744184, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '326032', 'license': 'MIT', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1992, 'n_words': 346, 'path': 'hw1/pi/analyzer_nographs.ipynb', 'repo_name': 'alekseik1/md_bash_course', 'size': '5011'}