Skip to content

Commit

Permalink
rename lattice element default variables to snake case
Browse files Browse the repository at this point in the history
  • Loading branch information
proy30 committed Jan 5, 2025
1 parent 398ba0d commit 7daf6e8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/python/impactx/dashboard/Input/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class DashboardDefaults:
}

LATTICE = {
"selectedLatticeList": [],
"selectedLattice": None,
"selected_lattice": None,
"selected_lattice_list": [],
}

SPACE_CHARGE = {
Expand Down
6 changes: 3 additions & 3 deletions src/python/impactx/dashboard/Input/generalFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def update_simulation_validation_status():
)

# Check for errors in lattice parameters
for lattice in state.selectedLatticeList:
for lattice in state.selected_lattice_list:
for param in lattice["parameters"]:
if param["parameter_error_message"]:
error_details.append(
Expand All @@ -165,7 +165,7 @@ def update_simulation_validation_status():
if state.mass_MeV_validation:
error_details.append(f"Ref. Particle Mass: {state.mass_MeV}")

if state.selectedLatticeList == []:
if state.selected_lattice_list == []:
error_details.append("LatticeListIsEmpty")

# Check for errors in CSR parameters
Expand Down Expand Up @@ -360,7 +360,7 @@ def reset_lattice_configuration_parameters():
Resets lattice inputs to defaults.
"""
state.update(DashboardDefaults.LATTICE)
state.selectedLatticeList = []
state.selected_lattice_list = []

@staticmethod
def reset_space_charge_parameters():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
# Default
# -----------------------------------------------------------------------------

state.selectedLattice = generalFunctions.get_default(
"selectedLattice", "default_values"
state.selected_lattice = generalFunctions.get_default(
"selected_lattice", "default_values"
)
state.selectedLatticeList = []
state.selected_lattice_list = []
state.nsliceDefaultValue = generalFunctions.get_default("n_slice", "default_values")

# -----------------------------------------------------------------------------
Expand All @@ -51,13 +51,13 @@ def add_lattice_element():
:return: dictionary representing the added lattice element with its parameters.
"""

selectedLattice = state.selectedLattice
selectedLatticeParameters = state.listOfLatticeElementParametersAndDefault.get(
selectedLattice, []
selected_lattice = state.selected_lattice
selected_lattice_parameters = state.listOfLatticeElementParametersAndDefault.get(
selected_lattice, []
)

selectedLatticeElement = {
"name": selectedLattice,
selected_lattice_element = {
"name": selected_lattice,
"parameters": [
{
"parameter_name": parameter[0],
Expand All @@ -67,13 +67,13 @@ def add_lattice_element():
parameter[1], parameter[2]
),
}
for parameter in selectedLatticeParameters
for parameter in selected_lattice_parameters
],
}

state.selectedLatticeList.append(selectedLatticeElement)
state.selected_lattice_list.append(selected_lattice_element)
generalFunctions.update_simulation_validation_status()
return selectedLatticeElement
return selected_lattice_element


def update_latticeElement_parameters(
Expand All @@ -83,13 +83,13 @@ def update_latticeElement_parameters(
Updates parameter value and includes error message if user input is not valid
"""

for param in state.selectedLatticeList[index]["parameters"]:
for param in state.selected_lattice_list[index]["parameters"]:
if param["parameter_name"] == parameterName:
param["parameter_default_value"] = parameterValue
param["parameter_error_message"] = parameterErrorMessage

generalFunctions.update_simulation_validation_status()
state.dirty("selectedLatticeList")
state.dirty("selected_lattice_list")


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -127,7 +127,7 @@ def lattice_elements():
"""

elements_list = []
for latticeElement in state.selectedLatticeList:
for latticeElement in state.selected_lattice_list:
latticeElement_name = latticeElement["name"]
parameters = parameter_input_checker_for_lattice(latticeElement)

Expand All @@ -142,31 +142,31 @@ def lattice_elements():
# -----------------------------------------------------------------------------


@state.change("selectedLatticeList")
def on_selectedLatticeList_change(selectedLatticeList, **kwargs):
if selectedLatticeList == []:
@state.change("selected_lattice_list")
def on_selected_lattice_list_change(selected_lattice_list, **kwargs):
if selected_lattice_list == []:
state.isSelectedLatticeListEmpty = "Please select a lattice element"
generalFunctions.update_simulation_validation_status()
else:
state.isSelectedLatticeListEmpty = ""


@state.change("selectedLattice")
def on_lattice_element_name_change(selectedLattice, **kwargs):
@state.change("selected_lattice")
def on_lattice_element_name_change(selected_lattice, **kwargs):
return


@ctrl.add("add_latticeElement")
def on_add_lattice_element_click():
selectedLattice = state.selectedLattice
selected_lattice = state.selected_lattice

if selectedLattice not in state.listOfLatticeElements:
if selected_lattice not in state.listOfLatticeElements:
state.isSelectedLatticeListEmpty = (
f"Lattice element '{selectedLattice}' does not exist."
f"Lattice element '{selected_lattice}' does not exist."
)
else:
add_lattice_element()
state.dirty("selectedLatticeList")
state.dirty("selected_lattice_list")


@ctrl.add("updateLatticeElementParameters")
Expand All @@ -183,28 +183,28 @@ def on_lattice_element_parameter_change(

@ctrl.add("deleteLatticeElement")
def on_delete_LatticeElement_click(index):
state.selectedLatticeList.pop(index)
state.dirty("selectedLatticeList")
state.selected_lattice_list.pop(index)
state.dirty("selected_lattice_list")


@ctrl.add("move_latticeElementIndex_up")
def on_move_latticeElementIndex_up_click(index):
if index > 0:
state.selectedLatticeList[index], state.selectedLatticeList[index - 1] = (
state.selectedLatticeList[index - 1],
state.selectedLatticeList[index],
state.selected_lattice_list[index], state.selected_lattice_list[index - 1] = (
state.selected_lattice_list[index - 1],
state.selected_lattice_list[index],
)
state.dirty("selectedLatticeList")
state.dirty("selected_lattice_list")


@ctrl.add("move_latticeElementIndex_down")
def on_move_latticeElementIndex_down_click(index):
if index < len(state.selectedLatticeList) - 1:
state.selectedLatticeList[index], state.selectedLatticeList[index + 1] = (
state.selectedLatticeList[index + 1],
state.selectedLatticeList[index],
if index < len(state.selected_lattice_list) - 1:
state.selected_lattice_list[index], state.selected_lattice_list[index + 1] = (
state.selected_lattice_list[index + 1],
state.selected_lattice_list[index],
)
state.dirty("selectedLatticeList")
state.dirty("selected_lattice_list")


@ctrl.add("nsliceDefaultChange")
Expand Down Expand Up @@ -259,7 +259,7 @@ def card():
with vuetify.VCol(cols=10):
vuetify.VCombobox(
label="Select Accelerator Lattice",
v_model=("selectedLattice", None),
v_model=("selected_lattice", None),
items=("listOfLatticeElements",),
error_messages=("isSelectedLatticeListEmpty",),
dense=True,
Expand Down Expand Up @@ -295,7 +295,7 @@ def card():
vuetify.VDivider()
with vuetify.VContainer(fluid=True):
with vuetify.VRow(
v_for="(latticeElement, index) in selectedLatticeList",
v_for="(latticeElement, index) in selected_lattice_list",
align="center",
no_gutters=True,
style="min-width: 1500px;",
Expand Down Expand Up @@ -362,7 +362,7 @@ def dialog_lattice_elementList():
vuetify.VDivider()
with vuetify.VContainer(fluid=True):
with vuetify.VRow(
v_for="(latticeElement, index) in selectedLatticeList",
v_for="(latticeElement, index) in selected_lattice_list",
align="center",
no_gutters=True,
style="min-width: 1500px;",
Expand Down
2 changes: 1 addition & 1 deletion src/python/impactx/dashboard/Toolbar/exportTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def build_lattice_list():
for key, value in parameter_input_checker_for_lattice(element).items()
)
+ ")"
for element in state.selectedLatticeList
for element in state.selected_lattice_list
)

return f"lattice_configuration = [\n {lattice_elements}\n]"
Expand Down

0 comments on commit 7daf6e8

Please sign in to comment.