Commit
·
0461401
1
Parent(s):
74241d1
feature: load preview and a new load profile
Browse files- when a load is selected, its preview is shown right below
- a simplified load profile from a payment gateway
- agent/backend/load.py +32 -2
- agent/dashboard/inference.py +39 -4
agent/backend/load.py
CHANGED
|
@@ -13,7 +13,8 @@ class ConstantLoad():
|
|
| 13 |
|
| 14 |
def __next__(self):
|
| 15 |
self.step += 1
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
class SinusLoad():
|
| 19 |
'''Periodic load profile'''
|
|
@@ -29,4 +30,33 @@ class SinusLoad():
|
|
| 29 |
|
| 30 |
def __next__(self):
|
| 31 |
self.step += 1
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def __next__(self):
|
| 15 |
self.step += 1
|
| 16 |
+
eod = False
|
| 17 |
+
return self.load, eod
|
| 18 |
|
| 19 |
class SinusLoad():
|
| 20 |
'''Periodic load profile'''
|
|
|
|
| 30 |
|
| 31 |
def __next__(self):
|
| 32 |
self.step += 1
|
| 33 |
+
eod = True if self.step % self.period == 0 else False
|
| 34 |
+
return max(0, self.amplitude + self.amplitude * np.sin(2 * np.pi * (self.step % self.period) / self.period )), eod
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class PaymentGateway113Load():
|
| 38 |
+
'''Payment Gateway Load 113 Days
|
| 39 |
+
|
| 40 |
+
Incoming load to Payment Gateway.
|
| 41 |
+
|
| 42 |
+
'''
|
| 43 |
+
|
| 44 |
+
def __init__(self):
|
| 45 |
+
self.label = f"""Payment Gateway 113 days"""
|
| 46 |
+
self.loadprofile = [40, 32, 48, 48, 56, 48, 40, 32, 64, 64, 64, 64, 72, 64, 48, 32, 80, 64, 64, 56, 56,
|
| 47 |
+
48, 40, 64, 56, 56, 56, 56, 48, 48, 96, 64, 64, 64, 72, 80, 104, 96, 112, 136, 80,
|
| 48 |
+
72, 88, 96, 104, 144, 136, 176, 112, 128, 104, 112, 88, 88, 112, 104, 104, 120, 128,
|
| 49 |
+
88, 88, 160, 144, 152, 160, 208, 128, 96, 128, 112, 112, 144, 136, 136, 144, 144, 128,
|
| 50 |
+
152, 248, 216, 232, 216, 152, 152, 120, 152, 144, 144, 136, 144, 120, 120, 152, 184, 216, 2,
|
| 51 |
+
32, 240, 152, 120, 168, 144, 136, 136, 144, 112, 112, 152, 152, 152, 152, 144, 120, 112]
|
| 52 |
+
self.n = len(self.loadprofile)
|
| 53 |
+
|
| 54 |
+
def __iter__(self):
|
| 55 |
+
self.step = 0
|
| 56 |
+
return self
|
| 57 |
+
|
| 58 |
+
def __next__(self):
|
| 59 |
+
i = self.step % self.n
|
| 60 |
+
eod = True if i == self.n - 1 else False
|
| 61 |
+
self.step += 1
|
| 62 |
+
return self.loadprofile[i], eod
|
agent/dashboard/inference.py
CHANGED
|
@@ -2,7 +2,7 @@ import solara
|
|
| 2 |
import pandas as pd
|
| 3 |
from ..backend.reward import RewardHighCPUUsage, RewardLowCPUUsage
|
| 4 |
from ..backend.policy import PolicyArgMax, PolicyHPA
|
| 5 |
-
from ..backend.load import ConstantLoad, SinusLoad
|
| 6 |
from .training import local_state as training_state
|
| 7 |
from .data import state as data_state
|
| 8 |
from ..backend.utils import estimate_metrics, read_metrics
|
|
@@ -23,7 +23,7 @@ policy_objects = [PolicyArgMax(), PolicyHPA(0.2), PolicyHPA(0.4), PolicyHPA(0.6)
|
|
| 23 |
policy_labels = [p.label for p in policy_objects]
|
| 24 |
selected_policy_label = solara.reactive(policy_labels[0])
|
| 25 |
|
| 26 |
-
load_objects = [ConstantLoad(24), ConstantLoad(72), ConstantLoad(168), SinusLoad(180, 100)]
|
| 27 |
load_labels = [p.label for p in load_objects]
|
| 28 |
selected_load_label = solara.reactive(load_labels[0])
|
| 29 |
|
|
@@ -72,7 +72,7 @@ def InferencePlots(render_count):
|
|
| 72 |
cur_hist = {}
|
| 73 |
replica = initial_replica.value
|
| 74 |
cpu = initial_cpu.value
|
| 75 |
-
for load in load_profile:
|
| 76 |
if step > nsteps.value:
|
| 77 |
break
|
| 78 |
# the model uses load as an input, supply with it
|
|
@@ -127,7 +127,7 @@ def InferencePlots(render_count):
|
|
| 127 |
|
| 128 |
model = training_state.value['model'].value
|
| 129 |
if model is None:
|
| 130 |
-
solara.Warning("
|
| 131 |
|
| 132 |
solara.Button(label="Execute", on_click=execute, disabled=model is None)
|
| 133 |
|
|
@@ -177,6 +177,40 @@ def InferencePlots(render_count):
|
|
| 177 |
solara.FigureEcharts(option=options, attributes={"style": "height: 300px; width: 300px"})
|
| 178 |
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
@solara.component
|
| 182 |
def Page():
|
|
@@ -206,4 +240,5 @@ def Page():
|
|
| 206 |
chosen_load_index = load_labels.index(selected_load_label.value)
|
| 207 |
chosen_load = load_objects[chosen_load_index]
|
| 208 |
solara.Markdown(md_text=chosen_load.__doc__)
|
|
|
|
| 209 |
InferencePlots(local_state.value['render_count'].value)
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from ..backend.reward import RewardHighCPUUsage, RewardLowCPUUsage
|
| 4 |
from ..backend.policy import PolicyArgMax, PolicyHPA
|
| 5 |
+
from ..backend.load import ConstantLoad, SinusLoad, PaymentGateway113Load
|
| 6 |
from .training import local_state as training_state
|
| 7 |
from .data import state as data_state
|
| 8 |
from ..backend.utils import estimate_metrics, read_metrics
|
|
|
|
| 23 |
policy_labels = [p.label for p in policy_objects]
|
| 24 |
selected_policy_label = solara.reactive(policy_labels[0])
|
| 25 |
|
| 26 |
+
load_objects = [ConstantLoad(24), ConstantLoad(72), ConstantLoad(168), SinusLoad(180, 100), PaymentGateway113Load()]
|
| 27 |
load_labels = [p.label for p in load_objects]
|
| 28 |
selected_load_label = solara.reactive(load_labels[0])
|
| 29 |
|
|
|
|
| 72 |
cur_hist = {}
|
| 73 |
replica = initial_replica.value
|
| 74 |
cpu = initial_cpu.value
|
| 75 |
+
for load, eod in load_profile:
|
| 76 |
if step > nsteps.value:
|
| 77 |
break
|
| 78 |
# the model uses load as an input, supply with it
|
|
|
|
| 127 |
|
| 128 |
model = training_state.value['model'].value
|
| 129 |
if model is None:
|
| 130 |
+
solara.Warning("There is no trained model ye, please train one!")
|
| 131 |
|
| 132 |
solara.Button(label="Execute", on_click=execute, disabled=model is None)
|
| 133 |
|
|
|
|
| 177 |
solara.FigureEcharts(option=options, attributes={"style": "height: 300px; width: 300px"})
|
| 178 |
|
| 179 |
|
| 180 |
+
@solara.component
|
| 181 |
+
def Plot1D(x,y):
|
| 182 |
+
options = {
|
| 183 |
+
"xAxis": {
|
| 184 |
+
"type": "category",
|
| 185 |
+
"data": x,
|
| 186 |
+
},
|
| 187 |
+
"yAxis": {
|
| 188 |
+
"type": "value",
|
| 189 |
+
},
|
| 190 |
+
"series": [
|
| 191 |
+
{
|
| 192 |
+
"data": y,
|
| 193 |
+
"type": 'line'
|
| 194 |
+
},
|
| 195 |
+
]
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
with solara.Column():
|
| 199 |
+
solara.FigureEcharts(option=options)
|
| 200 |
+
|
| 201 |
+
@solara.component
|
| 202 |
+
def LoadProfilePlot(load_profile):
|
| 203 |
+
x, y = [], []
|
| 204 |
+
step = 0
|
| 205 |
+
for load, eod in load_profile:
|
| 206 |
+
if step > 150 or eod :
|
| 207 |
+
break
|
| 208 |
+
x.append(step)
|
| 209 |
+
y.append(load)
|
| 210 |
+
step += 1
|
| 211 |
+
|
| 212 |
+
Plot1D(x,y)
|
| 213 |
+
|
| 214 |
|
| 215 |
@solara.component
|
| 216 |
def Page():
|
|
|
|
| 240 |
chosen_load_index = load_labels.index(selected_load_label.value)
|
| 241 |
chosen_load = load_objects[chosen_load_index]
|
| 242 |
solara.Markdown(md_text=chosen_load.__doc__)
|
| 243 |
+
LoadProfilePlot(chosen_load)
|
| 244 |
InferencePlots(local_state.value['render_count'].value)
|