Skip to content

Commit

Permalink
Adding scaffolding for running root model
Browse files Browse the repository at this point in the history
  • Loading branch information
JBris committed Aug 18, 2024
1 parent 970ab09 commit 51b19a5
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 33 deletions.
37 changes: 36 additions & 1 deletion app/conf/form/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,26 @@ components:
max: 1
step: 0.01
value: 0.1
data:
simulation:
collapsible: true
children:
- id: run-sim-button
label: Run
help: Run the simulation modelling procedure
class_name: dash_bootstrap_components.Button
kwargs:
children: Run model
color: primary
className: me-1
- id: cancel-sim-button
label: Cancel
help: Cancel the simulation modelling run
class_name: dash_bootstrap_components.Button
kwargs:
children: Cancel run
color: primary
className: me-1
disabled: true
- id: save-param-button
label: Save
help: Save current parameter configuration to file
Expand All @@ -236,3 +253,21 @@ components:
handler: file_upload
kwargs:
children: Load parameters
- id: save-results-button
label: Save
help: Save the current simulation modelling results
class_name: dash_bootstrap_components.Button
kwargs:
children: Save results
color: primary
className: me-1
disabled: true
- id: load-results-button
label: Load
help: Load previous simulation modelling results
class_name: dash_bootstrap_components.Button
kwargs:
children: Load results
color: primary
className: me-1
disabled: true
70 changes: 40 additions & 30 deletions app/pages/generate_root_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ def toggle_parameters_collapse(n: int, is_open: bool) -> bool:


@callback(
Output(f"{PAGE_ID}-data-collapse", "is_open"),
[Input(f"{PAGE_ID}-data-collapse-button", "n_clicks")],
[State(f"{PAGE_ID}-data-collapse", "is_open")],
Output(f"{PAGE_ID}-simulation-collapse", "is_open"),
[Input(f"{PAGE_ID}-simulation-collapse-button", "n_clicks")],
[State(f"{PAGE_ID}-simulation-collapse", "is_open")],
)
def toggle_data_io_collapse(n: int, is_open: bool) -> bool:
"""Toggle the collapsible for data input/output.
def toggle_simulation_collapse(n: int, is_open: bool) -> bool:
"""Toggle the collapsible for simulation management.
Args:
n (int):
Expand Down Expand Up @@ -147,28 +147,34 @@ def update_output(list_of_contents: list, list_of_names: list) -> tuple:
return inputs, True, toast_message


# @callback(
# Output("generate-root-system-plot", "figure"),
# Input({"type": f"{PAGE_ID}-parameters", "index": ALL}, "value"),
# )
# def plot_root_model(form_inputs: list) -> dcc.Graph:
# """Run and plot the root model.
@callback(
Output("generate-root-system-plot", "figure"),
Input({"index": f"{PAGE_ID}-run-sim-button", "type": ALL}, "n_clicks"),
State({"type": f"{PAGE_ID}-parameters", "index": ALL}, "value"),
prevent_initial_call=True,
)
def run_root_model(n_clicks: list, form_values: list) -> dcc.Graph:
"""Run and plot the root model.
# Args:
# form_inputs (list):
# The form input data.
Args:
n_clicks (list):
Number of times the button has been clicked.
form_values (list):
The form input data.
# Returns:
# dcc.Graph: The visualised root model.
# """
# inputs = {}
# app = get_app()
# form_model = app.settings["form"]
# for i, input in enumerate(form_model.components["parameters"]["children"]):
# k = input["param"]
# inputs[k] = form_inputs[i]
Returns:
dcc.Graph: The visualised root model.
"""
n_click: int = n_clicks[0]
if n_click > 0:
inputs = {}
app = get_app()
form_model = app.settings["form"]
for i, input in enumerate(form_model.components["parameters"]["children"]):
k = input["param"]
inputs[k] = form_values[i]

# return dcc.Graph()
return dcc.Graph()


######################################
Expand All @@ -187,21 +193,25 @@ def layout() -> html.Div:
app = get_app()
form_model = app.settings["form"]

k = "parameters"
parameter_components = build_common_components(
form_model.components["parameters"]["children"], PAGE_ID, "parameters"
form_model.components[k]["children"], PAGE_ID, k
)

if form_model.components["parameters"]["collapsible"]:
if form_model.components[k]["collapsible"]:
parameter_components = build_collapsible(
parameter_components, PAGE_ID, "Parameters"
)

k = "simulation"
data_io_components = build_common_components(
form_model.components["data"]["children"], PAGE_ID, "data"
form_model.components[k]["children"], PAGE_ID, k
)

if form_model.components["data"]["collapsible"]:
data_io_components = build_collapsible(data_io_components, PAGE_ID, "Data")
if form_model.components[k]["collapsible"]:
data_io_components = build_collapsible(
data_io_components, PAGE_ID, "Simulation"
)

input_components = dbc.Col([parameter_components, data_io_components])
output_components = dbc.Row(
Expand All @@ -213,7 +223,7 @@ def layout() -> html.Div:
)

page_description = """
Create synthetic root data by running the root system architecture simulation.
Create synthetic root data by running the root system architecture simulation
"""
layout = build_common_layout(
"Run Simulation", PAGE_ID, input_components, output_components, page_description
Expand Down
8 changes: 7 additions & 1 deletion deeprootgen/form/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def build_common_components(
component_spec.help,
target=f"{page_id}-{component_spec.id}-tooltip-target",
placement="right",
delay={"show": "500"},
)
component = locate(component_spec.class_name)
kwargs = component_spec.kwargs
Expand Down Expand Up @@ -198,7 +199,12 @@ def build_common_layout(
style={"margin-left": "1em", "margin-top": "0.2em", "text-align": "center"},
id=f"{page_id}-title",
),
dbc.Tooltip(layout_description, target=f"{page_id}-title", placement="right"),
dbc.Tooltip(
layout_description,
target=f"{page_id}-title",
placement="right",
delay={"show": "500"},
),
input_components,
dcc.Download(id=f"{page_id}-download-content"),
dbc.Toast(
Expand Down
65 changes: 64 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pymc = "^5.16.2"
pytensor = "^2.25.2"
dash-bootstrap-components = "^1.6.0"
dash-bootstrap-templates = "^1.2.3"
salib = "^1.5.0"


[tool.poetry.group.torch.dependencies]
Expand Down

0 comments on commit 51b19a5

Please sign in to comment.