Skip to content

Conversation

AlexanderSinn
Copy link
Member

Add option to allow for evaluating Parser expressions for debugging.
Examples:

Input:
parser.debug_print = "10*x + y" "x=[0,9,10]" "y=2"

Output:
Parser Debug Print "10*x + y" = [2, 12, 22, 32, 42, 52, 62, 72, 82, 92]
Input:
parser.debug_print = "plasma.radius"

Output:
Parser Debug Print "plasma.radius" = 0.001
Input:
parser.debug_print = "1000*x + 100*y + 10*z + t" "x=[1,2,2]" "y=[3,4,2]" "z=[5,6,2]" "t=[7,8,2]"

Output:
Parser Debug Print "1000*x + 100*y + 10*z + t" = [[[[1357, 2357],
[1457, 2457]],

[[1367, 2367],
[1467, 2467]]],


[[[1358, 2358],
[1458, 2458]],

[[1368, 2368],
[1468, 2468]]]]
Input:
parser.debug_print = "{plasma.density(x,y,z)}" "x=0" "y=0" "z=0"

Output:
Parser Debug Print "ne" = 2e+20
Input:
parser.debug_print = "
    avg_curr = abs(-8e-9 * clight / bunch_length1);
    head_curr = 0.1e3;
    diff_curr = avg_curr - head_curr;
    a = (diff_curr / (bunch_length1/2)) / avg_curr;
    b = 50e-7;
    ylo = -bunch_length1/2;
    yhi = bunch_length1/2;
    lower = b*(sqrt(pi/2)*(1 - a*z)*erf(((1/sqrt(2))*(ylo - z))/b) + a*b*exp(-(0.5*(ylo - z)^2)/b^2));
    upper = b*(sqrt(pi/2)*(1 - a*z)*erf(((1/sqrt(2))*(yhi - z))/b) + a*b*exp(-(0.5*(yhi - z)^2)/b^2));
    upper - lower" "bunch_length1=1050e-6" "z=[-1.5e-3,1.5e-3,100]"

Output:
Parser Debug Print "
    avg_curr = abs(-8e-9 * clight / bunch_length1);
    head_curr = 0.1e3;
    diff_curr = avg_curr - head_curr;
    a = (diff_curr / (bunch_length1/2)) / avg_curr;
    b = 50e-7;
    ylo = -bunch_length1/2;
    yhi = bunch_length1/2;
    lower = b*(sqrt(pi/2)*(1 - a*z)*erf(((1/sqrt(2))*(ylo - z))/b) + a*b*exp(-(0.5*(ylo - z)^2)/b^2));
    upper = b*(sqrt(pi/2)*(1 - a*z)*erf(((1/sqrt(2))*(yhi - z))/b) + a*b*exp(-(0.5*(yhi - z)^2)/b^2));
    upper - lower" = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.310698783e-17, 3.532722117e-06, 2.394688371e-05, 2.325514836e-05, 2.256340597e-05, 2.187166359e-05, 2.11799212e-05, 2.048817881e-05, 1.979643643e-05, 1.910469404e-05, 1.841295166e-05, 1.772120927e-05, 1.702946688e-05, 1.63377245e-05, 1.564598211e-05, 1.495423972e-05, 1.426249734e-05, 1.357075495e-05, 1.287901257e-05, 1.218727018e-05, 1.149552779e-05, 1.080378541e-05, 1.011204302e-05, 9.420300635e-06, 8.728558249e-06, 8.036815863e-06, 7.345073477e-06, 6.653331091e-06, 5.961588704e-06, 5.269846318e-06, 4.578103932e-06, 3.886361546e-06, 3.19461916e-06, 2.502876773e-06, 1.811134387e-06, 1.11939185e-06, 8.771348648e-08, 3.017554875e-19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  • Small enough (< few 100s of lines), otherwise it should probably be split into smaller PRs
  • Tested (describe the tests in the PR description)
  • Runs on GPU (basic: the code compiles and run well with the new module)
  • Contains an automated test (checksum and/or comparison with theory)
  • Documented: all elements (classes and their members, functions, namespaces, etc.) are documented
  • Constified (All that can be const is const)
  • Code is clean (no unwanted comments, )
  • Style and code conventions are respected at the bottom of https://github.com/Hi-PACE/hipace
  • Proper label and GitHub project, if applicable

@AlexanderSinn AlexanderSinn requested a review from MaxThevenet May 6, 2025 13:10
@MaxThevenet MaxThevenet merged commit 3f8a3f2 into Hi-PACE:development May 13, 2025
10 checks passed
EyaDammak added a commit to EyaDammak/hipace that referenced this pull request May 16, 2025
* Resize Beam Diagnostic buffer (Hi-PACE#1227)

* Fix shadow issue in AddGridExternalFields (Hi-PACE#1230)

* Update Ubuntu version of CI tests (Hi-PACE#1232)

* Remove CONDA from CUDA Local CI (Hi-PACE#1236)

* Beam read_from_file also reads spin (Hi-PACE#1172)

Co-authored-by: Alexander Sinn <[email protected]>

* Update physical constants (Hi-PACE#1223)

* Fix laser from file hanging with MPI (Hi-PACE#1235)

* Add Parser Debug Print Utility (Hi-PACE#1238)

* Fix CI with MPI (Hi-PACE#1241)

---------

Co-authored-by: Alexander Sinn <[email protected]>
Co-authored-by: Maxence Thévenet <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants