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

Implement Symbolic Recursive Integration for Dommaschk #1496

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

dpanici
Copy link
Collaborator

@dpanici dpanici commented Dec 26, 2024

Resolves #1467
Resolves #1278

Changes implementation of Dommaschk potentials to use sympy and symbolic integration to recursively compute the potentials with symbolic algebra. I then use the sympy.lambdify function to turn this into a jax-differentiable expression usable with our ScalarPotentialField class.

Copy link
Contributor

github-actions bot commented Dec 26, 2024

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     +0.15 +/- 4.29     | +7.86e-04 +/- 2.25e-02 |  5.25e-01 +/- 1.7e-02  |  5.24e-01 +/- 1.4e-02  |
 test_equilibrium_init_medres            |     +1.23 +/- 1.04     | +5.09e-02 +/- 4.31e-02 |  4.18e+00 +/- 3.3e-02  |  4.13e+00 +/- 2.7e-02  |
 test_equilibrium_init_highres           |     +0.40 +/- 2.62     | +2.16e-02 +/- 1.42e-01 |  5.44e+00 +/- 1.3e-01  |  5.42e+00 +/- 6.7e-02  |
 test_objective_compile_dshape_current   |     -0.46 +/- 4.45     | -1.89e-02 +/- 1.82e-01 |  4.08e+00 +/- 1.3e-01  |  4.09e+00 +/- 1.3e-01  |
 test_objective_compute_dshape_current   |     -1.07 +/- 1.78     | -5.53e-05 +/- 9.21e-05 |  5.12e-03 +/- 6.2e-05  |  5.18e-03 +/- 6.8e-05  |
 test_objective_jac_dshape_current       |     +0.54 +/- 7.61     | +2.29e-04 +/- 3.23e-03 |  4.27e-02 +/- 2.4e-03  |  4.24e-02 +/- 2.2e-03  |
 test_perturb_2                          |     +0.64 +/- 2.09     | +1.26e-01 +/- 4.10e-01 |  1.97e+01 +/- 8.1e-02  |  1.96e+01 +/- 4.0e-01  |
 test_proximal_freeb_jac                 |     +0.47 +/- 1.01     | +3.44e-02 +/- 7.47e-02 |  7.43e+00 +/- 3.5e-02  |  7.40e+00 +/- 6.6e-02  |
 test_solve_fixed_iter                   |     -0.26 +/- 2.08     | -8.19e-02 +/- 6.60e-01 |  3.17e+01 +/- 5.0e-01  |  3.18e+01 +/- 4.4e-01  |
 test_LinearConstraintProjection_build   |     -1.51 +/- 2.93     | -1.57e-01 +/- 3.05e-01 |  1.02e+01 +/- 7.9e-02  |  1.04e+01 +/- 2.9e-01  |
 test_build_transform_fft_midres         |     +0.48 +/- 2.54     | +2.90e-03 +/- 1.52e-02 |  6.01e-01 +/- 1.3e-02  |  5.99e-01 +/- 8.6e-03  |
 test_build_transform_fft_highres        |     +0.12 +/- 2.35     | +1.14e-03 +/- 2.25e-02 |  9.61e-01 +/- 2.0e-02  |  9.60e-01 +/- 1.1e-02  |
 test_equilibrium_init_lowres            |     +0.82 +/- 2.07     | +3.08e-02 +/- 7.80e-02 |  3.80e+00 +/- 7.3e-02  |  3.77e+00 +/- 2.7e-02  |
 test_objective_compile_atf              |     +1.24 +/- 2.50     | +1.01e-01 +/- 2.04e-01 |  8.26e+00 +/- 9.4e-02  |  8.16e+00 +/- 1.8e-01  |
 test_objective_compute_atf              |     +0.49 +/- 1.26     | +7.66e-05 +/- 1.97e-04 |  1.57e-02 +/- 1.5e-04  |  1.57e-02 +/- 1.2e-04  |
 test_objective_jac_atf                  |     +1.21 +/- 2.15     | +2.32e-02 +/- 4.11e-02 |  1.94e+00 +/- 3.2e-02  |  1.91e+00 +/- 2.6e-02  |
 test_perturb_1                          |     +0.08 +/- 1.00     | +1.13e-02 +/- 1.44e-01 |  1.44e+01 +/- 1.1e-01  |  1.44e+01 +/- 8.8e-02  |
 test_proximal_jac_atf                   |     +0.11 +/- 1.13     | +8.76e-03 +/- 9.26e-02 |  8.22e+00 +/- 5.3e-02  |  8.21e+00 +/- 7.6e-02  |
 test_proximal_freeb_compute             |     +0.25 +/- 1.47     | +4.98e-04 +/- 2.92e-03 |  2.00e-01 +/- 2.3e-03  |  1.99e-01 +/- 1.8e-03  |
 test_solve_fixed_iter_compiled          |     +0.25 +/- 0.51     | +5.04e-02 +/- 1.02e-01 |  2.03e+01 +/- 7.8e-02  |  2.03e+01 +/- 6.7e-02  |

Copy link

codecov bot commented Dec 27, 2024

Codecov Report

Attention: Patch coverage is 97.75281% with 2 lines in your changes missing coverage. Please review.

Project coverage is 95.69%. Comparing base (5322158) to head (8d2d691).

Files with missing lines Patch % Lines
desc/magnetic_fields/_dommaschk.py 97.75% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1496   +/-   ##
=======================================
  Coverage   95.68%   95.69%           
=======================================
  Files         101      101           
  Lines       25604    25606    +2     
=======================================
+ Hits        24500    24503    +3     
+ Misses       1104     1103    -1     
Files with missing lines Coverage Δ
desc/magnetic_fields/_dommaschk.py 96.13% <97.75%> (-1.08%) ⬇️

... and 3 files with indirect coverage changes

@dpanici dpanici marked this pull request as ready for review December 28, 2024 22:08
@dpanici dpanici requested review from a team, rahulgaur104, f0uriest, ddudt, kianorr, sinaatalay, unalmis and YigitElma and removed request for a team December 28, 2024 22:08
desc/backend.py Outdated Show resolved Hide resolved
desc/magnetic_fields/_dommaschk.py Outdated Show resolved Hide resolved
desc/magnetic_fields/_dommaschk.py Outdated Show resolved Hide resolved
desc/magnetic_fields/_dommaschk.py Outdated Show resolved Hide resolved
desc/magnetic_fields/_dommaschk.py Outdated Show resolved Hide resolved
desc/magnetic_fields/_dommaschk.py Outdated Show resolved Hide resolved
desc/magnetic_fields/_dommaschk.py Show resolved Hide resolved
tests/test_magnetic_fields.py Outdated Show resolved Hide resolved
@dpanici dpanici requested review from a team and f0uriest and removed request for a team January 22, 2025 16:24
@dpanici
Copy link
Collaborator Author

dpanici commented Jan 22, 2025

Moving notes to separate comment so it is not in PR commit comment

Notes

I've found that using sympy and symbolic integration to use the recursive form of the Dommaschk potentials to be a much more accurate way to use them (accurate as in, recreating poincare plots from the IPP report linked here, which previously I failed to find any flux surface using the nonrecursive algorithm)

Previous implementation was non-recursive and suffered from issues for certain more complex potentials, which were either due to numerical issues in the algorithm (precision issues) or due to an incorrect implementation on my part (which I never was able to track down). Either way, this symbolic method seems to work much better.

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.

Dommaschk Potential Issues Make Dommaschk factorials more accurate
2 participants