-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add JAX implementation of REGCOIL
algorithm and Add Ability to Discretize Current Potentials into Coilsets
#579
base: master
Are you sure you want to change the base?
Conversation
Ah this actually is branched off of #494 , should I point this PR towards there, or just wait to merge until that one is ready and merged in? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #579 +/- ##
==========================================
+ Coverage 95.52% 95.58% +0.06%
==========================================
Files 96 96
Lines 24005 24385 +380
==========================================
+ Hits 22930 23308 +378
- Misses 1075 1077 +2
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
flake8
desc/field_line_tracing_DESC_from_coilset.py|11 col 1| module level import not at top of file
desc/field_line_tracing_DESC_from_coilset.py|12 col 1| isort found an import in the wrong position
desc/field_line_tracing_DESC_from_coilset.py|12 col 1| 'desc.magnetic_fields.ToroidalMagneticField' imported but unused
desc/field_line_tracing_DESC_from_coilset.py|12 col 1| 'desc.magnetic_fields.SumMagneticField' imported but unused
desc/field_line_tracing_DESC_from_coilset.py|12 col 1| module level import not at top of file
desc/field_line_tracing_DESC_from_coilset.py|12 col 89| line too long (93 > 88 characters)
desc/field_line_tracing_DESC_from_coilset.py|13 col 1| isort found an import in the wrong position
desc/field_line_tracing_DESC_from_coilset.py|13 col 1| module level import not at top of file
desc/field_line_tracing_DESC_from_coilset.py|14 col 1| 'desc.io.load' imported but unused
desc/field_line_tracing_DESC_from_coilset.py|14 col 1| module level import not at top of file
desc/field_line_tracing_DESC_from_coilset.py|15 col 1| isort found an import in the wrong position
desc/field_line_tracing_DESC_from_coilset.py|15 col 1| 'scipy.interpolate.interp1d' imported but unused
desc/field_line_tracing_DESC_from_coilset.py|15 col 1| module level import not at top of file
desc/field_line_tracing_DESC_from_coilset.py|16 col 1| isort found an import in the wrong position
desc/field_line_tracing_DESC_from_coilset.py|17 col 1| isort found an import in the wrong position
desc/field_line_tracing_DESC_from_coilset.py|17 col 1| module level import not at top of file
desc/field_line_tracing_DESC_from_coilset.py|18 col 1| isort found an import in the wrong position
desc/field_line_tracing_DESC_from_coilset.py|18 col 1| module level import not at top of file
desc/field_line_tracing_DESC_from_coilset.py|19 col 1| isort found an unexpected blank line in imports
desc/field_line_tracing_DESC_from_coilset.py|20 col 1| isort found an unexpected blank line in imports
desc/field_line_tracing_DESC_from_coilset.py|21 col 1| isort found an import in the wrong position
desc/field_line_tracing_DESC_from_coilset.py|21 col 1| 'desc.coils.Coil' imported but unused
desc/field_line_tracing_DESC_from_coilset.py|21 col 1| module level import not at top of file
desc/field_line_tracing_DESC_from_coilset.py|22 col 1| isort found an unexpected blank line in imports
desc/field_line_tracing_DESC_from_coilset.py|23 col 1| isort found an unexpected missing import
desc/field_line_tracing_DESC_from_coilset.py|23 col 1| isort found an unexpected missing import
desc/field_line_tracing_DESC_from_coilset.py|23 col 1| isort found an unexpected missing import
desc/field_line_tracing_DESC_from_coilset.py|23 col 1| isort found an unexpected missing import
desc/field_line_tracing_DESC_from_coilset.py|23 col 1| isort found an unexpected missing import
desc/field_line_tracing_DESC_from_coilset.py|23 col 1| isort found an unexpected missing import
desc/field_line_tracing_DESC_from_coilset.py|31 col 1| isort found an import in the wrong position
desc/field_line_tracing_DESC_from_coilset.py|31 col 1| 'utils.get_coilset_from_MAKEGRID_or_regcoil' imported but unused
desc/field_line_tracing_DESC_from_coilset.py|31 col 1| module level import not at top of file
desc/field_line_tracing_DESC_from_coilset.py|33 col 21| trailing whitespace
desc/field_line_tracing_DESC_from_coilset.py|35 col 1| isort found an import in the wrong position
desc/field_line_tracing_DESC_from_coilset.py|35 col 1| module level import not at top of file
desc/field_line_tracing_DESC_from_coilset.py|40 col 23| trailing whitespace
desc/field_line_tracing_DESC_from_coilset.py|43 col 89| line too long (95 > 88 characters)
desc/field_line_tracing_DESC_from_coilset.py|46 col 14| trailing whitespace
desc/field_line_tracing_DESC_from_coilset.py|69 col 1| redefinition of unused 'os' from line 18
desc/field_line_tracing_DESC_from_coilset.py|69 col 1| module level import not at top of file
desc/field_line_tracing_DESC_from_coilset.py|70 col 1| isort expected 1 blank line in imports, found 0
desc/field_line_tracing_DESC_from_coilset.py|73 col 89| line too long (91 > 88 characters)
desc/field_line_tracing_DESC_from_coilset.py|74 col 89| line too long (91 > 88 characters)
desc/field_line_tracing_DESC_from_coilset.py|89 col 1| blank line contains whitespace
desc/field_line_tracing_DESC_from_coilset.py|115 col 1| too many blank lines (3)
desc/field_line_tracing_DESC_from_coilset.py|115 col 89| line too long (122 > 88 characters)
desc/field_line_tracing_DESC_from_coilset.py|117 col 1| blank line at end of file
closing until files are cleaned up |
reopening so tests will run |
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
desc/find_helical_contours_from_python_regcoil_equal_curr_line_integral.py
Outdated
Show resolved
Hide resolved
| benchmark_name | dt(%) | dt(s) | t_new(s) | t_old(s) |
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
test_build_transform_fft_lowres | -0.81 +/- 1.41 | -1.54e-04 +/- 2.68e-04 | 1.88e-02 +/- 2.0e-04 | 1.90e-02 +/- 1.8e-04 |
test_build_transform_fft_midres | +0.92 +/- 1.23 | +1.02e-03 +/- 1.37e-03 | 1.12e-01 +/- 9.9e-04 | 1.11e-01 +/- 9.5e-04 |
test_build_transform_fft_highres | +0.51 +/- 0.80 | +2.65e-03 +/- 4.14e-03 | 5.18e-01 +/- 1.8e-03 | 5.15e-01 +/- 3.7e-03 |
test_equilibrium_init_lowres | -0.56 +/- 1.71 | -2.45e-03 +/- 7.52e-03 | 4.36e-01 +/- 6.4e-03 | 4.39e-01 +/- 4.0e-03 |
test_equilibrium_init_medres | -0.60 +/- 1.81 | -3.39e-03 +/- 1.02e-02 | 5.60e-01 +/- 4.6e-03 | 5.64e-01 +/- 9.1e-03 |
test_equilibrium_init_highres | -0.60 +/- 1.14 | -5.94e-03 +/- 1.13e-02 | 9.86e-01 +/- 7.6e-03 | 9.92e-01 +/- 8.4e-03 |
test_objective_compile_dshape_current | -1.65 +/- 7.48 | -8.70e-02 +/- 3.95e-01 | 5.19e+00 +/- 2.6e-01 | 5.28e+00 +/- 2.9e-01 |
test_objective_compile_atf | +0.62 +/- 5.38 | +1.01e-01 +/- 8.71e-01 | 1.63e+01 +/- 7.0e-01 | 1.62e+01 +/- 5.1e-01 |
test_objective_compute_dshape_current | -0.68 +/- 2.09 | -2.25e-05 +/- 6.96e-05 | 3.31e-03 +/- 6.7e-05 | 3.33e-03 +/- 1.9e-05 |
test_objective_compute_atf | -1.96 +/- 0.90 | -2.22e-04 +/- 1.02e-04 | 1.11e-02 +/- 6.6e-05 | 1.13e-02 +/- 7.8e-05 |
test_objective_jac_dshape_current | +2.19 +/- 13.98 | +2.81e-03 +/- 1.79e-02 | 1.31e-01 +/- 1.6e-02 | 1.28e-01 +/- 7.4e-03 |
test_objective_jac_atf | +2.01 +/- 3.54 | +1.52e-01 +/- 2.68e-01 | 7.71e+00 +/- 1.4e-01 | 7.56e+00 +/- 2.3e-01 |
test_perturb_1 | -1.07 +/- 16.01 | -9.26e-02 +/- 1.39e+00 | 8.58e+00 +/- 9.9e-01 | 8.68e+00 +/- 9.8e-01 |
test_perturb_2 | -0.35 +/- 5.53 | -5.78e-02 +/- 9.05e-01 | 1.63e+01 +/- 6.1e-01 | 1.64e+01 +/- 6.7e-01 | |
# REGCOIL utilities | ||
|
||
|
||
def run_regcoil( # noqa: C901 fxn too complex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still not crazy about this name
… paired with surface current
Question: It would be nice to update our coil tutorial to have a section where we use this functionality to intiialize the coils for optimization, can I add this in this PR?
solve_regularized_surface_current
todesc.magnetic_fields
module that implements the REGCOIL algorithm (Landreman, (2017)) for surface current normal field optimizationcurrent_helicity=(q,p)
to determine if resulting contours correspond to helical topology (both(q,p)
not equal to 0), modular (p
equal to 0 andq
nonzero), PF (p
nonzero butq
zero, so coils don't link the plasma poloidally but they do close toroidally like a PF coil for a tokamak), or windowpane/saddle (p
andq
both zero).q
is number of poloidal transits a current potentiail contour (and consequently, a coil) makes per field period, whilep
is the number of toroidal transits per field period (not really true toroidal transits, but think of it as how many field periods it takes for a coil to return to the same poloidal position on surface, the larger thep
is for fixedq
, the more PF-coil-like the coil topology becomes)regularization_type
which can besimple
orregcoil
, the difference explained here, tldr is simple is not guaranteed to monotonically decreaseTo_CoilSet
toFourierCurrentPotentialField
which implements a coil cutting algorithm to discretize the surface current into coilsskimage.measure.find_contours
instead ofmatplotlib
's deprecated contour finding algorithm, so this PR adds a new dependency inskimage
.SurfaceCurrentRegularization
(which minimizesw*|K|
, the regularization term from surface current in the REGCOIL algorithm, withw
being the objective weight which act as the sqrt of the regularization parameter)QuadraticFlux
objective allows for REGCOIL solutions to be obtained through the optimization framework, and combined with other objectives as well.QuadraticFlux
has asqrt_area_weighting
flag added to make the area weighting be the sqrt of the surface Jacobian, which makes it more in line with the REGCOIL algorithm (as the cost squared and summed should be equal toFalse
which is the current behavior on masterREGCOIL
features.Resolves #578
Remaining TODO (Or for future PRs):
M=0, N=0
mode is inFourierCurrentPotentialField
basis (i.e. whensym_phi="cos" or False
) -> add warning if wrong phi symmetry or somethingrun_regcoil
method - maybe a flag like (set_G_automatically
which sets it based off of the integrated B_zeta from the eq and the external field, if provided) - this is done in the tutorial, it is simple enough so I will leave it as isOld TODO
TODO list:
source_grid_N
, which must be sufficiently large (something likeNFP * basis_N * 2
or*3
at least, whilesource_grid_M
can be 1.5 or 2 timesbasis_M
. eval_grids can be 1.5 or 2 timesbasis_M
andbasis_N
)n_rho
for toroidal surface, but probabnly not important to be compatible with Poincare surfaces right now)sym=False
CLEANUP TODO FOR WORKFLOW: