Skip to content

Conversation

@akaptano
Copy link
Contributor

@akaptano akaptano commented May 8, 2025

As discussed with @mishapadidar, @landreman and others, I am opening a pull request here to first get the force and torque overhaul changes merged into main. Then I will open a new pull request that adds in the dipole array and passive coil array work. Then a third pull request will be opened for other fixes on that branch. My hope is to have this ready by the end of today May 8.

To be clear, I have stripped out all of the passive and dipole array stuff. However this still includes a number of little fixes in addition to the big changes in the force and torque calculations. In addition, I have systematically added comments to all the changed files to narrate my thinking as you do your review. To summarize, the changes include:

  1. Adding the force and torque overhauls in force.py, and leaving the old calculations as deprecated functions (useful for checking unit tests, and also they still run faster than the overhauled ones if you don't use too many coils).
  2. Added a number of curve-related objects, including JaxPlanarFourier, JaxCurrent, CurvePlanarEllipticalCylindrical and so on. Also there was a huge bug in the C++ code calculation of the CurvePlanarFourier Jacobian, which gave weird Taylor test failures. I fixed this with the help of @AlexWiedman.
  3. Added a series of example files related to doing coil force optimization, see examples/3_Advanced/coil_force_optimization/. Some of the files allow for giant Pareto scans -- these are courtesy of Matt and Siena.
  4. Added some testing for the new functionality.
  5. Added an optional "downsample" integer to all the coil objectives that are expensive to compute. Downsample integer just downsamples the quadrature points of the coil to speed up calculations. Taylor test checks remain robust despite the downsampling. Note that this is better/easier than resampling the coil points because there is no need to interpolate gamma, gammadash, etc.

…on.py working fully with Jax objects. Had to make some changes for correctly dealing with coils obtained by symmetries, and rotated curves, and so far can plot the curves and initial surface errors correctly.
…s, and now optimizing over the sum of the net forces squared over all the coils.
…energy and inductance calculations working. Started a version of the self force from hurwitz paper but havent finished, and not sure how I will debug.
…at the frenet frame is not implemented for the JaxCurves so need to do this myself in the curve.py file. Also tested that the torque and tve objectives along have good-looking taylor tests and do sensible things when run them on the basic stage two example.
…ion objectives that compute the net torques and net forces from one set of coils onto another set of coils with different parameters (e.g. TF coils vs dipole coils with differing number of quadpoints).
…26 dipole coils and some fiddling, can get to 9e-4 or so solution in Bn_over_B. Feels like plenty still to hyperparameter tune there. Still need to test and debug the self force calculation and double check all the tve stuff. Then run a self force scan and add to paper.
…ions. Net force minimization does minimize net forces better but at cost of much higher pointwise forces. Maybe can combine the objectives.
…lculation from JaxCurves. Switching to Greene to try gpus again.
…ce calculations by directly computing BiotSavart, rather than calling a BiotSavart object in the loop, which gets very slow with many coils as the number of Optimizable objects balloon. Self forces also appear intolerably high, even for basic planar TF coils. Need to discuss this.
…ying to get various examples in order now and generate Pareto plots.
@akaptano akaptano mentioned this pull request May 28, 2025
"""

def __init__(self, curve, current):
def __init__(self, curve, current, regularization=regularization_circ(0.05)):
Copy link
Contributor

Choose a reason for hiding this comment

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

@akaptano what is the plan here?

#!/usr/bin/env python

"""
coil_force_pareto_scans.py
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should move this example to another location. The pareto scans are useful, but examples may not be the right home for them, since they are more of a utility than an instruction example. I don't exactly know where to put them for now, since we dont have a directory for this type of thing in simsopt at the moment.

optimization_tools.py
---------------------

This module provides tools for large-scale parameter scans and optimization workflows for stellarator coil design using SIMSOPT. It includes routines for:
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should talk about what to do with this function. PyTorch, for example, has a separate module, PytorchLightning, where useful tools have been built for accelerating typical tasks. Anyhow, there are some options.

#!/usr/bin/env python

"""
initiation.py
Copy link
Contributor

Choose a reason for hiding this comment

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

agree the scans are useful. I think we need to find the right home for them.

pointData = {**pointData, **extra_data}
curves_to_vtk(curves, filename, close=close, extra_data=pointData)

def coils_via_symmetries(curves, currents, nfp, stellsym, regularizations=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

i see. i think there is value in having the RegularizedCurve class or something similar.

@akaptano
Copy link
Contributor Author

@mishapadidar I have implemented the RegularizedCoil class and moved some of the pareto scans to a file utils/coil_optimization_helper_functions.py. Unfortunately this also ballooned the PR a bit, since now those helper functions need unit tests. Let me know if you have any last changes.

@akaptano
Copy link
Contributor Author

akaptano commented Aug 4, 2025

@mishapadidar @andrewgiuliani friendly monthly reminder

@mishapadidar
Copy link
Contributor

Hi, Alan, these are great changes. To continue with the review process, it would be helpful to break up this PR into more pieces. The idea is to try to separate the PR into self-contained pieces. We will be able to review smaller pieces more quickly. Here is a suggested breakdown.

  1. coil.py and curve.py and relevant unit tests. coil.py file has mostly self-contained changed, like the RegularizedCoil class and a bunch of documentation. The coils_to_vtk probably needs to wait until a later PR because of dependencies. curve.py Seems like only small changes have been made, so might as well include it in this PR.
  2. force.py, selffield.py and relevant unit tests. Also correct any examples that are broken, but don't add new examples yet. If this can somehow be split into 2 PRs, that would also be useful, but I suspect these functions all need to land at once. The goal here is to land the main coil-force functionality in a small PR.

At this point, the core functionality of this PR will have landed. The remaining bits such as example_coils.rst, the coils_to_vtk function, new examples, changes to the permanent magnet examples, or helpers can go in later PRs.

@akaptano @landreman @andrewgiuliani

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants