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

Collective Effects Config in Dashboard #690

Merged
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
d8f458c
Added initial space charge UI with basic compatibility with simulation
proy30 Aug 29, 2024
bc6ac53
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 29, 2024
245ca67
Connected max_level and poisson_solver to simulation
proy30 Aug 30, 2024
0fd00f4
prob_relative simulation functionality added
proy30 Aug 30, 2024
6de4c5d
Update code structuring
proy30 Aug 30, 2024
deab4ff
rename variables
proy30 Aug 31, 2024
8ac0134
Moved input cards
proy30 Aug 31, 2024
87f6117
code structure adjustment
proy30 Aug 31, 2024
6dd9df2
Added space charge documentation
proy30 Aug 31, 2024
a4967d3
Added CSR configuration
proy30 Aug 31, 2024
cc7796c
Rename 'CSR Configuration' to 'CSR' for UI and code
proy30 Aug 31, 2024
4d55002
Connect csr_bins to simulation
proy30 Aug 31, 2024
26658e8
Updated UI look and minor code structure
proy30 Aug 31, 2024
2dd9313
Add initial validation for Space Charge
proy30 Sep 1, 2024
8c4d341
update simulation code & change Vcombobox to vSelect
proy30 Sep 1, 2024
78235b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 31, 2024
fc9cd49
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 1, 2024
fcdb6f3
Updated default values
proy30 Sep 3, 2024
000d02c
Format update
proy30 Sep 5, 2024
db5940a
Minor updates
proy30 Sep 5, 2024
8cae249
Added initial space charge UI with basic compatibility with simulation
proy30 Aug 29, 2024
94ebbde
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 29, 2024
ed7e2c8
prob_relative simulation functionality added
proy30 Aug 30, 2024
c6fa4bb
Update code structuring
proy30 Aug 30, 2024
ba4ae18
rename variables
proy30 Aug 31, 2024
a7c879b
Moved input cards
proy30 Aug 31, 2024
0d1fb87
Added space charge documentation
proy30 Aug 31, 2024
b5df646
Add initial validation for Space Charge
proy30 Sep 1, 2024
eebe05e
update simulation code & change Vcombobox to vSelect
proy30 Sep 1, 2024
c2e489e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 31, 2024
595db82
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 1, 2024
76a70ac
Revert "Added IDs to UI components"
proy30 Sep 6, 2024
fe0ec58
Removed duiplicated UI cards
proy30 Sep 6, 2024
e9f3daa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 6, 2024
104fc61
Formatting change and remove duplicate code
proy30 Sep 13, 2024
60824ee
Update default n_cell
proy30 Sep 13, 2024
7f78b96
particle_shape placed in CSR
proy30 Sep 23, 2024
41639c4
Added blocking_factor to UI, no functionality
proy30 Sep 25, 2024
c58057f
Added blocking_factor defaults
proy30 Sep 25, 2024
74e0680
Added blocking_factor functionality
proy30 Sep 26, 2024
2e17299
Update default values for space charge
proy30 Sep 27, 2024
12c8681
Updated prob_relative validation
proy30 Sep 27, 2024
86e4c07
Connected blocking_factor to simulation
proy30 Sep 27, 2024
f94bcdc
Add multigrid-specific numerical options
proy30 Sep 28, 2024
5b0327c
Adjust UI formatting
proy30 Oct 3, 2024
dcdb8fe
Update export_template for space charge and csr
proy30 Oct 10, 2024
c00c91f
Updated default for blocking_factor xyz
proy30 Oct 18, 2024
774b365
Fixed simulation.py after merge
proy30 Oct 22, 2024
ccef469
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 24, 2024
6cadc74
Merge remote-tracking branch 'mainline/development' into dashboard/sp…
proy30 Oct 31, 2024
0397f60
Merge branch 'dashboard/space_charge_configuration' of github.com:pro…
proy30 Oct 31, 2024
5d1d771
Update validation for n_cell and blocking_factor
proy30 Nov 7, 2024
2afaa13
Updated ui format
proy30 Nov 7, 2024
6a60bec
Add csr validation
proy30 Nov 7, 2024
571ebd9
Update simulation station function
proy30 Nov 7, 2024
f6eea78
Merge branch 'development' into dashboard/space_charge_configuration
proy30 Nov 7, 2024
8233f2c
connect multigrid advanced settings to simulation
proy30 Nov 20, 2024
b5e2442
Merge remote-tracking branch 'mainline/development' into dashboard/sp…
proy30 Nov 21, 2024
a7396eb
add space
proy30 Nov 21, 2024
72c101d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
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
66 changes: 66 additions & 0 deletions src/python/impactx/dashboard/Input/csrConfiguration/csrMain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from trame.widgets import vuetify

from ...trame_setup import setup_server
from ..generalFunctions import generalFunctions

server, state, ctrl = setup_server()

# -----------------------------------------------------------------------------
# Default State Variables
# -----------------------------------------------------------------------------

state.csr_bins = 150
state.csr_bins_error_message = ""

# -----------------------------------------------------------------------------
#
# -----------------------------------------------------------------------------


@state.change("csr_bins")
def on_csr_bins_change(csr_bins, **kwargs):
error_message = generalFunctions.validate_against(csr_bins, "int", ["positive"])
state.csr_bins_error_message = error_message
generalFunctions.update_simulation_validation_status()


# -----------------------------------------------------------------------------
# UI
# -----------------------------------------------------------------------------


