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

Integrate on boundary to compute length scale quantities #1094

Draft
wants to merge 55 commits into
base: master
Choose a base branch
from

Conversation

unalmis
Copy link
Collaborator

@unalmis unalmis commented Jul 2, 2024

This pull request is waiting on #1127 .

See #1101, in particular this comment for some of other changes.

Some quantities like the plasma volume V, major radius R0, minor radius a etc. can be computed via stoke's theorem on the last closed flux surface. This pull request modifies the compute functions to default to such an integration on the boundary rather than throughout the volume so that the length scale quantities can be computed accurately on grids other than QuadratureGrid. This lets us avoid building transforms for QuadratureGrid in objectives, saving memory.

Also, might have some improvements in general

  1. Reducing dimensionality of integral makes integration more tractable with faster convergence.
  2. Transforming the integration to one over periodic domains makes it more accurate due to the exponential convergence of the quadrature on periodic domains.

@unalmis unalmis added the performance New feature or request to make the code faster label Jul 2, 2024
@unalmis unalmis changed the base branch from master to fieldline_compute July 2, 2024 19:52
@unalmis unalmis marked this pull request as ready for review July 2, 2024 19:55
@unalmis unalmis marked this pull request as draft July 2, 2024 20:31
Copy link
Contributor

github-actions bot commented Jul 2, 2024

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     -0.82 +/- 3.54     | -4.55e-03 +/- 1.96e-02 |  5.49e-01 +/- 1.2e-02  |  5.54e-01 +/- 1.5e-02  |
 test_equilibrium_init_medres            |     +0.06 +/- 1.38     | +2.47e-03 +/- 6.05e-02 |  4.39e+00 +/- 3.4e-02  |  4.39e+00 +/- 5.0e-02  |
 test_equilibrium_init_highres           |     +0.55 +/- 1.23     | +3.12e-02 +/- 6.97e-02 |  5.69e+00 +/- 5.9e-02  |  5.66e+00 +/- 3.8e-02  |
 test_objective_compile_dshape_current   |     +0.08 +/- 1.20     | +3.09e-03 +/- 4.80e-02 |  4.00e+00 +/- 4.0e-02  |  4.00e+00 +/- 2.7e-02  |
 test_objective_compute_dshape_current   |     +0.78 +/- 4.34     | +4.10e-05 +/- 2.29e-04 |  5.32e-03 +/- 1.3e-04  |  5.28e-03 +/- 1.9e-04  |
 test_objective_jac_dshape_current       |     +3.36 +/- 7.85     | +1.43e-03 +/- 3.35e-03 |  4.41e-02 +/- 3.1e-03  |  4.26e-02 +/- 1.3e-03  |
 test_perturb_2                          |     +0.03 +/- 1.78     | +6.59e-03 +/- 3.63e-01 |  2.04e+01 +/- 1.9e-01  |  2.04e+01 +/- 3.1e-01  |
 test_proximal_freeb_jac                 |     -0.17 +/- 0.95     | -1.27e-02 +/- 7.06e-02 |  7.42e+00 +/- 4.8e-02  |  7.43e+00 +/- 5.2e-02  |
 test_solve_fixed_iter                   |     +0.43 +/- 2.16     | +1.39e-01 +/- 7.07e-01 |  3.29e+01 +/- 3.7e-01  |  3.27e+01 +/- 6.0e-01  |
 test_LinearConstraintProjection_build   |     +0.29 +/- 2.57     | +3.04e-02 +/- 2.74e-01 |  1.07e+01 +/- 2.2e-01  |  1.06e+01 +/- 1.6e-01  |
 test_build_transform_fft_midres         |     +0.78 +/- 4.16     | +4.77e-03 +/- 2.56e-02 |  6.20e-01 +/- 2.1e-02  |  6.15e-01 +/- 1.5e-02  |
 test_build_transform_fft_highres        |     +0.41 +/- 1.93     | +3.97e-03 +/- 1.89e-02 |  9.84e-01 +/- 1.5e-02  |  9.80e-01 +/- 1.1e-02  |
 test_equilibrium_init_lowres            |     -0.10 +/- 1.73     | -3.99e-03 +/- 6.85e-02 |  3.94e+00 +/- 5.3e-02  |  3.95e+00 +/- 4.4e-02  |
 test_objective_compile_atf              |     -1.32 +/- 1.56     | -1.09e-01 +/- 1.29e-01 |  8.18e+00 +/- 1.2e-01  |  8.29e+00 +/- 4.7e-02  |
 test_objective_compute_atf              |     -0.35 +/- 4.75     | -5.71e-05 +/- 7.70e-04 |  1.62e-02 +/- 5.8e-04  |  1.62e-02 +/- 5.1e-04  |
 test_objective_jac_atf                  |     -1.89 +/- 2.14     | -3.83e-02 +/- 4.33e-02 |  1.98e+00 +/- 3.1e-02  |  2.02e+00 +/- 3.0e-02  |
 test_perturb_1                          |     -0.23 +/- 1.15     | -3.51e-02 +/- 1.73e-01 |  1.50e+01 +/- 9.4e-02  |  1.50e+01 +/- 1.5e-01  |
 test_proximal_jac_atf                   |     +0.61 +/- 0.70     | +5.08e-02 +/- 5.83e-02 |  8.37e+00 +/- 4.2e-02  |  8.32e+00 +/- 4.1e-02  |
 test_proximal_freeb_compute             |     -0.59 +/- 0.84     | -1.20e-03 +/- 1.70e-03 |  2.03e-01 +/- 1.0e-03  |  2.04e-01 +/- 1.3e-03  |
 test_solve_fixed_iter_compiled          |     -1.20 +/- 0.74     | -2.51e-01 +/- 1.55e-01 |  2.06e+01 +/- 1.3e-01  |  2.09e+01 +/- 8.2e-02  |

unalmis added 3 commits July 3, 2024 23:18
These differences are because, prior to the changes in this PR,
these length scale quantities would get computed on a full resolution
quadrature grid in test_compute_everything. Now thare computed on the same
low resolution used in the test that is used for everything else.

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: A.
Mismatched elements: 1 / 1 (100%)
Max absolute difference: 1.63995582e-05
Max relative difference: 2.03987171e-05
 x: array(0.803967)
 y: array(0.80395)

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: S.
Mismatched elements: 1 / 1 (100%)
Max absolute difference: 0.16850603
Max relative difference: 0.00125191
 x: array(134.767312)
 y: array(134.598806)

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: A(z).
Mismatched elements: 660 / 660 (100%)
Max absolute difference: 0.63797977
Max relative difference: 0.80369303
 x: array([0.763363, 0.763363, 0.763363, 0.763363, 0.763363, 0.763363,
       0.763363, 0.763363, 0.763363, 0.763363, 0.763363, 0.763363,
       0.763363, 0.763363, 0.763363, 0.763363, 0.763363, 0.763363,...
 y: array([0.762978, 0.762978, 0.762978, 0.762978, 0.762978, 0.762978,
       0.762978, 0.762978, 0.762978, 0.762978, 0.762978, 0.762978,
       0.762978, 0.762978, 0.762978, 0.762978, 0.762978, 0.762978,...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: R0.
Mismatched elements: 1 / 1 (100%)
Max absolute difference: 0.00011245
Max relative difference: 2.0398301e-05
 x: array(5.51284)
 y: array(5.512953)

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: A(r).
Mismatched elements: 594 / 660 (90%)
Max absolute difference: 1.63995582e-05
Max relative difference: 2.03987171e-05
 x: array([0.      , 0.      , 0.      , 0.      , 0.      , 0.      ,
       0.010291, 0.010291, 0.010291, 0.010291, 0.010291, 0.010291,
       0.041077, 0.041077, 0.041077, 0.041077, 0.041077, 0.041077,...
 y: array([0.      , 0.      , 0.      , 0.      , 0.      , 0.      ,
       0.010291, 0.010291, 0.010291, 0.010291, 0.010291, 0.010291,
       0.041077, 0.041077, 0.041077, 0.041077, 0.041077, 0.041077,...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: a.
Mismatched elements: 1 / 1 (100%)
Max absolute difference: 5.15953253e-06
Max relative difference: 1.01993065e-05
 x: array(0.505876)
 y: array(0.505871)

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: R0/a.
Mismatched elements: 1 / 1 (100%)
Max absolute difference: 0.00033345
Max relative difference: 3.05972954e-05
 x: array(10.89761)
 y: array(10.897944)

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: a_major/a_minor.
Mismatched elements: 660 / 660 (100%)
Max absolute difference: 10.92082022
Max relative difference: 4.88235767
 x: array([ 4.007305,  4.007305,  4.007305,  4.007305,  4.007305,  4.007305,
        4.007305,  4.007305,  4.007305,  4.007305,  4.007305,  4.007305,
        4.007305,  4.007305,  4.007305,  4.007305,  4.007305,  4.007305,...
 y: array([4.009882, 4.009882, 4.009882, 4.009882, 4.009882, 4.009882,
       4.009882, 4.009882, 4.009882, 4.009882, 4.009882, 4.009882,
       4.009882, 4.009882, 4.009882, 4.009882, 4.009882, 4.009882,...
@unalmis unalmis linked an issue Jul 4, 2024 that may be closed by this pull request
unalmis added 2 commits July 11, 2024 16:13
Some of the master compute data changes with this commit.
The changes which are not due to floating point differences or simply grid
resolution differences (recall the grid used in test_compute_everything has
L = 9, M=N=5 which is less than required for convergence to true integral
quantities on that equilbrium) are given below:

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: A(z).
Mismatched elements: 660 / 660 (100%)
Max absolute difference: 0.6494644
Max relative difference: 0.81816076
 x: array([0.792591, 0.792591, 0.792591, 0.792591, 0.792591, 0.792591,
       0.792591, 0.792591, 0.792591, 0.792591, 0.792591, 0.792591,
       0.792591, 0.792591, 0.792591, 0.792591, 0.792591, 0.792591,...
 y: array([0.762978, 0.762978, 0.762978, 0.762978, 0.762978, 0.762978,
       0.762978, 0.762978, 0.762978, 0.762978, 0.762978, 0.762978,
       0.762978, 0.762978, 0.762978, 0.762978, 0.762978, 0.762978,...

Not equal to tolerance rtol=1e-10, atol=1e-10
Parameterization: desc.equilibrium.equilibrium.Equilibrium. Name: a_major/a_minor.
Mismatched elements: 660 / 660 (100%)
Max absolute difference: 11.33931768
Max relative difference: 4.99527722
 x: array([ 3.864152,  3.864152,  3.864152,  3.864152,  3.864152,  3.864152,
        3.864152,  3.864152,  3.864152,  3.864152,  3.864152,  3.864152,
        3.864152,  3.864152,  3.864152,  3.864152,  3.864152,  3.864152,...
 y: array([4.057173, 4.057173, 4.057173, 4.057173, 4.057173, 4.057173,
       4.057173, 4.057173, 4.057173, 4.057173, 4.057173, 4.057173,
       4.057173, 4.057173, 4.057173, 4.057173, 4.057173, 4.057173,...

NOTE that both quanties are incorrect, because in general we cannot compute
these quantities accuratly on grids that do not sample the full poloidal
domain.
@unalmis unalmis marked this pull request as ready for review July 11, 2024 22:23
@unalmis unalmis added documentation Add documentation or better warnings etc. bug fix Something was fixed and removed bug fix Something was fixed labels Jul 12, 2024
@unalmis unalmis linked an issue Jul 12, 2024 that may be closed by this pull request
@unalmis unalmis marked this pull request as draft July 12, 2024 22:19
@unalmis unalmis marked this pull request as ready for review July 13, 2024 16:17
@unalmis unalmis added the P2 Medium Priority, not urgent but should be on the near-term agend label Dec 4, 2024
@unalmis unalmis added P1 Lowest Priority, will get to eventually and removed P2 Medium Priority, not urgent but should be on the near-term agend labels Dec 7, 2024
@unalmis unalmis added waiting for other PRs and removed P1 Lowest Priority, will get to eventually labels Dec 12, 2024
@unalmis unalmis added bug fix Something was fixed and removed add warning labels Dec 27, 2024
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix Something was fixed performance New feature or request to make the code faster waiting for other PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change description of S
4 participants