Skip to content
Snippets Groups Projects
Commit be842b56 authored by Maël Madon's avatar Maël Madon
Browse files

graph fluid residual

parent 97a2b015
Branches
Tags
No related merge requests found
%% Cell type:markdown id:sustained-helena tags:
 
# Analyse the data from the first campaign
 
In this notebook we analyse the results generated by launching the first experimental campaign `campaign1.py`.
 
## Initializing the environment
 
%% Cell type:code id:yellow-parking tags:
 
``` python
import pandas as pd, json, numpy as np
import os, random
from scripts.util import *
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams["figure.figsize"] = [15, 5]
 
OUT_DIR = f"{ROOT_DIR}/out"
nb_exp = 105
 
# the beginning and end of the demand response window in these expe
start_dr_h = 24 + 16
start_dr = start_dr_h * 3600
win = [1, 4]
end_dr_h = [24 + 17, 24 + 20]
end_dr = [t * 3600 for t in end_dr_h]
 
bvr_ord = {"replay_user_rigid":'0', "dm_user_renonce":'1', "dm_user_delay":'2',
"dm_user_degrad":'3', "dm_user_reconfig":'4'}
bvr_name = ["renounce", "delay", "degrad", "reconfig"]
bvr_orig_name = ["dm_user_renonce", "dm_user_delay", "dm_user_degrad", "dm_user_reconfig"]
```
 
%% Cell type:code id:51bac175 tags:
 
``` python
# Check if all XP succeded
for xp in range(nb_exp):
behavior, window = "replay_user_rigid", 1
expe_dir = f"{OUT_DIR}/expe{xp}/replay_user_rigid_window1"
if not os.path.exists(expe_dir):
print(f"{expe_dir} does not exist")
 
for window in [1, 4]:
for behavior in ["dm_user_reconfig", "dm_user_degrad", "dm_user_renonce", "dm_user_delay"]:
expe_dir = f"{OUT_DIR}/expe{xp}/{behavior}_window{window}"
if not os.path.exists(expe_dir):
print(f"{expe_dir} does not exist")
```
 
%% Cell type:markdown id:b20d17c8 tags:
 
## Look at one specific expe
 
%% Cell type:code id:impressed-disclosure tags:
 
``` python
# Visualize results
EXPE_DIR = f'{OUT_DIR}/expe0/replay_user_rigid_window1'
plot_load_and_details(EXPE_DIR)
```
 
%% Output
 
/home/mmadon/demand-response-user/scripts/util.py:93: UserWarning: Creating legend with loc="best" can be slow with large amounts of data.
fig.savefig(expe_file + '_viz.png')
/nix/store/8nqifk7a8fq7cb4i9rhhs86bn7aqmmrs-python3.8-ipython-7.21.0/lib/python3.8/site-packages/IPython/core/pylabtools.py:132: UserWarning: Creating legend with loc="best" can be slow with large amounts of data.
fig.canvas.print_figure(bytes_io, **kw)
 
 
%% Cell type:code id:d9066775 tags:
 
``` python
# begin, end = 24 * 3600, 48 * 3600
begin, end = (24 + 16) * 3600, (72) * 3600
 
js = JobSetMulticore.from_csv(f"{OUT_DIR}/expe0/replay_user_rigid_window1/_jobs.csv")
print(js.mean_utilisation(begin, end))
```
 
%% Output
 
778.6927430556945
 
%% Cell type:markdown id:attractive-inspection tags:
 
## Compute row summary all expes
We open all the experiment outputs, compute raw metrics such as energy in window or slowdown / waiting time, and save this as a csv file. Also compute these metrics for each experiments and each user behavior relatively to the baseline behavior.
 
%% Cell type:code id:assumed-saver tags:
 
