Skip to content

Conversation

@proy30
Copy link
Member

@proy30 proy30 commented Sep 15, 2025

A branch that was worked on primarily during the summer months.

In cleanup processes now..

  • Support a wider range of impactX examples
  • Add test_lattice_stats
    • By adding this test file, we test both the lattice statistics and indirectly the updated python parser. The statistics will reflect what the parser inputs into the dashboard.
  • Support sim.lattice.append()
  • Support sim.lattice.extend()
  • Support sim.lattice.reverse()

_Note: As we rely on regex for the parser, it is "breakable", depending on the type of input files structures it receives. However, it is important to note that any of the impactX examples inside of the dashboard is completely supported by the parser.

@proy30 proy30 added the component: dashboard our browser based trame dashboard label Sep 15, 2025
@proy30 proy30 mentioned this pull request Sep 15, 2025
3 tasks
@proy30 proy30 changed the title [Draft] Dashboard: update python parser [WIP] Dashboard: update python parser Sep 19, 2025
will need it's own file to handle all the capabilities
make more readable and clearly layout its purpose
will need to handle variable references
does not affect performance, simpler to read
we just need the numerical number and not the brackets
do a greedy search of the parenthesis to stop at the last ')' in the line.

We need this because sim.extend() can have a element.(..) stored inside, and stopped at the first ')' is premature
replace_variables_to_elements -> replace_variables
update how lattice element counts are stored

add lattice stats test

expand on testdata/examples

cleanup/fix

make imports relative

fix

add tests

simplify

simplify parse_list_inputs

more comments/docstring

simplify more

cleanup tests: only keep 1-2 hardcoded tests to validate python parser
found the culprit - the built in .reverse() that was being used emitted a reversed copy into the lattice instead of mutating the variable itself, and caused an extra set of elements to appear. we needed the reversed copy to be the only thing pushed to the elements, not the reversed copy AND the non-reversed
@proy30 proy30 force-pushed the dashboard/update_python_parser branch from 1c7e153 to 8569ccb Compare September 21, 2025 03:50
@proy30 proy30 changed the title [WIP] Dashboard: update python parser Dashboard: update python parser Sep 22, 2025
modify test_python_import's lattice section testing

test for correct population of element names and a single element parameter's value

I believe this is sufficient enough for testing how the lattice populates when importing from a file

fix test_lattice_stats and cleanup

fix examples

show examples

cleanup

[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

improvements
@proy30 proy30 force-pushed the dashboard/update_python_parser branch from 9b09ad1 to 3ea0c92 Compare September 22, 2025 02:48
@proy30 proy30 requested review from ax3l and cemitch99 September 22, 2025 15:11
Copy link
Member

@cemitch99 cemitch99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this PR! When I tried to pull this and initialize dashboard I received the attached error--it appears to be related to the previous PR #876. Did you encounter this at any point?

Dashboard_error_22Sept2025

Note: proy30 is currently working to address this, and this PR shouldn't be merged until then.

proy30 and others added 3 commits September 24, 2025 19:27
this funciton is needed by both the source code and the testing files. unsure where a good single location for the function would be without any import issues.
numeric_input = GeneralFunctions.convert_to_numeric(current_input)
setattr(state, state_name, numeric_input)

def get_impactx_root_dir() -> Path | None:

Check notice

Code scanning / CodeQL

First parameter of a method is not named 'self' Note

Normal methods should have at least one parameter (the first of which should be 'self').
@proy30
Copy link
Member Author

proy30 commented Sep 25, 2025

Hi @cemitch99 , would you please be able to try again? I was unable to replicate my environment as yours, so I am not fully positive if the solution is now fixed or not.

@cemitch99
Copy link
Member

Hi @proy30 . Thanks for the recent changes! I tried again, using impactx-dashboard, and I see the same error. A similar error appears if I launch within Jupyter. There could be an issue that is unique to my environment.

However, if I launch the dashboard using python -m dashboard within src/python/impactx, then everything works perfectly.

@proy30
Copy link
Member Author

proy30 commented Sep 25, 2025

@cemitch99 Thank you for letting me know. I have to investigate the issue further and will update again.

@ax3l
Copy link
Member

ax3l commented Oct 13, 2025

Fix in #1179

Comment on lines +151 to +154
current_directory = Path(__file__).resolve()
root_dir = None

for parent_dir in current_directory.parents:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@proy30 don't you already have a method for this from #876? :)

Please merge development and check if this is duplicate now :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping @proy30 don't you already have a method for this from #876? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ax3l Thank you for the ping. Yes, there is a duplicate function in both this PR (#1140) and #876.

At first, this was done intentionally when added in because (trying to recall correctly) it was difficult to have the pytests (from the directory impactx/tests/python/dashboard/utils.py call to the function in directory impactx/src/python/impactx/dashboard/Input/utils.py.

Any suggestions for where the function get_impactx_root_dir should be placed? It needs to be accessed by both the dashboard and the dashboard tests. Unsure if, in the future, the functionality could be used elsewhere where the root impactx directory is needed.

Comment on lines +155 to +156
if parent_dir.name == "impactx" and (parent_dir / ".git").is_dir():
root_dir = parent_dir # keep going until we reach the highest match
Copy link
Member

@ax3l ax3l Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@proy30 it looks to me like you are quite often assuming that ImpactX is used from its source tree. This is, outside of development, not the case.

We install ImpactX like this:

cmake -S . -B build -DImpactX_PYTHON=ON
cmake --build build -j 4 --target pip_install

which copies things outside of the source tree. Thus, looking for a .git/ directory is not a logic that will work when ImpactX was installed/deployed/is used in production.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ax3l Thank you for pointing this out. Will add a commit to work well in both development and non-development

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will utilise the old path and logic from get_impactx_path() that you mention in the comment below.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! :)

Retrieve the selected ImpactX example file and populate the UI with its values.
"""

impactx_directory = DashboardExamplesLoader.get_impactx_path()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep using the old path and logic from get_impactx_path(), I fixed the logic in #1179

Comment on lines +32 to +35
for parent_dir in current_directory.parents:
if parent_dir.name == "impactx" and (parent_dir / ".git").is_dir():
root_dir = parent_dir # keep going until we reach the highest match
return root_dir
Copy link
Member

@ax3l ax3l Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, please don't add this .git/ path based logic.

It should work if you rely on the one I fixed in #1179

@ax3l
Copy link
Member

ax3l commented Nov 10, 2025

@proy30 let me know when you are ready for me to review the updates discussed above :) 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: dashboard our browser based trame dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants