Skip to content
Open
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3fad621
place function for lattice parser in own file
proy30 May 31, 2025
aad51c8
break parse_lattice_elements into smaller helper functions
proy30 May 31, 2025
f9af77f
refactor: parse_cleaned_lattice
proy30 May 31, 2025
ea1e80d
add: collect_lattice_operations
proy30 May 31, 2025
37052e6
add: inline_element_variables
proy30 May 31, 2025
cffe7ed
add: flatten_variable_definition
proy30 Jun 1, 2025
5fbdf67
rebase for updating parse_cleaned_lattice
proy30 Jun 1, 2025
e7e10a1
update: parse_lattice_elements to utilize helper functions
proy30 Jun 1, 2025
af1b7c5
update naming: flatten variable list def
proy30 Jun 1, 2025
42de35a
add test: run/fodo.py
proy30 Jun 1, 2025
b3bc78e
add test: cyclotron
proy30 Jun 1, 2025
b527496
add test: dogleg
proy30 Jun 1, 2025
cce57cb
change if/else block to 'match'
proy30 Jun 1, 2025
0ae6eee
change static class to instance-based
proy30 Jun 1, 2025
ff0916f
fix indentation for match
proy30 Jun 1, 2025
8789634
fix: parsing blocking_factor
proy30 Jun 1, 2025
3b08807
update debug print statement for flatten
proy30 Jun 1, 2025
d0bf944
improve: flatten_variable_list_definitions
proy30 Jun 1, 2025
fd37c15
update collect_lattice_operations
proy30 Jun 1, 2025
87e3b72
rename flatton function name
proy30 Jun 1, 2025
f449595
add tests: expanding_fft_lattice
proy30 Jun 1, 2025
61a2eb5
update function name
proy30 Jun 1, 2025
af2f50a
add .reverse() functionality/chicane test
proy30 Jun 1, 2025
7068e92
add tests: apochromatic & expanding_fft - lattice builds
proy30 Jun 1, 2025
01a3039
add docstring to class
proy30 Jun 1, 2025
13271e7
update typends
proy30 Jun 1, 2025
ebdf01b
add: caching for saving recursive time
proy30 Jun 1, 2025
240ca26
separately find used lattice variables
proy30 Jun 3, 2025
733b0f7
update: docstrings/comments
proy30 Jun 3, 2025
41d9d85
store file_content in lattice class' initialization
proy30 Jun 3, 2025
eeaa9d1
add docstring
proy30 Jun 3, 2025
58e0204
cache content hash
proy30 Jun 3, 2025
10373fc
fix parser - distribution funciton
proy30 Jun 28, 2025
105e646
delete wrongly added file from rebase
proy30 Jun 28, 2025
49a95f4
revise naming for lattice vars/class/functions
proy30 Jun 28, 2025
2cd0f48
simplify
proy30 Jun 28, 2025
adb9618
support .revsese()
proy30 Sep 20, 2025
3ea0c92
fix/cleanup
proy30 Sep 20, 2025
f226783
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 22, 2025
583c6d3
relocate get_impactx_dir function
proy30 Sep 25, 2025
6833a6c
duplicate get_impactx_root_dir in tests utils
proy30 Sep 25, 2025
3c04630
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 25, 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
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def update_length_statistics() -> None:
@staticmethod
def update_element_counts() -> dict[str, int]:
"""
Computes the element counts in the lattice list.
Computes the element counts in the lattice list
and stores them in descending order by count.

:return: Dictionary of element names and their counts, sorted by count descending.
:return: Dictionary of element counts indexed by element name.
"""
counts = {}
for element in state.selected_lattice_list:
Expand Down
18 changes: 9 additions & 9 deletions src/python/impactx/dashboard/Toolbar/examples_loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