``` python
def metrics(exp_num, behavior, window, window_size=None):
"""Returns a dictionnary of metrics for the given expe.
Param window_size in case we want to compute metrics for a window
size different than the file name."""
 
expe_dir = f"{OUT_DIR}/expe{exp_num}/{behavior}_window{window}"
 
if window_size != None:
window = window_size
 
dm_window = [start_dr, (int) (start_dr + window*3600)]
# Observed window for the scheduling metrics:
[inf, sup] = observed_window = [start_dr, 72*3600] # From 16:00 on day2 to 24:00 on day3
data = pd.read_csv(f"{expe_dir}/_jobs.csv", index_col="job_id", dtype={'profile': 'str'})
data_in_window = data[(data.submission_time
>= inf) & (data.submission_time <= sup)]
 
out = {}
out['XP'] = exp_num
out['dir'] = expe_dir
out['behavior'] = behavior
out['window'] = window
out["makespan"] = data_in_window["finish_time"].max() - inf
out["#jobs"] = len(data_in_window.index)
out['NRJ_before'] = energy_consumed_in([0, inf], expe_dir)
out['NRJ_in'] = energy_consumed_in(dm_window, expe_dir)
out['NRJ_after'] = energy_consumed_in([dm_window[1], sup], expe_dir)
out["mean_waiting_time"] = data_in_window["waiting_time"].mean()
out["max_waiting_time"] = data_in_window["waiting_time"].max()
out["mean_slowdown"] = data_in_window["stretch"].mean()
out["max_slowdown"] = data_in_window["stretch"].max()
 
if behavior == "dm_user_delay":
# Corrected waiting time and slowdown: cross data with baseline expe
control_exp = pd.read_csv(f"{OUT_DIR}/expe{exp_num}/replay_user_rigid_window1/_jobs.csv",
index_col="job_id", dtype={'profile': 'str'})
original_submission_time = control_exp.loc[data_in_window.index]["submission_time"]
starting_time = data_in_window["starting_time"]
finish_time = data_in_window["finish_time"]
execution_time = data_in_window["execution_time"]
 
corrected_wtime = starting_time - original_submission_time
corrected_sdown = (finish_time - original_submission_time) / execution_time
 
out["mean_corrected_wtime"] = corrected_wtime.mean()
out["max_corrected_wtime"] = corrected_wtime.max()
out["mean_corrected_sdown"] = corrected_sdown.mean()
out["max_corrected_sdown"] = corrected_sdown.max()
 
return out
 
def pct_change(a, b):
"""a + pct_change(a, b) * a = b"""
return (b / a - 1) * 100
 
def metrics_relative(control, current):
"""Returns the metrics of current, relative to control.
Param or dictionnaries for a single expe."""
res = {}
res['XP'], res['window'], res['behavior'] = current['XP'], current['window'], current['behavior']
for metric in ["#jobs", "NRJ_in", "NRJ_after", "max_slowdown", "max_waiting_time", "mean_slowdown", "mean_waiting_time"]:
res[metric] = pct_change(control[metric], current[metric])
res["NRJ_in + NRJ_after"] = pct_change(control["NRJ_in"] + control["NRJ_after"], current["NRJ_in"] + current["NRJ_after"])
 
if "mean_corrected_sdown" in current: # for delay behavior
res["mean_corrected_sdown"] = pct_change(control["mean_slowdown"], current["mean_corrected_sdown"])
res["mean_corrected_wtime"] = pct_change(control["mean_waiting_time"], current["mean_corrected_wtime"])
return res
 
metrics = pd.DataFrame()
metrics_relative = pd.DataFrame()
 
for xp in range(nb_exp):
for window_size in [1, 4]:
# Baseline expe
behavior, window = "replay_user_rigid", 1
control_exp_metrics = metrics(xp, behavior, window, window_size)
metrics = metrics.append(control_exp_metrics, ignore_index=True)
 
# Other expe
for behavior in ["dm_user_reconfig", "dm_user_degrad", "dm_user_renonce", "dm_user_delay"]:
current_exp_metrics = metrics(xp, behavior, window_size)
metrics = metrics.append(current_exp_metrics, ignore_index=True)
metrics_relative = metrics_relative.append(metrics_relative(control_exp_metrics, current_exp_metrics), ignore_index=True)
 
metrics.to_csv(f"{OUT_DIR}/metrics_campaign2.csv")
metrics_relative.to_csv(f"{OUT_DIR}/metrics_relative_campaign2.csv")
```
 
%% Cell type:code id:extended-minutes tags:
 
``` python
metrics = pd.read_csv(f"{OUT_DIR}/metrics_campaign2.csv")
metrics
```
 
%% Output
 