class csrConfiguration:
@staticmethod
def card():
"""
Creates UI content for CSR.
"""

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()
with vuetify.VCardText():
with vuetify.VRow(classes="my-0"):
with vuetify.VCol(classes="py-0"):
vuetify.VSelect(
label="Particle Shape",
v_model=("particle_shape",),
items=([1, 2, 3],),
dense=True,
)
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,
)
57 changes: 44 additions & 13 deletions src/python/impactx/dashboard/Input/generalFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ def documentation(section_name):
Opens a tab to the specified section link in the documentation.
:param section_name (str): The name of the documentation section to open.
"""

if section_name == "LatticeElements":
url = "https://impactx.readthedocs.io/en/latest/usage/python.html#lattice-elements"
elif section_name == "BeamDistributions":
url = "https://impactx.readthedocs.io/en/latest/usage/python.html#initial-beam-distributions"
elif section_name == "pythonParameters":
url = "https://impactx.readthedocs.io/en/latest/usage/python.html#general"
else:
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",
}

url = url_dict.get(section_name)
if url is None:
raise ValueError(f"Invalid section name: {section_name}")

if "WSL_DISTRO_NAME" in os.environ:
Expand Down Expand Up @@ -104,11 +106,11 @@ def validate_against(input_value, value_type, additional_conditions=None):
if errors == [] and additional_conditions:
for condition in additional_conditions:
if condition == "non_zero" and value == 0:
errors.append("Must be non-zero")
if condition == "positive" and value <= 0:
errors.append("Must be positive")
if condition == "negative" and value >= 0:
errors.append("Must be negative")
errors.append("Must be non-zero.")
if condition == "positive" and value < 0:
errors.append("Must be positive.")
if condition == "negative" and value > 0:
errors.append("Must be negative.")

return errors

Expand Down Expand Up @@ -151,6 +153,35 @@ def update_simulation_validation_status():
if state.selectedLatticeList == []:
error_details.append("LatticeListIsEmpty")

# Check for errors in CSR parameters
if state.csr_bins_error_message:
error_details.append(f"CSR Bins: {state.csr_bins_error_message}")

# Check for errors in Space Charge parameters
if state.space_charge:
# n_cell parameters
for direction in ["x", "y", "z"]:
n_cell_error = getattr(state, f"error_message_n_cell_{direction}")
if n_cell_error:
error_details.append(f"n_cell_{direction}: {n_cell_error}")

# Blocking factor parameters
for direction in ["x", "y", "z"]:
blocking_factor_error = getattr(
state, f"error_message_blocking_factor_{direction}"
)
if blocking_factor_error:
error_details.append(
f"blocking_factor_{direction}: {blocking_factor_error}"
)

# Prob Relative Fields
for index, field in enumerate(state.prob_relative_fields):
if field["error_message"]:
error_details.append(
f"prob_relative[{index}]: {field['error_message']}"
)

state.disableRunSimulationButton = bool(error_details)

# -----------------------------------------------------------------------------
Expand Down
19 changes: 13 additions & 6 deletions src/python/impactx/dashboard/Input/inputParameters/inputMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,19 @@ def card(self):
)
vuetify.VDivider()
with vuetify.VCardText():
vuetify.VCombobox(
v_model=("particle_shape",),
label="Particle Shape",
items=([1, 2, 3],),
dense=True,
)
with vuetify.VRow(classes="py-2"):
with vuetify.VCol(cols=6, classes="py-0"):
vuetify.VCheckbox(
label="Space Charge",
v_model=("space_charge", False),
dense=True,
)
with vuetify.VCol(cols=6, classes="py-0"):
vuetify.VCheckbox(
label="CSR",
v_model=("csr", False),
dense=True,
)
with vuetify.VRow(classes="my-2"):
with vuetify.VCol(cols=6, classes="py-0"):
vuetify.VTextField(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from ...trame_setup import setup_server
from ..generalFunctions import generalFunctions

server, state, ctrl = setup_server()

# -----------------------------------------------------------------------------
# Functions
# -----------------------------------------------------------------------------


class SpaceChargeFunctions:
@staticmethod
def validate_prob_relative_fields(index, prob_relative_value):
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
"""
This function checks specific validation requirements
for prob_relative_fields.
:param index: The index of the prob_relative_field modified.
:param prob_relative_value: The numerical value entered by the user.
:return: An error message. An empty string if there is no error.
"""
error_message = ""

try:
prob_relative_value = float(prob_relative_value)
poisson_solver = state.poisson_solver

if index == 0:
if poisson_solver == "multigrid":
if prob_relative_value < 3:
error_message = "Must be greater than 3."
elif poisson_solver == "fft":
if prob_relative_value <= 1:
error_message = "Must be greater than 1."
else:
previous_value = float(state.prob_relative[index - 1])
if prob_relative_value >= previous_value:
error_message = (
f"Must be less than previous value ({previous_value})."
)
else:
if prob_relative_value <= 1:
error_message = "Must be greater than 1."
except ValueError:
error_message = "Must be a float."

return error_message

@staticmethod
def validate_n_cell_and_blocking_factor(direction):
"""
Validation function for n_cell and blocking_factor parameters.
"""
n_cell_value = getattr(state, f"n_cell_{direction}", None)
blocking_factor_value = getattr(state, f"blocking_factor_{direction}", None)

n_cell_errors = generalFunctions.validate_against(n_cell_value, "int")
blocking_factor_errors = generalFunctions.validate_against(
blocking_factor_value, "int", ["non_zero", "positive"]
)

setattr(state, f"error_message_n_cell_{direction}", "; ".join(n_cell_errors))
setattr(
state,
f"error_message_blocking_factor_{direction}",
"; ".join(blocking_factor_errors),
)

if not n_cell_errors and not blocking_factor_errors:
n_cell_value = int(n_cell_value)
blocking_factor_value = int(blocking_factor_value)
if n_cell_value % blocking_factor_value != 0:
setattr(
state,
f"error_message_n_cell_{direction}",
"Must be a multiple of blocking factor.",
)
Loading