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

Simplified Bout computation in free boundary #1600

Draft
wants to merge 198 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
198 commits
Select commit Hold shift + click to select a range
c32b2aa
add kernels for solving Laplace equation
dpanici May 29, 2024
b74446f
Merge branch 'master' into dp/laplace
unalmis Nov 8, 2024
93710e9
Merge branch 'master' into dp/laplace
unalmis Nov 12, 2024
acd8516
Add compute_B_laplace
unalmis Nov 13, 2024
38bb3ed
Fixing comment sign
unalmis Nov 13, 2024
a437b8a
Clean up API
unalmis Nov 16, 2024
300e95b
Merge branch 'master' into dp/laplace
unalmis Nov 16, 2024
e8738ec
Merge branch 'master' into dp/laplace
unalmis Nov 20, 2024
20cec4c
Merge branch 'master' into dp/laplace
unalmis Nov 23, 2024
94b1606
Debugging
unalmis Nov 24, 2024
ac9c1f8
Add baseline image for incorrect laplace test
unalmis Nov 24, 2024
1151007
Add tokamak test
unalmis Nov 25, 2024
9d69d47
Fix test
unalmis Nov 25, 2024
2ef0ad1
debugging 2
unalmis Nov 25, 2024
8fe40d0
Clean up unneded compute quantities
unalmis Nov 25, 2024
45405b6
.
unalmis Nov 25, 2024
5896589
Merge branch 'master' into dp/laplace
dpanici Dec 4, 2024
e937867
Merge branch 'master' into dp/laplace
unalmis Dec 5, 2024
6dbf58b
New method; still not working
unalmis Dec 6, 2024
5ad4a31
Correct normalization from previous commit
unalmis Dec 6, 2024
038a2df
Merge branch 'master' into dp/laplace
unalmis Dec 6, 2024
15399ae
Fix factor of in new method
unalmis Dec 6, 2024
9fe6337
Writing up dommaschk test
unalmis Dec 6, 2024
bc768b4
Apparent bug in transforms
unalmis Dec 8, 2024
17f9aba
Dommaschk test stellarator boundary bdotn
unalmis Dec 8, 2024
d4515c9
Failing 3D shape for green's id
unalmis Dec 9, 2024
8fb0d7c
Merge branch 'master' into debug_integral
unalmis Dec 9, 2024
1710819
Merge branch 'master' into dp/laplace
unalmis Dec 9, 2024
bc95043
Merge branch 'master' into dp/laplace
unalmis Dec 11, 2024
bc313a0
Merge branch 'master' into debug_integral
dpanici Dec 11, 2024
cc9862a
Merge branch 'master' into debug_integral
unalmis Dec 22, 2024
b5344c7
Merge branch 'master' into debug_integral
unalmis Jan 8, 2025
0c48769
Merge branch 'master' into debug_integral
unalmis Jan 14, 2025
cd229d9
Merge branch 'master' into debug_integral
dpanici Jan 15, 2025
b9fc895
Merge remote-tracking branch 'origin/debug_integral' into debug_integral
unalmis Jan 15, 2025
0dabf85
Commit failing test
unalmis Jan 16, 2025
3d45932
Merge branch 'master' into debug_integral
dpanici Jan 16, 2025
7bfa014
Merge branch 'master' into debug_integral
dpanici Jan 16, 2025
f78034b
Update FFT interpolator with restriction to avoid frequency truncation
unalmis Jan 17, 2025
9f3f62d
debugging DFTInterpolator
unalmis Jan 17, 2025
2ea5eaf
Merge remote-tracking branch 'origin/debug_integral' into debug_integral
unalmis Jan 17, 2025
7f8a2ea
Merge branch 'debug_integral' into dp/laplace
unalmis Jan 17, 2025
e51ef97
Debugging NFP periodicity
unalmis Jan 18, 2025
2477407
Merge branch 'debug_integral' into dp/laplace
unalmis Jan 18, 2025
faf14aa
Resolves #1524
unalmis Jan 18, 2025
e43690e
Bunt axissymetic case to later
unalmis Jan 18, 2025
8adff59
Allow different NFP only if there is no toroidal variation
unalmis Jan 18, 2025
8256621
Lower bound s by 1 for singular integral resolution...
unalmis Jan 18, 2025
12df7d9
Merge branch 'debug_integral' into dp/laplace
unalmis Jan 18, 2025
f831611
Fixing DFTInterpolator
unalmis Jan 20, 2025
f786430
Merge branch 'debug_integral' into dp/laplace
unalmis Jan 20, 2025
3d661ba
Cache vandermonde matrix
unalmis Jan 20, 2025
b9a13e6
Merge branch 'debug_integral' into dp/laplace
unalmis Jan 20, 2025
2d40524
Merge branch 'master' into debug_integral
unalmis Jan 20, 2025
c1d7066
Avoid constructing large matrix
unalmis Jan 20, 2025
371ec5d
Rename new public function for interpolator
unalmis Jan 21, 2025
6ca4ae7
Genearlize polar grid extent to non-square grids
unalmis Jan 22, 2025
e9e6f72
Resolves #1531
unalmis Jan 22, 2025
4513ee4
Fix comment in commit e9e6f72
unalmis Jan 22, 2025
42f3a6d
Merge branch 'master' into debug_integral
unalmis Jan 22, 2025
ec42c11
Remove now unused kwargs in DoubleFourierSeries
unalmis Jan 22, 2025
dc16ba3
Fix typos in docstrings
unalmis Jan 22, 2025
b7b96b1
Loop over data instead of index in _non_singular_part as this is more…
unalmis Jan 22, 2025
91b7aa1
Merge branch 'master' into debug_integral
unalmis Jan 22, 2025
6b06648
Add second hyperparameter to free boundary objective
unalmis Jan 23, 2025
67060ab
Merge branch 'master' into debug_integral
unalmis Jan 23, 2025
fc47523
Cache vander matrix in bounce integrals
unalmis Jan 23, 2025
1629bdf
.
unalmis Jan 23, 2025
51f5aaa
Update interpolator test
unalmis Jan 23, 2025
178d45c
Make docstrings more verbose as requested by user
unalmis Jan 24, 2025
3c70721
Reuse Vandermonde array to interpolate with JIT fusion
unalmis Jan 24, 2025
6a3ffd4
Comment hanging code
unalmis Jan 24, 2025
2bd67ce
Switch notebook to reverse mode
unalmis Jan 24, 2025
7c3720c
Update master compute data
unalmis Jan 24, 2025
2b3b287
Review request and document work to prove integration is symmetric fo…
unalmis Jan 26, 2025
b91bec1
Usually eval grid and source grid are same, so don't recompute stuff …
unalmis Jan 26, 2025
bd4143f
Add note to docstring for free boundary ob
unalmis Jan 27, 2025
a169caf
Merge branch 'debug_integral' into dp/laplace
unalmis Jan 27, 2025
04600a3
Throw error on axisymmetric devices with NFP 1 and explain why
unalmis Jan 27, 2025
a275e8f
Free boundary speed (#1536)
unalmis Jan 27, 2025
a0c5f2e
Apply suggestions from code review
unalmis Jan 27, 2025
d2657ef
Merge branch 'master' into debug_integral
unalmis Jan 27, 2025
6ef7c89
Merge branch 'master' into debug_integral
unalmis Jan 28, 2025
d0bb776
Merge branch 'master' into debug_integral
unalmis Jan 28, 2025
f76a00a
Outline plan to obtain theoretically better singular partition
unalmis Jan 28, 2025
5ede1bc
Merge branch 'debug_integral' into dp/laplace
unalmis Jan 28, 2025
7c3dd35
Move free boundary changes to new pr
unalmis Jan 29, 2025
25624aa
Merge branch 'master' into debug_integral
unalmis Jan 30, 2025
70a3aab
Merge branch 'master' into debug_integral
dpanici Jan 31, 2025
801af55
Merge branch 'debug_integral' into dp/laplace
unalmis Jan 31, 2025
f9c2789
Appease new jax versions
unalmis Jan 31, 2025
4924f25
Review requests
unalmis Feb 2, 2025
118216e
Merge branch 'debug_integral' into ku_rc/anistropy
unalmis Feb 2, 2025
f7b9569
Merge branch 'debug_integral' into dp/laplace
unalmis Feb 2, 2025
7f57c9e
Merge branch 'master' into debug_integral
unalmis Feb 3, 2025
9de0701
Merge branch 'debug_integral' into ku_rc/anistropy
unalmis Feb 3, 2025
8dfc43d
Update default partiton parameters for free boundary
unalmis Feb 3, 2025
9ef9c05
Switch required data keys to basis vectors
unalmis Feb 3, 2025
c771b55
Merge branch 'debug_integral' into dp/laplace
unalmis Feb 3, 2025
8e58244
PR requests and finish adding chunk_size to free boundary
unalmis Feb 4, 2025
6b589c4
Merge branch 'master' into debug_integral
unalmis Feb 4, 2025
2df9966
Merge branch 'debug_integral' into ku_rc/anistropy
unalmis Feb 4, 2025
04e91a7
Update free boundary docstring for chunking
unalmis Feb 4, 2025
d47ffce
Merge branch 'debug_integral' into ku_rc/anistropy
unalmis Feb 4, 2025
4535594
Merge branch 'debug_integral' into dp/laplace
unalmis Feb 4, 2025
382e64c
Merge branch 'master' into debug_integral
unalmis Feb 4, 2025
811559b
Merge branch 'debug_integral' into dp/laplace
unalmis Feb 4, 2025
23af247
Merge branch 'ku_rc/anistropy' into dp/laplace
unalmis Feb 5, 2025
1a82311
Update to use heuristic params
unalmis Feb 5, 2025
cbd4d64
Speed up biot-savart general and biot-savart vector general
unalmis Feb 5, 2025
cbea125
Simplify loop
unalmis Feb 5, 2025
0f20277
This is why I had just set default to 30 to being with @ddudt and @Yi…
unalmis Feb 5, 2025
c7d415b
Merge branch 'master' into ku_rc/anistropy
unalmis Feb 5, 2025
0c40c9a
Merge branch 'ku_rc/anistropy' into dp/laplace
unalmis Feb 5, 2025
a62b9d2
Merge branch 'master' into ku_rc/anistropy
dpanici Feb 6, 2025
a082068
Treat s parameter as st and sz if given as tuple
unalmis Feb 6, 2025
8bd4b62
Merge branch 'master' into ku/biot
unalmis Feb 6, 2025
a804c4a
Adding chunk_size to remaining places
unalmis Feb 6, 2025
ea7646d
Requested cosmetic changes
unalmis Feb 6, 2025
2b45a1e
Merge branch 'ku_rc/anistropy' into dp/laplace
unalmis Feb 6, 2025
76c5f06
Update test to reduce memory
unalmis Feb 6, 2025
86b4ebd
Add chunk size = 40 to regularized surface current tests
unalmis Feb 6, 2025
076830b
SEt regularize surf current chunk size to 20
unalmis Feb 6, 2025
ca118a4
Update desc/magnetic_fields/_core.py
unalmis Feb 7, 2025
b56c95a
Update desc/magnetic_fields/_core.py
unalmis Feb 7, 2025
f0f12db
Liberally decrease chunk_size in tests to avoid future commits
unalmis Feb 7, 2025
c4ec089
Set chunk size to 1 in objectives for now
unalmis Feb 7, 2025
f9c0547
Update laplace stuff after debugging interals PR
unalmis Feb 7, 2025
376b307
doesn't pass old test
unalmis Feb 7, 2025
3ca0aab
Merge branch 'master' into ku/biot
dpanici Feb 7, 2025
d2f56d4
Merge branch 'master' into dp/laplace
unalmis Feb 8, 2025
7be0c09
testign
unalmis Feb 9, 2025
57c96ce
Adapt netket stuff for batched reduce
unalmis Feb 9, 2025
be213c1
Try using regular jnp.sum instead of tree add
unalmis Feb 9, 2025
320e8a8
Batch reduce chunking
unalmis Feb 10, 2025
04b5c01
Fix for JAX bug
unalmis Feb 10, 2025
9409c59
Replace confusing filtering
unalmis Feb 10, 2025
119e04e
Don't construct large array, split scans into two functions
unalmis Feb 10, 2025
467cb41
Remove invalid code
unalmis Feb 10, 2025
8abfe5b
Resolves #1386
unalmis Feb 10, 2025
90af245
Fix subtle bug
unalmis Feb 10, 2025
67409d6
Fix reshape bug
unalmis Feb 10, 2025
1d1b882
Only unchunk if no reduction
unalmis Feb 10, 2025
7e46929
add chunk size to regcoil notebook
dpanici Feb 10, 2025
91393a8
Merge branch 'master' into ku/biot
unalmis Feb 10, 2025
d98339e
Making cosmetic changes required in pull request
unalmis Feb 10, 2025
a0c9414
Merge branch 'ku/batch_reduce' into dp/laplace
unalmis Feb 10, 2025
59edc9d
Merge branch 'master' into ku/biot
unalmis Feb 11, 2025
d028bdd
Change chunk size to None
unalmis Feb 11, 2025
04933c2
don't use imap
unalmis Feb 11, 2025
e39f2dd
Merge branch 'master' into ku/biot
unalmis Feb 11, 2025
18ca59a
Reverting commit d028bdd6c3a15cfc414f26e34318ea714cd0e380
unalmis Feb 11, 2025
f6d1f6e
Merge branch 'master' into ku_rc/anistropy
unalmis Feb 11, 2025
7716aa9
Merge branch 'master' into dp/laplace
unalmis Feb 11, 2025
a06ca55
Merge branch 'ku/biot' into dp/laplace
unalmis Feb 11, 2025
2f65629
Merge branch 'master' into ku_rc/anistropy
YigitElma Feb 11, 2025
d2d3092
Merge branch 'master' into ku/biot
YigitElma Feb 11, 2025
a7509f3
Reducing chunk size more
unalmis Feb 11, 2025
162beee
Reducing chunk size mo
unalmis Feb 11, 2025
27aebec
Add chunk size to solve regularize current
unalmis Feb 11, 2025
4ef2c85
Merge branch 'ku/biot' into dp/laplace
unalmis Feb 11, 2025
3303bd2
Merge branch 'master' into ku/biot
dpanici Feb 11, 2025
f49bb62
Merge branch 'ku/biot' into dp/laplace
unalmis Feb 12, 2025
f108109
Merge branch 'master' into ku/biot
dpanici Feb 12, 2025
9c2f5ab
Merge branch 'master' into ku_rc/anistropy
dpanici Feb 12, 2025
a9b8c76
Add chunk size arg
unalmis Feb 12, 2025
51ecd05
Increase chunking
unalmis Feb 12, 2025
e8545d5
Rename to bs_chunk_size
unalmis Feb 13, 2025
877fa98
add kwargs
unalmis Feb 14, 2025
661b1ec
Merge branch 'master' into ku/biot
unalmis Feb 14, 2025
3c8867a
Merge branch 'master' into ku/biot
unalmis Feb 14, 2025
8cb73d2
Merge branch 'ku/biot' into dp/laplace
unalmis Feb 14, 2025
aaa0129
Updating tests
unalmis Feb 19, 2025
3d728a1
Merge branch 'master' into ku/biot
unalmis Feb 19, 2025
99f92f5
Merge branch 'ku/biot' into dp/laplace
unalmis Feb 19, 2025
fb06fd1
Merge branch 'master' into ku_rc/anistropy
unalmis Feb 19, 2025
e70c9ee
Make sure theta is on outboard side in test
unalmis Feb 19, 2025
5cf7a95
Add more general test
unalmis Feb 19, 2025
aa7e51f
Add flag to docstring
unalmis Feb 19, 2025
f7b7d08
Switch to vmap identity
unalmis Feb 19, 2025
6215bd9
Use vmap chunked
unalmis Feb 19, 2025
893d329
Workaround JAX bug with nan linear algebra solve
unalmis Feb 20, 2025
b65af7e
Reduce tolerance
unalmis Feb 20, 2025
5d49a37
Fix heuristic params for axisymmetry
f0uriest Feb 20, 2025
59cca07
Merge branch 'ku_rc/anistropy' into dp/laplace
unalmis Feb 20, 2025
e2f7ed1
move docstring to correct test
unalmis Feb 20, 2025
4e77f0f
cosmetic change to avoid confusion
unalmis Feb 20, 2025
ffcc6a1
better comment in test
unalmis Feb 20, 2025
faa14e6
Remove image compare for now
unalmis Feb 20, 2025
9d09393
Halfway through debugging
unalmis Feb 21, 2025
7a1b30d
Add nfp loop wrapper
unalmis Feb 22, 2025
7ec2f7c
Fix laplace solver
unalmis Feb 22, 2025
e2a9b21
Add markers for tests
unalmis Feb 22, 2025
1a73002
Merge branch 'master' into ku/biot
unalmis Feb 22, 2025
22f1dcd
Merge branch 'ku/biot' into dp/laplace
unalmis Feb 22, 2025
c7b996d
Finalize API for vacuum solver
unalmis Feb 23, 2025
ae53815
Allow solving overdetermined system and passing remaining tests
unalmis Feb 23, 2025
50b2ac3
Add warnings about JAX bug
unalmis Feb 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ New Features
- Adds batching feature to singular integrals.
- ``desc.objectives.CoilSetMinDistance`` and ``desc.objectives.PlasmaCoilSetMinDistance`` now include the option to use a softmin which can give smoother gradients. They also both now have a ``dist_chunk_size`` option to break up the distance calculation into smaller pieces to save memory
- Adds a new function ``desc.coils.initialize_helical_coils`` for creating an initial guess for stage 2 helical coil optimization.
- Adds ``chunk_size`` option to compute magnetic field methods to increase performance.
- Adds ``desc.vmec_utils.make_boozmn_output `` for writing boozmn.nc style output files
for compatibility with other codes which expect such files from the Booz_Xform code.
- Renames compute quantity ``sqrt(g)_B`` to ``sqrt(g)_Boozer_DESC`` to more accurately reflect what the quantiy is (the jacobian from (rho,theta_B,zeta_B) to (rho,theta,zeta)), and adds a new function to compute ``sqrt(g)_Boozer`` which is the jacobian from (rho,theta_B,zeta_B) to (R,phi,Z).
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Contribute
- `Contributing guidelines <https://github.com/PlasmaControl/DESC/blob/master/CONTRIBUTING.rst>`_
- `Issue Tracker <https://github.com/PlasmaControl/DESC/issues>`_
- `Source Code <https://github.com/PlasmaControl/DESC/>`_
- `Documentation <https://desc-docs.readthedocs.io/>`_
- `Documentation <https://desc-docs.readthedocs.io/en/latest/>`_

.. |License| image:: https://img.shields.io/github/license/PlasmaControl/desc?color=blue&logo=open-source-initiative&logoColor=white
:target: https://github.com/PlasmaControl/DESC/blob/master/LICENSE
Expand Down
26 changes: 11 additions & 15 deletions desc/batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
----------
The ``_batch_and_remainder``, ``_evaluate_in_chunks``, ``jacrev_chunked``,
and ``jacfwd_chunked`` functions are adapted from JAX.
https://github.com/jax-ml/jax/blob/main/jax/_src/lax/control_flow/loops.py#L2139.
https://github.com/jax-ml/jax/blob/main/jax/_src/lax/control_flow/loops.py#L2209.
https://github.com/jax-ml/jax/blob/main/jax/_src/lax/control_flow/loops.py.
https://github.com/jax-ml/jax/blob/main/jax/_src/api.py.

The original copyright notice is as follows
Expand Down Expand Up @@ -42,7 +41,7 @@
tree_transpose,
)

from desc.backend import jax, jnp, scan
from desc.backend import jax, jnp, scan, vmap
from desc.utils import errorif

if jax.__version_info__ >= (0, 4, 16):
Expand Down Expand Up @@ -191,7 +190,7 @@ def vmap_chunked(
reduction=None,
chunk_reduction=_identity,
):
"""Behaves like jax.vmap but uses scan to chunk the computations in smaller chunks.
"""Behaves like ``vmap`` but uses scan to chunk the computations in smaller chunks.

Parameters
----------
Expand All @@ -217,10 +216,7 @@ def vmap_chunked(

"""
in_axes, argnums = _parse_in_axes(in_axes)
if isinstance(argnums, int):
argnums = (argnums,)

f = jax.vmap(f, in_axes=in_axes)
f = vmap(f, in_axes=in_axes)
if chunk_size is None:
return lambda *args, **kwargs: chunk_reduction(f(*args, **kwargs))
return partial(
Expand All @@ -244,12 +240,11 @@ def batch_map(
):
"""Compute ``chunk_reduction(fun(fun_input))`` in batches.

This utility is like ``desc.backend.imap(fun,fun_input,batch_size)`` except that
``fun`` is assumed to be vectorized natively. No JAX vectorization such as ``vmap``
is applied to the supplied function. This makes compilation faster and avoids the
weaknesses of applying JAX vectorization, such as executing all branches of code
conditioned on dynamic values. For example, this function would be useful for
GitHub issue #1303.
This utility is like ``vmap_chunked`` except that ``fun`` is assumed to be
vectorized natively. No JAX vectorization such as ``vmap`` is applied to the
supplied function. This makes compilation faster and avoids the weaknesses of
applying JAX vectorization, such as executing all branches of code conditioned on
dynamic values. For example, this function would be useful for GitHub issue #1303.

Parameters
----------
Expand All @@ -265,7 +260,8 @@ def batch_map(
Should take two arguments and return one output, e.g. ``jnp.add``.
chunk_reduction : callable
Chunk-wise reduction operation.
Should apply ``reduction`` along the mapped axis, e.g. ``jnp.add.reduce``.
Should typically apply ``reduction`` along the mapped axis,
e.g. ``jnp.add.reduce``.

Returns
-------
Expand Down
Loading
Loading