#jobs NRJ_after NRJ_before NRJ_in XP \
Unnamed: 0
0 4525.0 379.095561 330.632095 15.958916 0.0
1 4525.0 379.716607 330.632095 15.835053 0.0
2 4525.0 378.211812 330.632095 15.835053 0.0
3 4353.0 369.414075 330.632095 15.574638 0.0
4 4525.0 376.966849 330.632095 15.576238 0.0
... ... ... ... ... ...
1045 19011.0 426.434174 665.809533 90.272213 104.0
1046 19011.0 427.765204 665.809533 90.272213 104.0
1047 19011.0 403.122903 665.809533 90.272373 104.0
1048 17610.0 380.231158 665.809533 83.480785 104.0
1049 19011.0 430.269170 665.809533 83.482133 104.0
behavior \
Unnamed: 0
0 replay_user_rigid
1 dm_user_reconfig
2 dm_user_degrad
3 dm_user_renonce
4 dm_user_delay
... ...
1045 replay_user_rigid
1046 dm_user_reconfig
1047 dm_user_degrad
1048 dm_user_renonce
1049 dm_user_delay
dir makespan \
Unnamed: 0
0 /home/mmadon/demand-response-user/out/expe0/re... 192701.0
1 /home/mmadon/demand-response-user/out/expe0/dm... 192701.0
2 /home/mmadon/demand-response-user/out/expe0/dm... 192701.0
3 /home/mmadon/demand-response-user/out/expe0/dm... 192701.0
4 /home/mmadon/demand-response-user/out/expe0/dm... 192701.0
... ... ...
1045 /home/mmadon/demand-response-user/out/expe104/... 193569.0
1046 /home/mmadon/demand-response-user/out/expe104/... 193569.0
1047 /home/mmadon/demand-response-user/out/expe104/... 193569.0
1048 /home/mmadon/demand-response-user/out/expe104/... 193569.0
1049 /home/mmadon/demand-response-user/out/expe104/... 193569.0
max_slowdown max_waiting_time mean_slowdown mean_waiting_time \
Unnamed: 0
0 331.20 5734.000000 4.561806 571.630939
1 352.80 5764.000000 4.593056 574.691934
2 352.80 4412.000000 4.601100 576.861878
3 329.80 5739.000000 4.553823 605.601654
4 333.40 3577.000000 4.532490 579.920663
... ... ... ... ...
1045 2095.20 22869.000000 11.957727 879.067803
1046 1573.70 18768.000000 9.324098 925.240229
1047 1533.60 16073.000001 5.397535 474.735732
1048 16.00 2622.000000 1.022170 8.203975
1049 660.55 16030.000000 2.320387 374.382884
window max_corrected_sdown max_corrected_wtime \
Unnamed: 0
0 1.0 NaN NaN
1 1.0 NaN NaN
2 1.0 NaN NaN
3 1.0 NaN NaN
4 1.0 333.400000 3577.0
... ... ... ...
1045 4.0 NaN NaN
1046 4.0 NaN NaN
1047 4.0 NaN NaN
1048 4.0 NaN NaN
1049 4.0 1417.200001 25712.0
mean_corrected_sdown mean_corrected_wtime
Unnamed: 0
0 NaN NaN
1 NaN NaN
2 NaN NaN
3 NaN NaN
4 8.043834 642.518674
... ... ...
1045 NaN NaN
1046 NaN NaN
1047 NaN NaN
1048 NaN NaN
1049 7.803630 908.682816
[1050 rows x 17 columns]
 
%% Cell type:code id:bottom-moore tags:
 
``` python
# Create a similar file with metrics relative to the control XP
metrics_relative = pd.read_csv(f"{OUT_DIR}/metrics_relative_campaign2.csv")
aggregated = metrics_relative.groupby(["window", "behavior"]).median()
aggregated
```
 
%% Output
 
Unnamed: 0 XP #jobs NRJ_in NRJ_after \
window behavior
1.0 dm_user_degrad 417.0 52.0 0.000000 -0.084491 -0.845076
dm_user_delay 419.0 52.0 0.000000 -2.999259 0.137106
dm_user_reconfig 416.0 52.0 0.000000 -0.084491 -0.084304
dm_user_renonce 418.0 52.0 -4.050309 -2.999259 -2.569424
4.0 dm_user_degrad 421.0 52.0 0.000000 -1.550643 -3.176829
dm_user_delay 423.0 52.0 0.000000 -12.576834 2.782374
dm_user_reconfig 420.0 52.0 0.000000 -0.755172 -0.271207
dm_user_renonce 422.0 52.0 -14.834092 -12.577432 -10.706547
max_slowdown max_waiting_time mean_slowdown \
window behavior
1.0 dm_user_degrad -0.768976 -2.052022 -1.830263
dm_user_delay 0.000000 -0.041770 0.732654
dm_user_reconfig 0.000000 0.000000 -0.590662
dm_user_renonce -7.819905 -7.327678 -4.650406
4.0 dm_user_degrad -6.009832 -7.422668 -7.355576
dm_user_delay 0.789715 -0.137337 9.290796
dm_user_reconfig 0.000000 -2.147329 -1.527935
dm_user_renonce -23.708726 -16.641113 -16.018570
mean_waiting_time NRJ_in + NRJ_after \
window behavior
1.0 dm_user_degrad -2.734000 -0.940268
dm_user_delay 0.834744 0.010208
dm_user_reconfig -0.394617 -0.123558
dm_user_renonce -9.136388 -2.586890
4.0 dm_user_degrad -11.947051 -3.392949
dm_user_delay 10.917350 0.239269
dm_user_reconfig -2.122846 -0.492412
dm_user_renonce -18.847380 -11.308871
mean_corrected_sdown mean_corrected_wtime
window behavior
1.0 dm_user_degrad NaN NaN
dm_user_delay 7.129606 3.980916
dm_user_reconfig NaN NaN
dm_user_renonce NaN NaN
4.0 dm_user_degrad NaN NaN
dm_user_delay 84.387697 64.886070
dm_user_reconfig NaN NaN
dm_user_renonce NaN NaN
 
