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

LinkingCurrent objective #1222

Merged
merged 37 commits into from
Dec 13, 2024
Merged

LinkingCurrent objective #1222

merged 37 commits into from
Dec 13, 2024

Conversation

ddudt
Copy link
Collaborator

@ddudt ddudt commented Aug 23, 2024

This is a nonlinear form of the existing linear objective FixSumCoilCurrent. It ensures the total current through the coils matches the poloidal current of the equilibrium. This is necessary for single-stage optimization where the equilibrium and coils are changing simultaneously.

@ddudt ddudt added objectives Adding or improving objective functions coil stuff relating to coils and coil optimization labels Aug 23, 2024
@ddudt ddudt self-assigned this Aug 23, 2024
Copy link
Contributor

github-actions bot commented Aug 23, 2024

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     +4.34 +/- 5.58     | +2.39e-02 +/- 3.07e-02 |  5.75e-01 +/- 2.3e-02  |  5.51e-01 +/- 2.0e-02  |
 test_equilibrium_init_medres            |     -1.56 +/- 6.66     | -7.21e-02 +/- 3.07e-01 |  4.54e+00 +/- 1.5e-01  |  4.61e+00 +/- 2.7e-01  |
 test_equilibrium_init_highres           |     +0.53 +/- 2.86     | +3.13e-02 +/- 1.68e-01 |  5.92e+00 +/- 1.2e-01  |  5.89e+00 +/- 1.2e-01  |
 test_objective_compile_dshape_current   |     +0.01 +/- 2.44     | +2.90e-04 +/- 1.01e-01 |  4.13e+00 +/- 9.0e-02  |  4.13e+00 +/- 4.6e-02  |
 test_objective_compute_dshape_current   |     +2.30 +/- 6.92     | +1.24e-04 +/- 3.73e-04 |  5.51e-03 +/- 3.5e-04  |  5.38e-03 +/- 1.2e-04  |
 test_objective_jac_dshape_current       |     +0.72 +/- 7.17     | +3.22e-04 +/- 3.20e-03 |  4.49e-02 +/- 2.0e-03  |  4.46e-02 +/- 2.5e-03  |
 test_perturb_2                          |     -2.85 +/- 2.58     | -6.05e-01 +/- 5.47e-01 |  2.06e+01 +/- 4.7e-01  |  2.12e+01 +/- 2.8e-01  |
 test_proximal_freeb_jac                 |     -0.95 +/- 2.34     | -7.29e-02 +/- 1.79e-01 |  7.57e+00 +/- 1.1e-01  |  7.64e+00 +/- 1.4e-01  |
 test_solve_fixed_iter                   |     -2.25 +/- 2.46     | -7.96e-01 +/- 8.71e-01 |  3.46e+01 +/- 7.0e-01  |  3.54e+01 +/- 5.2e-01  |
 test_LinearConstraintProjection_build   |     -1.22 +/- 3.60     | -1.35e-01 +/- 4.00e-01 |  1.10e+01 +/- 3.5e-01  |  1.11e+01 +/- 1.9e-01  |
 test_build_transform_fft_midres         |     -2.52 +/- 4.89     | -1.66e-02 +/- 3.22e-02 |  6.42e-01 +/- 2.0e-02  |  6.58e-01 +/- 2.5e-02  |
 test_build_transform_fft_highres        |     -2.57 +/- 2.63     | -2.66e-02 +/- 2.72e-02 |  1.01e+00 +/- 1.7e-02  |  1.03e+00 +/- 2.1e-02  |
 test_equilibrium_init_lowres            |     -1.45 +/- 3.02     | -6.21e-02 +/- 1.29e-01 |  4.22e+00 +/- 9.2e-02  |  4.28e+00 +/- 9.0e-02  |
 test_objective_compile_atf              |     -3.45 +/- 4.64     | -2.97e-01 +/- 4.00e-01 |  8.31e+00 +/- 3.0e-01  |  8.61e+00 +/- 2.6e-01  |
 test_objective_compute_atf              |     -4.15 +/- 5.51     | -7.36e-04 +/- 9.78e-04 |  1.70e-02 +/- 9.0e-04  |  1.77e-02 +/- 3.9e-04  |
 test_objective_jac_atf                  |     -1.42 +/- 2.70     | -2.89e-02 +/- 5.49e-02 |  2.01e+00 +/- 3.9e-02  |  2.04e+00 +/- 3.8e-02  |
 test_perturb_1                          |     -3.70 +/- 1.61     | -5.97e-01 +/- 2.60e-01 |  1.55e+01 +/- 1.6e-01  |  1.61e+01 +/- 2.0e-01  |
 test_proximal_jac_atf                   |     -0.78 +/- 1.06     | -6.57e-02 +/- 8.93e-02 |  8.34e+00 +/- 4.2e-02  |  8.40e+00 +/- 7.9e-02  |
 test_proximal_freeb_compute             |     -2.01 +/- 1.42     | -4.15e-03 +/- 2.93e-03 |  2.02e-01 +/- 2.1e-03  |  2.07e-01 +/- 2.1e-03  |
 test_solve_fixed_iter_compiled          |     -0.56 +/- 2.46     | -1.28e-01 +/- 5.62e-01 |  2.27e+01 +/- 3.8e-01  |  2.28e+01 +/- 4.2e-01  |

@dpanici
Copy link
Collaborator

dpanici commented Aug 28, 2024

do #1231

@dpanici
Copy link
Collaborator

dpanici commented Sep 24, 2024

Any progress on this @daniel-dudt ?

@dpanici
Copy link
Collaborator

dpanici commented Sep 25, 2024

Use Linking number calc for linear objective for sum coil currents as well, to use as weights for sum

@dpanici
Copy link
Collaborator

dpanici commented Sep 28, 2024

I think an equivalent sort of objective to ensure that the coils are creating the necessary current, without needing the linking number calculation (though I'd still like that in sometime), is to directly calculate $\int_{o}^{2\pi/NFP} \mathbf{B}{coil} \cdot \mathbf{e}{\zeta} d\zeta - \int_{o}^{2\pi/NFP} \mathbf{B}{DESC} \cdot \mathbf{e}{\zeta} d\zeta$ which is the relation that Ampere's law tells us (the second term here is $G(\rho=1)$, possibly sans a $2\pi$ factor).

This being zero means the coils are consistent with Ampere's law and avoids needing to worry about the linking currents (though this is a bit more expensive, as it relies on biot-savart integration over the coils to get $\mathbf{B}_{coil}$

@f0uriest f0uriest changed the base branch from master to rc/linking_number October 11, 2024 19:33
@f0uriest f0uriest changed the base branch from rc/linking_number to master October 15, 2024 04:06
Copy link

codecov bot commented Oct 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.62%. Comparing base (4bfa728) to head (ab74f48).
Report is 38 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1222      +/-   ##
==========================================
+ Coverage   95.60%   95.62%   +0.02%     
==========================================
  Files          98       98              
  Lines       25300    25374      +74     
==========================================
+ Hits        24188    24264      +76     
+ Misses       1112     1110       -2     
Files with missing lines Coverage Δ
desc/coils.py 97.98% <100.00%> (+0.20%) ⬆️
desc/objectives/__init__.py 100.00% <ø> (ø)
desc/objectives/_coils.py 99.34% <100.00%> (+0.06%) ⬆️

... and 1 file with indirect coverage changes

@f0uriest f0uriest marked this pull request as ready for review October 15, 2024 22:01
@f0uriest f0uriest requested review from a team and rahulgaur104 and removed request for a team October 15, 2024 22:01
Copy link
Collaborator Author

@ddudt ddudt left a comment

Choose a reason for hiding this comment

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

I can't officially approve, but it looks good.

# linking number for coils with axis
link = np.round(dummy_coilset._compute_linking_number())[0, 1:]

self._constants = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this could be 1 line instead of 4

Returns
-------
f : array of floats
Linking current error.
Copy link
Collaborator

Choose a reason for hiding this comment

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

techincally just a single float but not a big deal

Copy link
Collaborator

@dpanici dpanici left a comment

Choose a reason for hiding this comment

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

I think the name could be changed to LinkingCurrentConsistency or something, or the docstring should make it clearer that target should be zero, and NOT the targeted linking current G

@f0uriest f0uriest requested a review from dpanici December 11, 2024 23:25
verbose=2,
copy=True,
)
with warnings.catch_warnings():
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do we understand why this constraint is being flagged as "incompatible"? This is like the simplest possible linear constraint, so I'm worried if this doesn't work without warnings.

Copy link
Member

Choose a reason for hiding this comment

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

The error is like 1e-9 which is about what we'd expect given the currents are ~MA

desc/objectives/_coils.py Outdated Show resolved Hide resolved
@f0uriest f0uriest requested a review from dpanici December 13, 2024 01:54
@f0uriest f0uriest merged commit afeff2c into master Dec 13, 2024
24 of 25 checks passed
@ddudt ddudt deleted the dd/linking_current branch December 17, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coil stuff relating to coils and coil optimization objectives Adding or improving objective functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants