Skip to content

Commit 2c151d0

Browse files
Dashboard: restructure/refactor toolbar code (BLAST-ImpactX#981)
* add: functionality to parse variables from input file Only allowing int,float values at the moment. So no lists, or math expressions * update: update delete available after loading variables otherwise the delete button stays disabled to the user * add: variable to reset button Not implemented in a very robust way right now * fix: prevent crash For example, say lattice element #1 references a variable called 'ns'. If the lattice list is reset or elements are deleted, the variable update handler would still try to access index 1, causing an IndexError. This patch adds a guard to skip updates if the referenced lattice element index is no longer valid. * update: parser to only load in variables which are used in the lattice configuration * empty the variables list before loading in variables * update: allow negative inputs with variables * add float wrapper * update: on_variable_change modify docstring and set variable value to None if empty * simplify 'process_if_variable' * variable renames and move code block * shorted helper function name * add docstring to state.change('variables') * correctly update lattice elements on variable change after element deletion Prevents cases similar to the following: Say you add three lattice elements, the first two reference a variable named ns, the third one references a variable named ns2 in the same parameter name. If we end up deleting the second lattice element, and update the value of the ns variable, the ns2 originally from index 2 becomes ns * add parse_variables docstring and update var name * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix docstring * move input toolbar to separate file also need to move toolbarimport class to remove circular dependency * move parser to separate folder new folder name is 'dashboard_parser' importParser renamed to parser.py importParserHelper renamed to parser_helper.py * move logic to ui_populator.py * rename * move RunToolbar to separate file * move AnalyzeToolbar to separate file * introduce general_toolbar.py contain toolbar components utilized in all the routes * strip '_toolbar' from file name fix resulting circular import * simplify ui_populator break into sub functions * update class docstring * update docstrings * break out populate_variables logic * add inline comments * relocate some code * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 350aa81 commit 2c151d0

File tree

17 files changed

+602
-513
lines changed

17 files changed

+602
-513
lines changed

src/python/impactx/dashboard/Input/distribution/ui.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ def populate_distribution_parameters():
8080

8181
@state.change("distribution")
8282
def on_distribution_name_change(distribution, **kwargs):
83-
if state.importing_file:
84-
return
85-
8683
if distribution == "Thermal" or distribution == "Empty":
8784
state.distribution_type = ""
8885
state.distribution_type_disable = True
@@ -99,8 +96,6 @@ def on_distribution_name_change(distribution, **kwargs):
9996

10097
@state.change("distribution_type")
10198
def on_distribution_type_change(**kwargs):
102-
if state.importing_file:
103-
return
10499
populate_distribution_parameters()
105100

106101

src/python/impactx/dashboard/Input/generalFunctions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import Union
1010

1111
from .. import setup_server
12+
from ..Toolbar.file_imports.python.parser import DashboardParser
1213
from .defaults import DashboardDefaults
1314

1415
server, state, ctrl = setup_server()
@@ -101,6 +102,7 @@ def reset_inputs(input_section):
101102
state.dirty("max_level")
102103

103104
elif input_section == "all":
105+
DashboardParser.reset_importing_states()
104106
state.update(DashboardDefaults.DEFAULT_VALUES)
105107
state.dirty("distribution_type")
106108
state.selected_lattice_list = []

src/python/impactx/dashboard/Run/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77

88
from .. import setup_server
9-
from ..Toolbar.sim_history.ui import SimulationHistory
9+
from ..Toolbar.sim_history import save_view_details_log
1010

1111
server, state, ctrl = setup_server()
1212

@@ -50,7 +50,7 @@ def complete_simulation():
5050
state.sim_is_generating_plots = False
5151
state.dirty("filtered_sims")
5252
state.flush()
53-
SimulationHistory.save_view_details_log()
53+
save_view_details_log()
5454

5555
@staticmethod
5656
def cancel_simulation(proc: asyncio.subprocess.Process):
@@ -68,7 +68,7 @@ def cancel_simulation(proc: asyncio.subprocess.Process):
6868
state.dirty("filtered_sims")
6969
ctrl.terminal_print("Simulation cancelled.")
7070
state.flush()
71-
SimulationHistory.save_view_details_log()
71+
save_view_details_log()
7272

7373
@staticmethod
7474
def fail_simulation() -> None:
@@ -82,7 +82,7 @@ def fail_simulation() -> None:
8282
state.dirty("filtered_sims")
8383
state.flush()
8484
ctrl.terminal_print("Simulation failed due to the above error.")
85-
SimulationHistory.save_view_details_log()
85+
save_view_details_log()
8686

8787
@staticmethod
8888
def reset():
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from ..Input.components.card import CardComponents
2+
from ..Input.generalFunctions import generalFunctions
3+
4+
__all__ = ["CardComponents", "generalFunctions"]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
This file is part of ImpactX
3+
4+
Copyright 2025 ImpactX contributors
5+
Authors: Parthib Roy, Axel Huebl
6+
License: BSD-3-Clause-LBNL
7+
"""
8+
9+
from .. import setup_server, vuetify
10+
11+
server, state, ctrl = setup_server()
12+
13+
14+
class AnalyzeToolbar:
15+
"""
16+
Contains toolbar components for the 'Analyze' page.
17+
"""
18+
19+
@staticmethod
20+
def plot_options() -> vuetify.VSelect:
21+
"""
22+
Displays a dropdown menu to select the available plots
23+
generated from the simulation data.
24+
"""
25+
26+
return vuetify.VSelect(
27+
v_model=("active_plot", "1D plots over s"),
28+
items=("plot_options",),
29+
label="Select plot to view",
30+
hide_details=True,
31+
density="compact",
32+
variant="underlined",
33+
style="max-width: 250px",
34+
disabled=("disableRunSimulationButton", True),
35+
)

0 commit comments

Comments
 (0)