%% Cell type:markdown id:30234b04 tags:
 
## What do our data look like?
Descriptive stats: for each expe and each window, calculate the number of jobs in dr_window et infrastructure load in dr_window. Use the baseline expe to get these stats.
 
%% Cell type:code id: tags:
 
``` python
res = {}
res["XP"], res["window"], res["wday"], res["#job_in_dr"], res["mass_in_dr"] = [], [], [], [], []
wday = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
for xp in range(nb_exp):
# Get these stats from the baseline XP
expe_dir = f"{OUT_DIR}/expe{xp}/replay_user_rigid_window1"
for i in range(2):
data = pd.read_csv(f"{expe_dir}/_jobs.csv", index_col="job_id", dtype={'profile': 'str'})
data_in_window = data[(data.submission_time
>= start_dr) & (data.submission_time <= end_dr[i])]
js = JobSetMulticore.from_csv(f"{expe_dir}/_jobs.csv")
 
res["XP"].append(xp)
res["window"].append(win[i])
res["wday"].append( wday[xp % 5] )
res["#job_in_dr"].append(len(data_in_window.index))
res["mass_in_dr"].append(js.mean_utilisation(start_dr, end_dr[i]) * (end_dr_h[i] - start_dr_h))
pd.DataFrame(res).to_csv(f"{OUT_DIR}/load_in_dr.csv")
```
 
%% Cell type:code id:742cabe7 tags:
 
``` python
# Print these stats
fig, axs = plt.subplots(2, 2)
load_in_dr = pd.read_csv(f"{OUT_DIR}/load_in_dr.csv")
 
load_in_dr.boxplot(column="#job_in_dr", by="window", vert=False, ax=axs[0, 0])
axs[0, 1].axvline(x=104*16, color='red', linewidth=1)
axs[0, 1].axvline(x=104*16*4, color='darkred', linewidth=1)
load_in_dr.boxplot(column="mass_in_dr", by="window", vert=False, ax=axs[0, 1])
 
axs[1, 0].axhline(y=104*16, color='red', linewidth=1)
load_in_dr[load_in_dr.window==1].plot.scatter(x="#job_in_dr", y="mass_in_dr", ax=axs[1, 0])
 
# axs[1, 1].axhline(y=104*16*4, color='darkred', linewidth=1)
# load_in_dr[load_in_dr.window==4].plot.scatter(x="#job_in_dr", y="mass_in_dr", ax=axs[1, 1])
axs[1, 1].axvline(x=104*16, color='red', linewidth=1)
load_in_dr[load_in_dr.window==1].boxplot(column="mass_in_dr", by="wday",
vert=False, positions=[1,5,2,4,3], ax=axs[1, 1])
 
axs[0,0].set_title('(a)')
axs[0,1].set_title('(b)')
axs[1,0].set_title('(c)')
axs[1,1].set_title('(d)')
 
# plt.suptitle('')
plt.suptitle("(a) number of jobs in window; (b) total mass (in core-hour) in window; (c) total mass in window by number of jobs (1-hour window); (d) total mass in window by weekday (1-hour window)")
plt.show()
```
 
%% Output
 
 
%% Cell type:markdown id:ed775f60 tags:
 
Analysis:
- no correletion between the number of jobs in the demand response window and the average load during that period: the jobs have very different size
- data very scattered, even if we notice that in more than 50% of the case, the infrastructure is at almost full load during the demand response event, and at more than 80% load in more than 75% of the case
- the 1-hour window (from 16:00 to 17:00) is more loaded on average than the 4-hour window (from 16:00 to 20:00)
 
%% Cell type:code id:4847dbbf tags:
 
``` python
fig, axs = plt.subplots(1, 2)
load_in_dm = pd.read_csv(f"{OUT_DIR}/load_in_dm.csv")
load_in_dm[load_in_dm.window==1].boxplot(column="mean_load_in_dm", by="wday", ax=axs[0])
load_in_dm[load_in_dm.window==4].boxplot(column="mean_load_in_dm", by="wday", ax=axs[1])
plt.suptitle("Mean load per weekday for a window of 1 hour (left) and 4 hours (right)")
plt.show()
```
 
%% Output
 
 
%% Cell type:markdown id:22d2bc2e tags:
 
## Energy and scheduling metrics
 
%% Cell type:code id:sublime-warning tags:
 
``` python
#########
# For 1-hour time window
#########
# Load data
metrics_relative = pd.read_csv(f"{OUT_DIR}/metrics_relative_campaign2.csv")
metrics_relative["bvr_ord"] = metrics_relative["behavior"].replace(bvr_ord)
data_window1 = metrics_relative[metrics_relative.window==1]
 
# Energy metrics
fig, axs = plt.subplots(1,3)
for ax in axs:
ax.yaxis.set_major_formatter("{x:.0f}%")
ax.axhline(y=0, color='lightpink', linewidth=1)
ax.set_ylim(-35, 5)
data_window1.boxplot(column="NRJ_in", by="bvr_ord", ax=axs[0])
data_window1.boxplot(column="NRJ_after", by="bvr_ord", ax=axs[1])
data_window1.boxplot(column="NRJ_in + NRJ_after", by="bvr_ord", ax=axs[2])
for ax in axs:
ax.set_xticklabels(bvr_name)
plt.suptitle("Energy metrics (relative to baseline) - 1-hour DR window")
 
# Scheduling metrics
fig, axs = plt.subplots(1,2)
for ax in axs:
ax.xaxis.set_major_formatter("{x:.0f}%")
ax.axvline(x=0, color='lightpink', linewidth=1)
 
sd, wt = pd.DataFrame(), pd.DataFrame()
for name, orig_name in zip(reversed(bvr_name), reversed(bvr_orig_name)):
select = data_window1[data_window1.behavior == orig_name].reset_index()
if name == 'delay':
sd["delay\n(corrected)"] = select["mean_corrected_sdown"]
wt["delay\n(corrected)"] = select["mean_corrected_wtime"]
sd[name] = select["mean_slowdown"]
wt[name] = select["mean_waiting_time"]
 
sd.boxplot(vert=False, ax=axs[0])
axs[0].set_xlim(-100, 120)
axs[0].set_title("Mean slowdown")
wt.boxplot(vert=False, ax=axs[1])
axs[1].set_xlim(-100, 120)
axs[1].set_title("Mean waiting time")
plt.suptitle("Scheduling metrics (relative to baseline) - 1-hour DR window")
 
# User_delay outliers
fig, ax = plt.subplots(figsize=(15,2))
data_window1[data_window1.behavior=="dm_user_delay"].boxplot(
column=["mean_slowdown", "mean_corrected_sdown", "mean_waiting_time", "mean_corrected_wtime"],
vert=False, ax=ax)
ax.xaxis.set_major_formatter("{x:.0f}%")
plt.suptitle("User_delay outliers")
plt.show()
```
 
%% Output
 
 
 
 
%% Cell type:markdown id:3a472900 tags:
 
sd, wt = pd.DataFrame(), pd.DataFrame()
for behavior in ["dm_user_reconfig", "dm_user_degrad", "dm_user_renonce", "dm_user_delay"]:
 
%% Cell type:code id:quarterly-count tags:
 
``` python
#########
# For 4-hour time window
#########
data_window4 = metrics_relative[metrics_relative.window==4]
# Energy metrics
fig, axs = plt.subplots(1,3)
for ax in axs:
ax.yaxis.set_major_formatter("{x:.0f}%")
ax.axhline(y=0, color='lightpink', linewidth=1)
data_window4.boxplot(column="NRJ_in", by="bvr_ord", ax=axs[0])
data_window4.boxplot(column="NRJ_after", by="bvr_ord", ax=axs[1])
data_window4.boxplot(column="NRJ_in + NRJ_after", by="bvr_ord", ax=axs[2])
for ax in axs:
ax.set_ylim(-55, 18)
ax.set_xticklabels(bvr_name)
plt.suptitle("Energy metrics (relative to baseline) - 4-hour DR window")
 
# Scheduling metrics
fig, axs = plt.subplots(1,2)
for ax in axs:
ax.xaxis.set_major_formatter("{x:.0f}%")
ax.axvline(x=0, color='lightpink', linewidth=1)
sd, wt = pd.DataFrame(), pd.DataFrame()
for name, orig_name in zip(reversed(bvr_name), reversed(bvr_orig_name)):
select = data_window4[data_window4.behavior == orig_name].reset_index()
if name == 'delay':
sd["delay\n(corrected)"] = select["mean_corrected_sdown"]
wt["delay\n(corrected)"] = select["mean_corrected_wtime"]
sd[name] = select["mean_slowdown"]
wt[name] = select["mean_waiting_time"]
 
sd.boxplot(vert=False, ax=axs[0])
axs[0].set_xlim(-110, 120)
axs[0].set_title("Mean slowdown")
wt.boxplot(vert=False, ax=axs[1])
axs[1].set_xlim(-110, 120)
axs[1].set_title("Mean waiting time")
 
plt.suptitle("Scheduling metrics (relative to baseline) - 4-hour DR window")
 
# User_delay outliers
fig, ax = plt.subplots(figsize=(15,2))
data_window4[data_window4.behavior=="dm_user_delay"].boxplot(
column=["mean_slowdown", "mean_corrected_sdown", "mean_waiting_time", "mean_corrected_wtime"],
vert=False, ax=ax)
ax.xaxis.set_major_formatter("{x:.0f}%")
plt.suptitle("User_delay outliers")
plt.show()
```
 
