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

start analysis campaign 3

parent 3130d319
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:sustained-helena tags:
# Speedup experiments
In this notebook we analyse the results generated by launching the third experimental campaign `campaign3.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/campaign3"
nb_exp = 10
# the beginning and end of the demand response window in these experiments
start_dr_h = 24 + 16
start_dr = start_dr_h * 3600
end_dr_h = 24 + 20
end_dr = end_dr_h * 3600
```
%% Cell type:code id:51bac175 tags:
``` python
# Check if all XP succeded
for xp in range(nb_exp):
for seed in list(range(1,11)):
expe_dir = f"{OUT_DIR}/expe{xp}/seed_alpha_{seed}"
if not os.path.exists(expe_dir):
print(f"{expe_dir} does not exist")
```
%% 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 experiment relatively to the baseline behavior.
%% Cell type:code id:assumed-saver tags:
``` python
def compute_metrics(exp_num, seed):
"""Returns a dictionnary of metrics for the given expe."""
expe_dir = f"{OUT_DIR}/expe{exp_num}/seed_alpha_{seed}"
dm_window = [start_dr, end_dr]
# 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'] = "dm_user_reconfig"
out['window'] = 4metrics_campaign2.XP >= 0 and
out['seed'] = seed
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()
return out
# def pct_change(a, b):
# """a + pct_change(a, b) * a = b"""
# return (b / a - 1) * 100
# def compute_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"])
# return res
metrics = pd.DataFrame()
# metrics_relative = pd.DataFrame()
for xp in range(nb_exp):
# # Baseline expe
# behavior, window = "replay_user_rigid", 4
# control_exp_metrics = compute_metrics(xp, behavior, window, window_size)
# metrics = metrics.append(control_exp_metrics, ignore_index=True)
# # Reconfig without speedup
# Reconfig with speedup
for seed in list(range(1,11)):
current_exp_metrics = compute_metrics(xp, seed)
metrics = metrics.append(current_exp_metrics, ignore_index=True)
#metrics_relative = metrics_relative.append(compute_metrics_relative(control_exp_metrics, current_exp_metrics), ignore_index=True)
metrics.to_csv(f"{OUT_DIR}/metrics_campaign3.csv")
#metrics_relative.to_csv(f"{OUT_DIR}/metrics_relative_campaign3.csv")
```
%% Cell type:markdown id:f6ad76dd tags:
Lets see how this files look like:
%% Cell type:code id:extended-minutes tags:
``` python
metrics = pd.read_csv(f"{OUT_DIR}/metrics_campaign3.csv")
metrics
```
%% Output
Unnamed: 0 #jobs NRJ_after NRJ_before NRJ_in XP \
0 0 4525.0 345.736752 329.988990 49.051666 0.0
1 1 4525.0 346.285611 329.988990 49.046949 0.0
2 2 4525.0 344.593656 329.988990 49.046949 0.0
3 3 4525.0 347.162689 329.988990 49.019172 0.0
4 4 4525.0 346.368245 329.988990 49.052505 0.0
.. ... ... ... ... ... ...
95 95 14434.0 254.860782 379.990556 45.450707 9.0
96 96 14434.0 251.588478 379.990556 45.172997 9.0
97 97 14434.0 251.880951 379.990556 45.095954 9.0
98 98 14434.0 254.564838 379.990556 45.121994 9.0
99 99 14434.0 252.564207 379.990556 44.919544 9.0
behavior dir \
0 dm_user_reconfig /home/mael/big_files/demand-response-user/out/...
1 dm_user_reconfig /home/mael/big_files/demand-response-user/out/...
2 dm_user_reconfig /home/mael/big_files/demand-response-user/out/...
3 dm_user_reconfig /home/mael/big_files/demand-response-user/out/...
4 dm_user_reconfig /home/mael/big_files/demand-response-user/out/...
.. ... ...
95 dm_user_reconfig /home/mael/big_files/demand-response-user/out/...
96 dm_user_reconfig /home/mael/big_files/demand-response-user/out/...
97 dm_user_reconfig /home/mael/big_files/demand-response-user/out/...
98 dm_user_reconfig /home/mael/big_files/demand-response-user/out/...
99 dm_user_reconfig /home/mael/big_files/demand-response-user/out/...
makespan max_slowdown max_waiting_time mean_slowdown \
0 192701.0 358.1 3893.0 4.549961
1 192701.0 340.2 5875.0 4.541913
2 192701.0 343.9 6751.0 4.396275
3 192701.0 355.0 6087.0 4.408050
4 192701.0 351.9 3830.0 4.461764
.. ... ... ... ...
95 165135.0 16.0 150.0 1.102382
96 165135.0 16.0 150.0 1.117288
97 165135.0 16.0 150.0 1.102702
98 164985.0 16.0 150.0 1.111503
99 164985.0 6.0 150.0 1.107547
mean_waiting_time seed window
0 654.335187 1.0 4.0
1 617.358253 2.0 4.0
2 623.730082 3.0 4.0
3 649.953073 4.0 4.0
4 639.997053 5.0 4.0
.. ... ... ...
95 7.967022 6.0 4.0
96 8.928225 7.0 4.0
97 8.123805 8.0 4.0
98 8.469586 9.0 4.0
99 8.541846 10.0 4.0
[100 rows x 15 columns]
%% Cell type:markdown id:578e1c60 tags:
## Influence of introducing speedup
%% Cell type:code id: tags:
``` python
metrics_campaign3 = pd.read_csv(f"{OUT_DIR}/metrics_campaign3.csv")
metrics_campaign2 = pd.read_csv(f"{OUT_DIR}/../metrics_campaign2.csv")
# Select only in campaign 2 the expe of interest:
metrics_campaign2 = metrics_campaign2[
(metrics_campaign2.XP >= 0) &
(metrics_campaign2.XP <= 9) &
(metrics_campaign2.window == 4)
]
fig, ax = plt.subplots(4, 1, figsize=[15,30])
y_axis = ["NRJ_in", "NRJ_after", "mean_slowdown", "mean_waiting_time"]
for i in range(4):
# Plot reconfig with speedup
metrics_campaign3.plot.scatter(
x="XP", y=y_axis[i], color="r", label="reconfig (speedup)", ax=ax[i], grid=True)
# Plot baseline
metrics_campaign2[metrics_campaign2.behavior=="replay_user_rigid"].plot.scatter(
title="", x="XP", y=y_axis[i], color="Blue", label="rigid", ax=ax[i])
# Plot reconfig without speedup
metrics_campaign2[metrics_campaign2.behavior=="dm_user_reconfig"].plot.scatter(
title="", x="XP", y=y_axis[i], color="k", label="reconfig (no speedup)", ax=ax[i], grid=True)
ax[i].set_xlabel("XP nummer")
ax[i].set_xticks(range(10))
ax[i].set_ylabel(y_axis[i])
ax[i]
```
%% Output
%% Cell type:code id:d2ae43e1 tags:
``` python
metrics_campaign3 = pd.read_csv(f"{OUT_DIR}/metrics_campaign3.csv")
metrics_campaign2 = pd.read_csv(f"{OUT_DIR}/../metrics_campaign2.csv")
metrics_campaign2 = metrics_campaign2[metrics_campaign2.XP]
load_in_dr = pd.read_csv(f"{OUT_DIR}/../load_in_dr.csv")
jointure = metrics.join(load_in_dr.set_index("XP"), on="XP", rsuffix="*")
j_w_4 = jointure[jointure.window==4]
colors = ['g', 'r', 'y', 'k']
fig, ax = plt.subplots(figsize=[15,10])
# 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])
ax[i//2][i%2].set_xlabel("mass_in_dr")
ax[i//2][i%2].set_ylabel("energy_in")
plt.savefig(f"{OUT_DIR}/energy_in_scatter.pdf", bbox_inches='tight', dpi=1000)
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment