Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Condense repetitive dashboard code #780

Merged
merged 23 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
892b876
Centralize vselect and vtextfields
proy30 Jan 5, 2025
73f9a55
Centralize documentation code
proy30 Jan 5, 2025
2e8cbbe
Centralize section header code
proy30 Jan 5, 2025
e7de38f
Fix multigrid settings
proy30 Jan 6, 2025
7365f29
Centralize dialog settings code for lattice config and space charge
proy30 Jan 6, 2025
19ce589
Add staticmethods
proy30 Jan 6, 2025
5f520be
Centralize some more space charge functions
proy30 Jan 6, 2025
7550126
Reduce code for calling toolbars
proy30 Jan 6, 2025
163b3c6
Remove redundant error_message state inits
proy30 Jan 7, 2025
07505ad
Create initialize_states() and remove redundant state initialization
proy30 Jan 7, 2025
3ad09f5
Remove state inits for dialogs
proy30 Jan 7, 2025
72997c5
Merge branch 'development' into dashboard/condense_redundant_code
proy30 Jan 7, 2025
12d3afc
Correctly condense refresh input functionality into input_section_hea…
proy30 Jan 7, 2025
f123b16
Merge branch 'development' into dashboard/condense_redundant_code
proy30 Jan 8, 2025
afe6256
Provide default v_model_name if not given
proy30 Jan 8, 2025
e1f691c
rename selected_distribution and selected_distribution_type to distri…
proy30 Jan 8, 2025
51a75f0
Simplify inputMain.py
proy30 Jan 8, 2025
a01b272
Centralize shared imports in Input/__init__.py
proy30 Jan 8, 2025
f71b1f5
Simplify csrConfiguration
proy30 Jan 8, 2025
8e61749
Update more of distributionMain.py
proy30 Jan 8, 2025
788d374
Simplify duplicated lattice config code
proy30 Jan 10, 2025
abe3ea0
Remove print statement
proy30 Jan 10, 2025
48ba3f9
Merge branch 'development' into dashboard/condense_redundant_code
proy30 Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions src/python/impactx/dashboard/Input/csrConfiguration/csrMain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from trame.widgets import vuetify

from ...Input.trameFunctions import TrameFunctions
proy30 marked this conversation as resolved.
Show resolved Hide resolved
from ...trame_setup import setup_server
from ..generalFunctions import generalFunctions

Expand Down Expand Up @@ -37,32 +38,16 @@ def card():
"""

with vuetify.VCard(v_show="csr", style="width: 170px;"):
with vuetify.VCardTitle("CSR"):
vuetify.VSpacer()
vuetify.VIcon(
"mdi-information",
classes="ml-2",
click=lambda: generalFunctions.documentation("CSR"),
style="color: #00313C;",
)
vuetify.VDivider()
TrameFunctions.input_section_header("CSR")
with vuetify.VCardText():
with vuetify.VRow(classes="my-0"):
with vuetify.VCol(classes="py-0"):
vuetify.VSelect(
TrameFunctions.select(
label="Particle Shape",
v_model=("particle_shape",),
items=([1, 2, 3],),
dense=True,
v_model_name="particle_shape",
)
with vuetify.VRow(classes="my-0"):
with vuetify.VCol(classes="py-0"):
vuetify.VTextField(
label="CSR Bins",
v_model=("csr_bins",),
error_messages=("csr_bins_error_message",),
type="number",
dense=True,
step=generalFunctions.get_default("csr_bins", "steps"),
__properties=["step"],
TrameFunctions.text_field(
label="CSR Bins", v_model_name="csr_bins"
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from impactx import distribution

from ...Input.trameFunctions import TrameFunctions
from ...trame_setup import setup_server
from ..generalFunctions import generalFunctions
from .distributionFunctions import DistributionFunctions
Expand Down Expand Up @@ -191,33 +192,24 @@ def card():
"""