%% Output
 
 
 
 
%% Cell type:markdown id:ada01643 tags:
 
## Energy and scheduling metrics in f(load)
 
%% Cell type:code id:882339d5 tags:
 
``` python
metrics = pd.read_csv(f"{OUT_DIR}/metrics_campaign2.csv")
load_in_dr = pd.read_csv(f"{OUT_DIR}/load_in_dr.csv")
jointure = metrics.join(load_in_dr.set_index(["XP", "window"]), on=["XP", "window"], rsuffix="*")
j_w_1 = jointure[jointure.window==1]
j_w_4 = jointure[jointure.window==4]
colors = ['g', 'r', 'y', 'k']
 
fig, ax = plt.subplots(2, 2, figsize=[15,10])
for i in range(4):
# Window = 1
j_w_1[j_w_1.behavior=="replay_user_rigid"].plot.scatter(title="", marker='x',
x="mass_in_dr", y="NRJ_in", color="Blue", label="rigid (window 1)", ax=ax[i//2][i%2])
j_w_1[j_w_1.behavior==bvr_orig_name[i]].plot.scatter(marker='x',
x="mass_in_dr", y="NRJ_in", color=colors[i], label=bvr_name[i] + " (window 1)", ax=ax[i//2][i%2])
 
# fig, ax = plt.subplots(2, 2)
for i in range(4):
# Window = 1
j_w_4[j_w_4.behavior=="replay_user_rigid"].plot.scatter(title="",
x="mass_in_dr", y="NRJ_in", color="Blue", label="rigid (window 4)", ax=ax[i//2][i%2])
j_w_4[j_w_4.behavior==bvr_orig_name[i]].plot.scatter(
x="mass_in_dr", y="NRJ_in", color=colors[i], label=bvr_name[i] + " (window 4)", ax=ax[i//2][i%2])
```
 
%% Output
 
 
%% Cell type:markdown id:9d851cfa tags:
 
Analysis:
- when the platform is fully loaded (right-end side of graphs): involving the user does not help, because the queue of jobs needs to empty itself: effets de latence et d'inertie
- no obvious correlation between the load of the platform during the DR event and the energy gain relative to the baseline (confirmed by the graph below)
- une prise en compte niveau scheduler de l’effort utilisateur indispensable
 
%% Cell type:code id:2102be87 tags:
 
``` python
metrics_relative = pd.read_csv(f"{OUT_DIR}/metrics_relative_campaign2.csv")
load_in_dm = pd.read_csv(f"{OUT_DIR}/load_in_dm.csv")
jointure = metrics_relative.join(load_in_dm.set_index(["XP", "window"]), on=["XP", "window"], rsuffix="*")
j_w_1 = jointure[jointure.window==1]
j_w_4 = jointure[jointure.window==4]
 
fig, ax = plt.subplots(1, 2)
behaviors = ["dm_user_reconfig", "dm_user_degrad", "dm_user_renonce", "dm_user_delay"]
colors = ['g', 'r', 'y', 'k']
for behavior, color in zip(behaviors, colors):
# Window = 1
j_w_1[j_w_1.behavior==behavior].plot.scatter(title="Window 1 hour",
x="mean_load_in_dm", y="NRJ_in", color=color, label=behavior, ax=ax[0])
 
# Window = 4
j_w_4[j_w_4.behavior==behavior].plot.scatter(title="Window 4 hours",
x="mean_load_in_dm", y="NRJ_in", color=color, label=behavior, ax=ax[1])
```
 
