Skip to content
Merged
1 change: 1 addition & 0 deletions dashboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def update_on_change_model(**kwargs):
"parameters_max",
"parameters_show_all",
"simulation_calibration",
"use_inferred_calibration",
)
def update_on_change_others(**kwargs):
# skip if triggered on server ready (all state variables marked as modified)
Expand Down
175 changes: 143 additions & 32 deletions dashboard/calibration_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from trame.widgets import client, vuetify3 as vuetify, html
from state_manager import state
from error_manager import add_error
import copy


Expand All @@ -15,7 +16,26 @@ def convert_sim_to_exp(self, df_sim):
for value in state.simulation_calibration.values():
sim_name = value["name"]
exp_name = value["depends_on"]
df_sim[exp_name] = df_sim[sim_name] / value["alpha"] + value["beta"]
df_sim[exp_name] = (
df_sim[sim_name] / value["alpha_guess"] + value["beta_guess"]
)
if state.use_inferred_calibration:
if all(
inferred_key in value.values()
for inferred_key in ["alpha_inferred", "beta_inferred"]
):
df_sim[exp_name] = (
df_sim[sim_name] / value["alpha_inferred"]
+ value["beta_inferred"]
)
else:
title = "Inferrred calibration does not exist"
message = "Attempted to use the inferred calibration values to apply to the simulation points but calibration hasn't been inferred yet. Applying the guess calibration instead."
add_error(
title,
message,
)
print(message)

def convert_exp_to_sim(self, exp_dict):
"""
Expand All @@ -38,8 +58,28 @@ def convert_exp_to_sim(self, exp_dict):
)
# fill the dictionary
if exp_name in exp_dict:
sim_val = (exp_dict[exp_name] - value["beta"]) * value["alpha"]
sim_dict[sim_name] = sim_val
sim_dict[sim_name] = (exp_dict[exp_name] - value["beta_guess"]) * value[
"alpha_guess"
]
if state.use_inferred_calibration:
if all(
inferred_key in value.values()
for inferred_key in ["alpha_inferred", "beta_inferred"]
):
sim_dict[sim_name] = (
exp_dict[exp_name] - value["beta_inferred"]
) * value["alpha_inferred"]
else:
title = "Inferrred calibration does not exist"
message = (
"Attempted to use the inferred calibration values to apply to the experimental points but the calibration hasn't been inferret yet. Applying the guess calibration instead.",
)
add_error(
title,
message,
)
print(message)

return sim_dict

def panel(self):
Expand All @@ -49,39 +89,110 @@ def panel(self):
title="Control: Calibrate simulation points",
style="font-size: 20px; font-weight: 500;",
):
with vuetify.VExpansionPanelText():
with vuetify.VExpansionPanelText(
style="font-weight: lighter; font-size: 16px;"
):
with vuetify.VRow():
vuetify.VCheckbox(
v_model="use_inferred_calibration",
density="compact",
label="Use inferred calibration",
)
with client.DeepReactive("simulation_calibration"):
for key in state.simulation_calibration.keys():
# create a row for the parameter label
with vuetify.VRow():
html.Small(
f"<b> {state.simulation_calibration[key]['name']}</b> = α × (<b>{state.simulation_calibration[key]['depends_on']}</b> - β)",
style="font-weight: lighter; font-size: 70%;",
)
with vuetify.VRow():
with vuetify.VCol():
vuetify.VTextField(
v_model_number=(
f"simulation_calibration['{key}']['alpha']",
),
change="flushState('simulation_calibration')",
density="compact",
hide_details=True,
hide_spin_buttons=True,
style="width: 100px;",
type="number",
label="α",
)
with vuetify.VCol():
vuetify.VTextField(
v_model_number=(
f"simulation_calibration['{key}']['beta']",
),
change="flushState('simulation_calibration')",
density="compact",
hide_details=True,
hide_spin_buttons=True,
style="width: 100px;",
type="number",
label="β",
)
with vuetify.VRow(
style="display: flex; align-items: center; margin: 20px; justify-content: space-between;"
):
html.Small("α = ")
with vuetify.VCard(
subtitle="guess", density="comfortable"
):
with vuetify.VCardText():
with vuetify.VRow(style="align-items: center"):
vuetify.VTextField(
v_model_number=(
f"simulation_calibration['{key}']['alpha_guess']",
),
change="flushState('simulation_calibration')",
density="compact",
hide_details=True,
hide_spin_buttons=True,
style="width: 100px;",
type="number",
)
html.Small("±")
vuetify.VTextField(
v_model_number=(
f"simulation_calibration['{key}']['alpha_uncertainty']",
),
density="compact",
hide_details=True,
hide_spin_buttons=True,
style="width: 100px;",
type="number",
)
with vuetify.VCard(subtitle="inferred"):
with vuetify.VCardText():
with vuetify.VRow():
vuetify.VTextField(
v_model_number=(
f"simulation_calibration['{key}']['alpha_inferred']",
),
density="compact",
hide_details=True,
hide_spin_buttons=True,
style="width: 100px;",
type="number",
disabled=True,
)

with vuetify.VRow(
style="display: flex; align-items: center; margin: 20px; justify-content: space-between;"
):
html.Small("β = ")
with vuetify.VCard(
subtitle="guess", density="comfortable"
):
with vuetify.VCardText():
with vuetify.VRow(style="align-items: center"):
vuetify.VTextField(
v_model_number=(
f"simulation_calibration['{key}']['beta_guess']",
),
change="flushState('simulation_calibration')",
density="compact",
hide_details=True,
hide_spin_buttons=True,
style="width: 100px;",
type="number",
)
html.Small("±")
vuetify.VTextField(
v_model_number=(
f"simulation_calibration['{key}']['beta_uncertainty']",
),
density="compact",
hide_details=True,
hide_spin_buttons=True,
style="width: 100px;",
type="number",
)
with vuetify.VCard(subtitle="inferred"):
with vuetify.VCardText():
with vuetify.VRow():
vuetify.VTextField(
v_model_number=(
f"simulation_calibration['{key}']['beta_inferred']",
),
density="compact",
hide_details=True,
hide_spin_buttons=True,
style="width: 100px;",
type="number",
disabled=True,
)
2 changes: 2 additions & 0 deletions dashboard/state_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ def initialize_state():
# Errors management
state.errors = []
state.error_counter = 0
# Calibration toggles
state.use_inferred_calibration = False
2 changes: 1 addition & 1 deletion ml/train_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
for _, value in simulation_calibration.items():
sim_name = value["name"]
exp_name = value["depends_on"]
df_sim[exp_name] = df_sim[sim_name] / value["alpha"] + value["beta"]
df_sim[exp_name] = df_sim[sim_name] / value["alpha_guess"] + value["beta_guess"]

# Concatenate experimental and simulation data for training and validation
variables = input_names + output_names + ["experiment_flag"]
Expand Down