DASHBOARD_EXAMPLES = {
"fodo/run_fodo.py",
# "chicane/run_chicane_csr.py",
# "fodo_space_charge/run_fodo_envelope_sc.py",
# "apochromatic/run_apochromatic.py",
# "kurth/run_kurth_10nC_periodic.py",
# "expanding_beam/run_expanding_fft.py",
# "expanding_beam/run_expanding_envelope.py",
# "iota_lattice/run_iotalattice.py",
# "cyclotron/run_cyclotron.py",
# "dogleg/run_dogleg.py",
"chicane/run_chicane_csr.py",
"fodo_space_charge/run_fodo_envelope_sc.py",
"apochromatic/run_apochromatic.py",
# "kurth/run_kurth_10nC_periodic.py", - running into recursion issues
"expanding_beam/run_expanding_fft.py",
"expanding_beam/run_expanding_envelope.py",
"iota_lattice/run_iotalattice.py",
"cyclotron/run_cyclotron.py",
"dogleg/run_dogleg.py",
}


Expand Down
Empty file.
64 changes: 32 additions & 32 deletions src/python/impactx/dashboard/Toolbar/file_imports/python/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def parse_single_inputs(content: str) -> dict:
pattern_match = re.search(pattern.format(parameter_name), content)
if pattern_match:
value = ast.literal_eval(pattern_match.group(1))

if parameter_name == "space_charge" and isinstance(value, bool):
value = str(value).lower()

reference_dictionary[parameter_name] = value
break

Expand All @@ -61,8 +65,14 @@ def parse_single_inputs(content: str) -> dict:
r"\bkin_energy_MeV\s*=\s*([^#\n]+)", content
)
if kin_energy_pattern_match:
kin_energy_value = kin_energy_pattern_match.group(1)
reference_dictionary["kin_energy_on_ui"] = kin_energy_value
kin_energy_value = kin_energy_pattern_match.group(1).strip()

try:
parsed_value = ast.literal_eval(kin_energy_value)
except (ValueError, SyntaxError):
parsed_value = reference_dictionary.get("kin_energy_MeV")

reference_dictionary["kin_energy_on_ui"] = parsed_value

return reference_dictionary

Expand All @@ -71,11 +81,24 @@ def parse_list_inputs(content: str) -> dict:
"""
Parses list-based simulation parameters from the simulation file content.

Some of the dashboard inputs are lists, such as n_cell = [16, 16, 16].
We have to look inside of the brackets to retrieve the individual values.

:param content: The content of the ImpactX simulation file.
"""
dictionary = {}
list_inputs = ["n_cell", "prob_relative"]
list_parsing = "{} = (\\[.*?\\])"
list_inputs = [
"n_cell",
"prob_relative",
"blocking_factor_x",
"blocking_factor_y",
"blocking_factor_z",
]

# The below regex will capture everything inside of the brackets
# it assumes that the list will be placed in a single line (not multiple).
# Example: n_cell = [16, 16, 16] --> [16, 16, 16]
list_parsing = r"{}\s*=\s*(\[[^\]]*\])"

for input_name in list_inputs:
match = re.search(list_parsing.format(input_name), content)
Expand All @@ -86,9 +109,13 @@ def parse_list_inputs(content: str) -> dict:
for i, dim in enumerate(["x", "y", "z"]):
dictionary[f"n_cell_{dim}"] = values[i]

if input_name == "prob_relative":
elif input_name == "prob_relative":
dictionary["prob_relative"] = values

elif input_name.startswith("blocking_factor_"):
# Convert [16] -> 16
dictionary[input_name] = values[0]

return dictionary

@staticmethod
Expand Down Expand Up @@ -134,33 +161,6 @@ def extract_parameters(distribution_type, parsing_pattern):

return dictionary

@staticmethod
def parse_lattice_elements(content: str) -> dict:
"""
Parses lattice elements from the simulation file content.

:param content: The content of the ImpactX simulation file.
"""

dictionary = {"lattice_elements": []}
used_variables = set()

lattice_elements = re.findall(r"elements\.(\w+)\((.*?)\)", content)

for element_name, element_parameter in lattice_elements:
element = {"element": element_name, "parameters": {}}

parameter_pairs = re.findall(r"(\w+)=([^,\)]+)", element_parameter)
for parameter_name, parameter_value in parameter_pairs:
parameter_value_cleaned = parameter_value.strip("'\"")
element["parameters"][parameter_name] = parameter_value_cleaned
used_variables.add(parameter_value_cleaned)

dictionary["lattice_elements"].append(element)

dictionary["used_lattice_variables"] = used_variables
return dictionary

@staticmethod
def parse_variables(content: str, used_vars: set) -> dict:
"""
Expand Down
Loading
Loading