%% Output
 
 
%% Cell type:markdown id:b35cb01b tags:
 
## Analysis specific delay
 
%% Cell type:code id:industrial-charleston tags:
 
``` python
inf, sup = observed_window = [start_dr, 72*3600]
 
df = pd.DataFrame(data={
'sd_rig': [],
'sd_dlay': [],
'sd_dlay_corr': []
})
# sd_rig = pd.Series(dtype="float64")
# sd_dlay = pd.Series(dtype="float64")
# sd_dlay_corr = pd.Series(dtype="float64")
for window in [1]:
for xp in range(1):
# Open rigid and select only the jobs whose sumbission
# time is in the window
df_rig = pd.read_csv(f"{OUT_DIR}/expe{xp}/replay_user_rigid_window{window}/_jobs.csv",
index_col="job_id", dtype={'profile': 'str'})
rig = df_rig[(df_rig.submission_time
>= inf) & (df_rig.submission_time <= sup)]
 
# Open delay and select the same jobs
df_dlay = pd.read_csv(f"{OUT_DIR}/expe{xp}/dm_user_delay_window{window}/_jobs.csv",
index_col="job_id", dtype={'profile': 'str'})
dlay = df_dlay.loc[rig.index]
 
# Compute the corrected slowdown
corrected_sdown = (dlay["finish_time"] - rig["submission_time"]) / dlay["execution_time"]
 
df1 = pd.DataFrame(data={
'sd_rig': rig["stretch"],
'sd_dlay': dlay["stretch"],
'sd_dlay_corr': corrected_sdown})
df = pd.concat([df, df1], ignore_index=True, axis=0)
 
```
 
%% Cell type:code id:f360a08c tags:
 
``` python
df.plot(kind="hist", bins=500, alpha=.5)
plt.show()
```
 
%% Output
 
 
%% Cell type:code id:daf57f5f tags:
 
``` python
df.boxplot(vert=False)
plt.show()
```
 
%% Output
 
 
%% Cell type:markdown id:swedish-malaysia tags:
 
## Analysis "fluid mass"
First, for all the experiences with rigid behavior, make a `_jobs.csv` without the fluid mass for a window of 1 and 4 hours.
 
Then compute and save the value of fluid and residual mass for each experiment.
%% Cell type:code id:acc6429d tags:
 
``` python
for xp in range(nb_exp):
expe_dir = f"{OUT_DIR}/expe{xp}/replay_user_rigid_window1"
jobs = pd.read_csv(f"{expe_dir}/_jobs.csv", index_col="job_id", dtype={'profile': 'str'})
 
for window in [1, 4]:
inf, sup = start_dr, start_dr + window*3600
# Select only the jobs submitted out of the window
jobs_wo_fluid = jobs[(jobs.submission_time
< inf) | (jobs.submission_time > sup)]
jobs_wo_fluid.to_csv(f"{expe_dir}/_jobs_wo_fluid_w{window}.csv")
```
 
%% Cell type:code id:0fd8f2e0 tags:
``` python
fluid_residual = {'XP': [], 'window': [], 'residual_mass': []}
# Compute the residual mass from the previously created csv files
for xp in range(nb_exp):
expe_dir = f"{OUT_DIR}/expe{xp}/replay_user_rigid_window1"
for i in range(2):
js = JobSetMulticore.from_csv(f"{expe_dir}/_jobs_wo_fluid_w{win[i]}.csv")
fluid_residual["XP"].append(xp)
fluid_residual["window"].append(win[i])
fluid_residual["residual_mass"].append(
js.mean_utilisation(start_dr, end_dr[i]) * (end_dr_h[i] - start_dr_h))
df = pd.DataFrame(fluid_residual)
load_in_dr = pd.read_csv(f"{OUT_DIR}/load_in_dr.csv")
df = df.join(load_in_dr.set_index(["XP", "window"]), on=["XP", "window"], rsuffix="*")
df['fluid_mass'] = df['mass_in_dr'] - df['residual_mass']
df['ratio_fl_res'] = df['fluid_mass'] / df['residual_mass']
df.to_csv(f"{OUT_DIR}/fluid_residual.csv")
```
%% Cell type:markdown id:63b0bf48 tags:
 
Let's see how this looks like for one expe.
 
%% Cell type:code id:18be6388 tags:
 
