Skip to content

non-singular BIE solver, improved FFT interpolation for singular integral, and new magnetic field API#2213

Open
unalmis wants to merge 427 commits into
masterfrom
ku/laplace
Open

non-singular BIE solver, improved FFT interpolation for singular integral, and new magnetic field API#2213
unalmis wants to merge 427 commits into
masterfrom
ku/laplace

Conversation

@unalmis
Copy link
Copy Markdown
Collaborator

@unalmis unalmis commented May 15, 2026

PR Age (see #1360)

  • All the solvers are thoroughly tested. See the shared paper to explain this PR. Significantly improved adjoint solve from earlier. It seems like this is still the only differentiable 3d laplace solver on the internet that works on multiply connected geometry.
  • Tested and confirmed agreement with BIE3D package. plotter.py
  • This PR includes my FFT improvements significantly improve free surface optimization (both old and new) and anything that involves singular integrals. Even the flaky GitHub ci benchmarks detect this.
  • Non-invasive, backward compatible, new magnetic field api implemented. Without the new api, the code would be unreadable.
  • There are other applications besides free surface.
  • The linear solve to compute the objective function only takes 2 gmres iterations. Gradient based optimization is very fast. Using a fast multipole technique would greatly improve performance. There are jax libraries that do this, but that can be a later pull request to merge after this.

iterative plots

stop tolerance denotes typical stop tol in most applications. gmres is expected to always invert the linear system in 2 iterations. after stateful opt, my guess is it will be reduced to 1 iteration.

image image image

@unalmis unalmis changed the title BIE solver, improved FFT interpolation for singular integral, and new magnetic field API non-singular BIE solver, improved FFT interpolation for singular integral, and new magnetic field API May 15, 2026
@unalmis unalmis added performance New feature or request to make the code faster run_benchmarks Run timing benchmarks on this PR against current master branch stable Besides merging master, other updates require a child PR that should be merged to master later. labels May 15, 2026
@unalmis unalmis self-assigned this May 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 15, 2026

Memory benchmark result

|               Test Name                |      %Δ      |    Master (MB)     |      PR (MB)       |    Δ (MB)    |    Time PR (s)     |  Time Master (s)   |
| -------------------------------------- | ------------ | ------------------ | ------------------ | ------------ | ------------------ | ------------------ |
  test_objective_jac_w7x                 |    1.86 %    |     3.976e+03      |     4.050e+03      |    73.79     |       31.75        |       29.03        |
  test_proximal_jac_w7x_with_eq_update   |   -0.28 %    |     6.578e+03      |     6.560e+03      |    -18.41    |       153.30       |       150.73       |
+ test_proximal_freeb_jac                |   -16.32 %   |     1.330e+04      |     1.113e+04      |   -2170.14   |       69.68        |       77.50        |
+ test_proximal_freeb_jac_blocked        |   -15.74 %   |     7.625e+03      |     6.425e+03      |   -1199.93   |       65.16        |       67.66        |
+ test_proximal_freeb_jac_batched        |   -16.27 %   |     7.670e+03      |     6.422e+03      |   -1247.70   |       66.47        |       67.47        |
  test_proximal_jac_ripple               |   -0.91 %    |     3.507e+03      |     3.475e+03      |    -31.98    |       53.55        |       54.87        |
  test_proximal_jac_ripple_bounce1d      |   -2.40 %    |     3.775e+03      |     3.685e+03      |    -90.53    |       68.92        |       69.61        |
  test_eq_solve                          |   -3.33 %    |     2.074e+03      |     2.005e+03      |    -69.16    |       86.31        |       86.42        |

For the memory plots, go to the summary of Memory Benchmarks workflow and download the artifact.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 15, 2026

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     +4.56 +/- 9.57     | +3.91e-02 +/- 8.20e-02 |  8.96e-01 +/- 8.0e-02  |  8.57e-01 +/- 1.7e-02  |
 test_equilibrium_init_medres            |     -2.76 +/- 7.52     | -2.06e-01 +/- 5.63e-01 |  7.28e+00 +/- 5.3e-01  |  7.48e+00 +/- 2.0e-01  |
 test_equilibrium_init_highres           |     -2.28 +/- 6.58     | -1.85e-01 +/- 5.34e-01 |  7.93e+00 +/- 4.8e-01  |  8.11e+00 +/- 2.2e-01  |
 test_objective_compile_dshape_current   |     -1.59 +/- 2.23     | -6.64e-02 +/- 9.28e-02 |  4.10e+00 +/- 7.5e-02  |  4.17e+00 +/- 5.5e-02  |
 test_objective_compute_dshape_current   |     -2.49 +/- 7.26     | -1.57e-05 +/- 4.56e-05 |  6.13e-04 +/- 3.4e-05  |  6.29e-04 +/- 3.0e-05  |
 test_objective_jac_dshape_current       |     -5.96 +/- 28.21    | -1.57e-03 +/- 7.44e-03 |  2.48e-02 +/- 5.7e-03  |  2.64e-02 +/- 4.8e-03  |
 test_perturb_2                          |     +4.41 +/- 3.09     | +8.52e-01 +/- 5.96e-01 |  2.02e+01 +/- 3.3e-01  |  1.93e+01 +/- 5.0e-01  |
 test_proximal_jac_atf_with_eq_update    |     +2.99 +/- 2.09     | +3.76e-01 +/- 2.63e-01 |  1.30e+01 +/- 2.2e-01  |  1.26e+01 +/- 1.4e-01  |
+test_proximal_freeb_jac                 |    -14.62 +/- 2.31     | -6.93e-01 +/- 1.09e-01 |  4.04e+00 +/- 5.7e-02  |  4.74e+00 +/- 9.3e-02  |
 test_solve_fixed_iter_compiled          |     +3.91 +/- 3.12     | +3.39e-01 +/- 2.71e-01 |  9.01e+00 +/- 1.8e-01  |  8.67e+00 +/- 2.0e-01  |
 test_LinearConstraintProjection_build   |    +10.67 +/- 7.47     | +6.98e-01 +/- 4.89e-01 |  7.24e+00 +/- 4.7e-01  |  6.55e+00 +/- 1.4e-01  |
 test_objective_compute_ripple_bounce1d  |     +1.71 +/- 4.94     | +4.78e-03 +/- 1.38e-02 |  2.84e-01 +/- 7.1e-03  |  2.79e-01 +/- 1.2e-02  |
 test_objective_grad_ripple_bounce1d     |     +0.00 +/- 1.58     | +2.08e-05 +/- 1.54e-02 |  9.79e-01 +/- 9.5e-03  |  9.79e-01 +/- 1.2e-02  |
 test_build_transform_fft_midres         |     -0.14 +/- 3.36     | -1.25e-03 +/- 2.97e-02 |  8.84e-01 +/- 2.2e-02  |  8.85e-01 +/- 1.9e-02  |
 test_build_transform_fft_highres        |     -0.39 +/- 1.69     | -4.64e-03 +/- 1.99e-02 |  1.17e+00 +/- 1.3e-02  |  1.18e+00 +/- 1.5e-02  |
 test_equilibrium_init_lowres            |     -0.70 +/- 2.58     | -4.45e-02 +/- 1.65e-01 |  6.35e+00 +/- 1.2e-01  |  6.40e+00 +/- 1.1e-01  |
 test_objective_compile_atf              |     -0.03 +/- 2.81     | -1.65e-03 +/- 1.74e-01 |  6.22e+00 +/- 6.0e-02  |  6.22e+00 +/- 1.6e-01  |
 test_objective_compute_atf              |     -1.02 +/- 18.79    | -2.09e-05 +/- 3.85e-04 |  2.03e-03 +/- 3.0e-04  |  2.05e-03 +/- 2.4e-04  |
 test_objective_jac_atf                  |     +0.81 +/- 3.01     | +1.28e-02 +/- 4.78e-02 |  1.60e+00 +/- 3.3e-02  |  1.59e+00 +/- 3.4e-02  |
 test_perturb_1                          |     -0.12 +/- 2.25     | -1.88e-02 +/- 3.57e-01 |  1.58e+01 +/- 1.0e-01  |  1.59e+01 +/- 3.4e-01  |
 test_proximal_jac_atf                   |     +0.39 +/- 1.69     | +2.05e-02 +/- 8.81e-02 |  5.24e+00 +/- 5.5e-02  |  5.22e+00 +/- 6.9e-02  |
 test_proximal_freeb_compute             |     -6.48 +/- 3.12     | -1.08e-02 +/- 5.18e-03 |  1.55e-01 +/- 2.8e-03  |  1.66e-01 +/- 4.4e-03  |
 test_solve_fixed_iter                   |     -0.60 +/- 1.86     | -1.55e-01 +/- 4.80e-01 |  2.57e+01 +/- 3.7e-01  |  2.59e+01 +/- 3.0e-01  |
 test_objective_compute_ripple           |     -0.77 +/- 3.90     | -1.81e-03 +/- 9.18e-03 |  2.33e-01 +/- 7.0e-03  |  2.35e-01 +/- 6.0e-03  |
 test_objective_grad_ripple              |     -0.09 +/- 2.68     | -7.71e-04 +/- 2.32e-02 |  8.66e-01 +/- 2.1e-02  |  8.66e-01 +/- 1.0e-02  |

Github CI performance can be noisy. When evaluating the benchmarks, developers should take this into account.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 94.73684% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.39%. Comparing base (c119da0) to head (69d556f).

Files with missing lines Patch % Lines
desc/compute/_laplace.py 93.77% 15 Missing ⚠️
desc/integrals/singularities.py 90.56% 15 Missing ⚠️
desc/magnetic_fields/_laplace.py 93.54% 6 Missing ⚠️
desc/backend.py 84.00% 4 Missing ⚠️
desc/compute/utils.py 96.49% 2 Missing ⚠️
desc/basis.py 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2213      +/-   ##
==========================================
+ Coverage   94.34%   94.39%   +0.05%     
==========================================
  Files         101      103       +2     
  Lines       28845    29375     +530     
==========================================
+ Hits        27213    27729     +516     
- Misses       1632     1646      +14     
Files with missing lines Coverage Δ
desc/coils.py 97.96% <ø> (ø)
desc/compute/__init__.py 100.00% <ø> (ø)
desc/compute/_basis_vectors.py 100.00% <100.00%> (ø)
desc/compute/_core.py 100.00% <100.00%> (ø)
desc/compute/_metric.py 100.00% <100.00%> (ø)
desc/compute/_surface.py 100.00% <100.00%> (ø)
desc/compute/data_index.py 95.89% <ø> (ø)
desc/equilibrium/equilibrium.py 95.96% <ø> (ø)
desc/geometry/core.py 95.30% <100.00%> (ø)
desc/grid.py 94.76% <100.00%> (+0.04%) ⬆️
... and 15 more

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@unalmis unalmis added theory Requires theory work before coding and removed theory Requires theory work before coding labels May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance New feature or request to make the code faster run_benchmarks Run timing benchmarks on this PR against current master branch stable Besides merging master, other updates require a child PR that should be merged to master later.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

document tangential assumption of current potential classes New magnetic field API Better FFT interpolation for singular integration

5 participants