with vuetify.VCard(style="width: 340px; height: 300px"):
with vuetify.VCardTitle("Distribution Parameters"):
vuetify.VSpacer()
vuetify.VIcon(
"mdi-information",
style="color: #00313C;",
click=lambda: generalFunctions.documentation("BeamDistributions"),
)
vuetify.VDivider()
TrameFunctions.input_section_header("Distribution Parameters")
with vuetify.VCardText():
with vuetify.VRow():
with vuetify.VCol(cols=6):
vuetify.VCombobox(
TrameFunctions.select(
label="Select Distribution",
v_model=("selectedDistribution",),
v_model_name="selectedDistribution",
items=("listOfDistributions",),
dense=True,
)
with vuetify.VCol(cols=6):
vuetify.VSelect(
v_model=("selectedDistributionType",),
TrameFunctions.select(
label="Type",
v_model_name="selectedDistributionType",
items=(
generalFunctions.get_default(
"distribution_type_list", "default_values"
),
),
dense=True,
disabled=("distributionTypeDisabled",),
)
with vuetify.VRow(classes="my-2"):
Expand Down
32 changes: 17 additions & 15 deletions src/python/impactx/dashboard/Input/generalFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def documentation(section_name):
:param section_name (str): The name of the documentation section to open.
"""
url_dict = {
"LatticeElements": "https://impactx.readthedocs.io/en/latest/usage/python.html#lattice-elements",
"BeamDistributions": "https://impactx.readthedocs.io/en/latest/usage/python.html#initial-beam-distributions",
"pythonParameters": "https://impactx.readthedocs.io/en/latest/usage/python.html#general",
"space_charge_documentation": "https://impactx.readthedocs.io/en/latest/usage/parameters.html#space-charge",
"CSR": "https://impactx.readthedocs.io/en/latest/usage/parameters.html#coherent-synchrotron-radiation-csr",
"input_parameters": "https://impactx.readthedocs.io/en/latest/usage/python.html#general",
"lattice_configuration": "https://impactx.readthedocs.io/en/latest/usage/python.html#lattice-elements",
"distribution_parameters": "https://impactx.readthedocs.io/en/latest/usage/python.html#initial-beam-distributions",
"space_charge": "https://impactx.readthedocs.io/en/latest/usage/parameters.html#space-charge",
"csr": "https://impactx.readthedocs.io/en/latest/usage/parameters.html#coherent-synchrotron-radiation-csr",
}

url = url_dict.get(section_name)
Expand Down Expand Up @@ -154,16 +154,18 @@ def update_simulation_validation_status():
)

# Check for errors in input card
if state.npart_validation:
error_details.append(f"Number of Particles: {state.npart_validation}")
if state.kin_energy_validation:
error_details.append(f"Kinetic Energy: {state.kin_energy_validation}")
if state.bunch_charge_C_validation:
error_details.append(f"Bunch Charge: {state.bunch_charge_C_validation}")
if state.charge_qe_validation:
error_details.append(f"Ref. Particle Charge: {state.charge_qe_validation}")
if state.mass_MeV_validation:
error_details.append(f"Ref. Particle Mass: {state.mass_MeV}")
if state.npart_error_message:
error_details.append(f"Number of Particles: {state.npart_error_message}")
if state.kin_energy_error_message:
error_details.append(f"Kinetic Energy: {state.kin_energy_error_message}")
if state.bunch_charge_C_error_message:
error_details.append(f"Bunch Charge: {state.bunch_charge_C_error_message}")
if state.charge_qe_error_message:
error_details.append(
f"Ref. Particle Charge: {state.charge_qe_error_message}"
)
if state.mass_MeV_error_message:
error_details.append(f"Ref. Particle Mass: {state.mass_MeV_error_message}")

if state.selectedLatticeList == []:
error_details.append("LatticeListIsEmpty")
Expand Down
92 changes: 24 additions & 68 deletions src/python/impactx/dashboard/Input/inputParameters/inputMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from trame.widgets import vuetify

from ...Input.trameFunctions import TrameFunctions
from ...trame_setup import setup_server
from ..generalFunctions import generalFunctions
from .inputFunctions import InputFunctions
Expand Down Expand Up @@ -83,26 +84,19 @@ def __init__(self):
state.charge_qe = generalFunctions.get_default("charge_qe", "default_values")
state.mass_MeV = generalFunctions.get_default("mass_MeV", "default_values")

state.npart_validation = []
state.kin_energy_validation = []
state.bunch_charge_C_validation = []
state.mass_MeV_validation = []
state.charge_qe_validation = []
state.npart_error_message = []
state.kin_energy_error_message = []
state.bunch_charge_C_error_message = []
state.mass_MeV_error_message = []
state.charge_qe_error_message = []

def card(self):
"""
Creates UI content for beam properties.
"""

with vuetify.VCard(style="width: 340px; height: 350px"):
with vuetify.VCardTitle("Input Parameters"):
vuetify.VSpacer()
vuetify.VIcon(
"mdi-information",
style="color: #00313C;",
click=lambda: generalFunctions.documentation("pythonParameters"),
)
vuetify.VDivider()
TrameFunctions.input_section_header("Input Parameters")
with vuetify.VCardText():
with vuetify.VRow(classes="py-2"):
with vuetify.VCol(cols=6, classes="py-0"):
Expand All @@ -119,95 +113,57 @@ def card(self):
)
with vuetify.VRow(classes="my-2"):
with vuetify.VCol(cols=6, classes="py-0"):
vuetify.VTextField(
TrameFunctions.text_field(
label="Ref. Particle Charge",
v_model=("charge_qe",),
suffix=generalFunctions.get_default("charge_qe", "units"),
type="number",
step=generalFunctions.get_default("charge_qe", "steps"),
__properties=["step"],
dense=True,
error_messages=("charge_qe_validation",),
v_model_name="charge_qe",
change=(
ctrl.on_input_change,
"[$event, 'int','charge_qe','charge_qe_validation', ['non_zero']]",
"[$event, 'int','charge_qe','charge_qe_error_message', ['non_zero']]",
),
)
with vuetify.VCol(cols=6, classes="py-0"):
vuetify.VTextField(
TrameFunctions.text_field(
label="Ref. Particle Mass",
v_model=("mass_MeV",),
suffix=generalFunctions.get_default("mass_MeV", "units"),
type="number",
step=generalFunctions.get_default("mass_MeV", "steps"),
__properties=["step"],
dense=True,
error_messages=("mass_MeV_validation",),
v_model_name="mass_MeV",
change=(
ctrl.on_input_change,
"[$event, 'float','mass_MeV','mass_MeV_validation', ['positive']]",
"[$event, 'float','mass_MeV','mass_MeV_error_message', ['positive']]",
),
)
with vuetify.VRow(classes="my-0"):
with vuetify.VCol(cols=12, classes="py-0"):
vuetify.VTextField(
v_model=("npart",),
TrameFunctions.text_field(
label="Number of Particles",
error_messages=("npart_validation",),
v_model_name="npart",
change=(
ctrl.on_input_change,
"[$event, 'int','npart','npart_validation']",
"[$event, 'int','npart','npart_error_message']",
),
type="number",
step=generalFunctions.get_default("npart", "steps"),
__properties=["step"],
dense=True,
)
with vuetify.VRow(classes="my-2"):
with vuetify.VCol(cols=8, classes="py-0"):
vuetify.VTextField(
v_model=("kin_energy",),
TrameFunctions.text_field(
label="Kinetic Energy",
error_messages=("kin_energy_validation",),
v_model_name="kin_energy",
change=(
ctrl.on_input_change,
"[$event, 'float','kin_energy','kin_energy_validation']",
"[$event, 'float','kin_energy','kin_energy_error_message']",
),
type="number",
step=generalFunctions.get_default("kin_energy", "steps"),
__properties=["step"],
dense=True,
classes="mr-2",
)
with vuetify.VCol(cols=4, classes="py-0"):
vuetify.VSelect(
v_model=("kin_energy_unit",),
TrameFunctions.select(
label="Unit",
items=(
generalFunctions.get_default(
"kin_energy_unit_list", "default_values"
),
),
v_model_name="kin_energy_unit",
change=(ctrl.kin_energy_unit_change, "[$event]"),
dense=True,
)
with vuetify.VRow(classes="my-2"):
with vuetify.VCol(cols=12, classes="py-0"):
vuetify.VTextField(
TrameFunctions.text_field(
label="Bunch Charge",
v_model=("bunch_charge_C",),
error_messages=("bunch_charge_C_validation",),
v_model_name="bunch_charge_C",
change=(
ctrl.on_input_change,
"[$event, 'float','bunch_charge_C','bunch_charge_C_validation']",
),
type="number",
step=generalFunctions.get_default(
"bunch_charge_C", "steps"
),
__properties=["step"],
dense=True,
suffix=generalFunctions.get_default(
"bunch_charge_C", "units"
"[$event, 'float','bunch_charge_C','bunch_charge_C_error_message']",
),
)
Loading
Loading