``` python
expe_dir = f"{OUT_DIR}/expe1/replay_user_rigid_window1"
js = JobSetMulticore.from_csv(f"{expe_dir}/_jobs.csv")
js_wo_fluid = []
js_wo_fluid.append(JobSetMulticore.from_csv(f"{expe_dir}/_jobs_wo_fluid_w1.csv"))
js_wo_fluid.append(JobSetMulticore.from_csv(f"{expe_dir}/_jobs_wo_fluid_w4.csv"))
print(
"Mean utilisation\nReference:\n"
f" Window1: {js.mean_utilisation(start_dr, start_dr + 1*3600)}\n"
f" Window4: {js.mean_utilisation(start_dr, start_dr + 4*3600)}\n"
"Without fluid mass:\n"
f" Window1: {js_wo_fluid[0].mean_utilisation(start_dr, start_dr + 1*3600)}\n"
f" Window4: {js_wo_fluid[1].mean_utilisation(start_dr, start_dr + 4*3600)}\n"
)
 
window = [1, 4]
fig, axs = plt.subplots(1, 2)
fig.suptitle(f"Window 1 (left), window 4 (right)")
zoom_a, zoom_b = start_dr - 3600, start_dr + (4 + 3) * 3600
 
for i in range(len(window)):
vleg.plot_load(js.utilisation, js.MaxProcs, time_scale=False, ax=axs[i])
vleg.plot_load(js_wo_fluid[i].utilisation, js.MaxProcs, time_scale=False, ax=axs[i])
axs[i].xaxis.set_ticks(np.arange(zoom_a, zoom_b, 3600))
axs[i].xaxis.set_ticklabels(np.arange(15, 16 + 4 + 3, 1))
axs[i].set_xlim(zoom_a, zoom_b)
axs[i].axvline(x=start_dr, color='green')
axs[i].axvline(x=start_dr + window[i]*3600, color='green')
plt.show()
# js.plot()
# js_w1.plot()
# js_w4.plot()
```
 
%% Output
 
Mean utilisation
Reference:
Window1: 1026.6177777777777
Window4: 860.9359722222222
Without fluid mass:
Window1: 856.2488888888889
Window4: 579.0436111111111
 
 
%% Cell type:code id:0fd8f2e0 tags:
%% Cell type:code id:18760171 tags:
``` python
metrics_relative = pd.read_csv(f"{OUT_DIR}/metrics_relative_campaign2.csv")
fluid_residual = pd.read_csv(f"{OUT_DIR}/fluid_residual.csv")
# Compute the ratio explicative of the results:
fluid_residual['ratio_fl_mass'] = fluid_residual['fluid_mass'] / fluid_residual['mass_in_dr']
jointure = metrics_relative.join(fluid_residual.set_index(["XP", "window"]), on=["XP", "window"], rsuffix="*")
j_w_1 = jointure[jointure.window==1]
j_w_4 = jointure[jointure.window==4]
fig, ax = plt.subplots(1,1, figsize=[15,10])
# fig, ax = plt.subplots(2, 2, figsize=[15,10])
# Delay / renounce
j_w_1[j_w_1.behavior=="dm_user_renonce"].plot.scatter(marker='x', x="ratio_fl_mass",
y="NRJ_in", color='g', label="(window 1) renounce/delay", ax=ax)#ax[i//2][i%2])
j_w_4[j_w_4.behavior=="dm_user_renonce"].plot.scatter(
x="ratio_fl_mass", y="NRJ_in", color='g', label="(window 4) renounce/delay", ax=ax)#ax[i//2][i%2])
# Degrad
j_w_1[j_w_1.behavior=="dm_user_degrad"].plot.scatter(marker='x', x="ratio_fl_mass",
y="NRJ_in", color='y', label="(window 1) degrad", ax=ax)
j_w_4[j_w_4.behavior=="dm_user_degrad"].plot.scatter(
x="ratio_fl_mass", y="NRJ_in", color='y', label="(window 4) degrad", ax=ax)
# Reconfig
j_w_1[j_w_1.behavior=="dm_user_reconfig"].plot.scatter(marker='x', x="ratio_fl_mass",
y="NRJ_in", color='k', label="(window 1) reconfig", ax=ax)
j_w_4[j_w_4.behavior=="dm_user_reconfig"].plot.scatter(
x="ratio_fl_mass", y="NRJ_in", color='k', label="(window 4) reconfig", ax=ax)
# Droites de pente -1 et -1/2
x = np.linspace(0, 0.70, 100)
ax.plot(x, -100 * x, '-.r', label='y = -100x')
ax.plot(x, -50 * x, '-.m', label='y = -50x')
ax.set_ylim(-55, 5)
ax.set_xlim(-.01, .65)
plt.legend()
plt.show()
```
%% Output
%% Cell type:code id:6993a15c tags:
 
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment