Advanced Optimization

In this tutorial we will show an example of “precise” QS optimization using a multigrid approach, and using constrained optimization

[1]:
import sys
import os

sys.path.insert(0, os.path.abspath("."))
sys.path.append(os.path.abspath("../../../"))
[2]:
import numpy as np

from desc.continuation import solve_continuation_automatic
from desc.equilibrium import EquilibriaFamily, Equilibrium
from desc.geometry import FourierRZToroidalSurface
from desc.grid import LinearGrid
from desc.objectives import (
    AspectRatio,
    FixBoundaryR,
    FixBoundaryZ,
    FixCurrent,
    FixPressure,
    FixPsi,
    ForceBalance,
    ObjectiveFunction,
    QuasisymmetryTwoTerm,
)
from desc.optimize import Optimizer
DESC version 0.10.2+349.g81f43916.dirty,using JAX backend, jax version=0.4.13, jaxlib version=0.4.13, dtype=float64
Using device: CPU, with 5.10 GB available memory

Initial Guess

We start by creating an initial equilibrium and solving a standard fixed boundary problem:

[3]:
# create initial surface. Aspect ratio ~ 8, circular cross section with slight
# axis torsion to make it nonplanar
surf = FourierRZToroidalSurface(
    R_lmn=[1, 0.125, 0.1],
    Z_lmn=[-0.125, -0.1],
    modes_R=[[0, 0], [1, 0], [0, 1]],
    modes_Z=[[-1, 0], [0, -1]],
    NFP=4,
)
# create initial equilibrium. Psi chosen to give B ~ 1 T. Could also give profiles here,
# default is zero pressure and zero current
eq = Equilibrium(M=4, N=4, Psi=0.04, surface=surf)
# this is usually all you need to solve a fixed boundary equilibrium
eq0 = solve_continuation_automatic(eq, verbose=0)[-1]

# it will be helpful to store intermediate results
eqfam = EquilibriaFamily(eq0)

Multigrid method with proximal optimizer

By “multigrid” method we mean we will start by optimizing over boundary modes with \(|m|, |n| \leq 1\), then \(|m|, |n| \leq 2\) and so on. To do this we’ll define a helper function that will create the necessary constraints and objectives for a given maximum mode number \(k\).

By a “proximal” optimizer we mean one that handles the equilibrium constraint by re-solving a fixed boundary equilibrium problem at each step, given the current position of the boundary. This is made more efficient by using a perturbed estimate based on the previous step as a warm start to the equilibrium sub-problem.

[4]:
def run_qh_step(k, eq):
    """Run a step of the precise QH optimization example from Landreman & Paul."""
    # this step will only optimize boundary modes with |m|,|n| <= k

    # create grid where we want to minimize QS error. Here we do it on 3 surfaces
    grid = LinearGrid(
        M=eq.M_grid, N=eq.N_grid, NFP=eq.NFP, rho=np.array([0.6, 0.8, 1.0]), sym=True
    )

    # we create an ObjectiveFunction, in this case made up of multiple objectives
    # which will be combined in a least squares sense
    objective = ObjectiveFunction(
        (
            # pass in the grid we defined, and don't forget the target helicity!
            QuasisymmetryTwoTerm(eq=eq, helicity=(1, eq.NFP), grid=grid),
            # try to keep the aspect ratio about the same
            AspectRatio(eq=eq, target=8, weight=100),
        ),
    )
    # as opposed to SIMSOPT and STELLOPT where variables are assumed fixed, in DESC
    # we assume variables are free. Here we decide which ones to fix, starting with
    # the major radius (R mode = [0,0,0]) and all modes with m,n > k
    R_modes = np.vstack(
        (
            [0, 0, 0],
            eq.surface.R_basis.modes[
                np.max(np.abs(eq.surface.R_basis.modes), 1) > k, :
            ],
        )
    )
    Z_modes = eq.surface.Z_basis.modes[
        np.max(np.abs(eq.surface.Z_basis.modes), 1) > k, :
    ]
    # next we create the constraints, using the mode number arrays just created
    # if we didn't pass those in, it would fix all the modes (like for the profiles)
    constraints = (
        ForceBalance(eq=eq),
        FixBoundaryR(eq=eq, modes=R_modes),
        FixBoundaryZ(eq=eq, modes=Z_modes),
        FixPressure(eq=eq),
        FixCurrent(eq=eq),
        FixPsi(eq=eq),
    )
    # this is the default optimizer, which re-solves the equilibrium at each step
    optimizer = Optimizer("proximal-lsq-exact")

    eq_new, history = eq.optimize(
        objective=objective,
        constraints=constraints,
        optimizer=optimizer,
        maxiter=20,  # we don't need to solve to optimality at each multigrid step
        verbose=3,
        copy=True,  # don't modify original, return a new optimized copy
        options={
            # Sometimes the default initial trust radius is too big, allowing the
            # optimizer to take too large a step in a bad direction. If this happens,
            # we can manually specify a smaller starting radius. Each optimizer has a
            # number of different options that can be used to tune the performance.
            # See the documentation for more info.
            "initial_trust_ratio": 1.0,
        },
    )

    return eq_new

Lets look at the initial field:

[5]:
from desc.plotting import plot_boozer_surface

plot_boozer_surface(eq0);
../../_images/notebooks_tutorials_advanced_optimization_11_0.png

We see that it is vaguely QH like, which is why we’re targeting QH symmetry. Now let’s run the optimization in steps and look at the intermediate result after each step:

[6]:
eq1 = run_qh_step(1, eq0)
eqfam.append(eq1)
plot_boozer_surface(eq1);
Building objective: QS two-term
Precomputing transforms
Timer: Precomputing transforms = 1.80 sec
Building objective: aspect ratio
Precomputing transforms
Timer: Precomputing transforms = 160 ms
Timer: Objective build = 2.96 sec
Building objective: force
Precomputing transforms
Timer: Precomputing transforms = 675 ms
Timer: Objective build = 1.37 sec
Timer: Proximal projection build = 10.2 sec
Timer: Linear constraint projection build = 7.24 sec
Compiling objective function and derivatives: ['QS two-term', 'aspect ratio']
Timer: Objective compilation time = 6.40 sec
Timer: Jacobian compilation time = 13.5 sec
Timer: Total compilation time = 20.0 sec
Compiling objective function and derivatives: ['force']
Timer: Objective compilation time = 5.01 sec
Timer: Jacobian compilation time = 12.0 sec
Timer: Total compilation time = 17.0 sec
Number of parameters: 8
Number of objectives: 460
Starting optimization
Using method: proximal-lsq-exact
   Iteration     Total nfev        Cost      Cost reduction    Step norm     Optimality
       0              1          9.423e+01                                    4.153e+03
       1              4          8.246e+01      1.177e+01      3.949e-02      1.520e+04
       2              5          6.107e+01      2.138e+01      2.860e-02      7.766e+02
       3              6          5.550e+01      5.570e+00      4.691e-02      1.101e+03
       4              7          5.327e+01      2.233e+00      3.093e-02      1.153e+03
       5              8          5.129e+01      1.981e+00      3.706e-02      4.521e+03
       6              9          5.049e+01      7.967e-01      5.597e-02      9.557e+02
       7             10          4.868e+01      1.816e+00      1.419e-02      7.632e+02
       8             11          4.671e+01      1.971e+00      1.270e-02      9.588e+02
       9             12          4.341e+01      3.300e+00      1.321e-02      1.451e+03
      10             13          3.975e+01      3.658e+00      1.839e-02      6.927e+03
      11             14          3.427e+01      5.482e+00      2.885e-02      5.602e+03
      12             16          3.084e+01      3.421e+00      1.464e-02      6.814e+02
      13             17          2.769e+01      3.158e+00      2.349e-02      1.494e+03
      14             19          2.636e+01      1.324e+00      1.927e-02      5.056e+03
      15             20          2.474e+01      1.620e+00      1.998e-02      5.038e+03
      16             21          2.332e+01      1.425e+00      1.874e-02      8.541e+02
      17             23          2.324e+01      7.529e-02      4.844e-03      1.858e+02
Optimization terminated successfully.
`ftol` condition satisfied.
         Current function value: 2.324e+01
         Total delta_x: 1.517e-01
         Iterations: 17
         Function evaluations: 23
         Jacobian evaluations: 18
Timer: Solution time = 3.84 min
Timer: Avg time per step = 12.8 sec
Start of solver
Total (sum of squares):  9.423e+01,
Maximum absolute Quasi-symmetry (1,4) two-term error:  6.254e-01 (T^3)
Minimum absolute Quasi-symmetry (1,4) two-term error:  2.245e-04 (T^3)
Average absolute Quasi-symmetry (1,4) two-term error:  1.502e-01 (T^3)
Maximum absolute Quasi-symmetry (1,4) two-term error:  1.057e+00 (normalized)
Minimum absolute Quasi-symmetry (1,4) two-term error:  3.795e-04 (normalized)
Average absolute Quasi-symmetry (1,4) two-term error:  2.539e-01 (normalized)
Aspect ratio:  8.000e+00 (dimensionless)
Maximum absolute Force error:  4.313e+01 (N)
Minimum absolute Force error:  9.195e-04 (N)
Average absolute Force error:  3.601e+00 (N)
Maximum absolute Force error:  6.234e-05 (normalized)
Minimum absolute Force error:  1.329e-09 (normalized)
Average absolute Force error:  5.205e-06 (normalized)
R boundary error:  0.000e+00 (m)
Z boundary error:  0.000e+00 (m)
Fixed-pressure profile error:  0.000e+00 (Pa)
Fixed-current profile error:  0.000e+00 (A)
Fixed-Psi error:  0.000e+00 (Wb)
End of solver
Total (sum of squares):  2.324e+01,
Maximum absolute Quasi-symmetry (1,4) two-term error:  4.818e-01 (T^3)
Minimum absolute Quasi-symmetry (1,4) two-term error:  9.029e-05 (T^3)
Average absolute Quasi-symmetry (1,4) two-term error:  7.068e-02 (T^3)
Maximum absolute Quasi-symmetry (1,4) two-term error:  8.145e-01 (normalized)
Minimum absolute Quasi-symmetry (1,4) two-term error:  1.526e-04 (normalized)
Average absolute Quasi-symmetry (1,4) two-term error:  1.195e-01 (normalized)
Aspect ratio:  7.998e+00 (dimensionless)
Maximum absolute Force error:  1.253e+03 (N)
Minimum absolute Force error:  1.489e-01 (N)
Average absolute Force error:  9.588e+01 (N)
Maximum absolute Force error:  1.811e-03 (normalized)
Minimum absolute Force error:  2.152e-07 (normalized)
Average absolute Force error:  1.386e-04 (normalized)
R boundary error:  0.000e+00 (m)
Z boundary error:  0.000e+00 (m)
Fixed-pressure profile error:  0.000e+00 (Pa)
Fixed-current profile error:  0.000e+00 (A)
Fixed-Psi error:  0.000e+00 (Wb)
../../_images/notebooks_tutorials_advanced_optimization_13_1.png
[7]:
eq2 = run_qh_step(2, eq1)
eqfam.append(eq2)
plot_boozer_surface(eq2);
Building objective: QS two-term
Precomputing transforms
Timer: Precomputing transforms = 310 ms
Building objective: aspect ratio
Precomputing transforms
Timer: Precomputing transforms = 109 ms
Timer: Objective build = 962 ms
Building objective: force
Precomputing transforms
Timer: Precomputing transforms = 397 ms
Timer: Objective build = 984 ms
Timer: Proximal projection build = 5.55 sec
Timer: Linear constraint projection build = 4.54 sec
Compiling objective function and derivatives: ['QS two-term', 'aspect ratio']
Timer: Objective compilation time = 4.01 sec
Timer: Jacobian compilation time = 11.1 sec
Timer: Total compilation time = 15.1 sec
Compiling objective function and derivatives: ['force']
Timer: Objective compilation time = 4.51 sec
Timer: Jacobian compilation time = 14.6 sec
Timer: Total compilation time = 19.2 sec
Number of parameters: 24
Number of objectives: 460
Starting optimization
Using method: proximal-lsq-exact
   Iteration     Total nfev        Cost      Cost reduction    Step norm     Optimality
       0              1          3.109e+01                                    1.586e+03
       1              5          2.219e+01      8.903e+00      1.439e-02      4.001e+03
       2              6          1.403e+01      8.155e+00      3.303e-02      6.524e+03
       3              8          8.437e+00      5.595e+00      9.715e-03      8.742e+02
       4              9          6.044e+00      2.393e+00      1.921e-02      2.964e+03
       5             11          5.278e+00      7.659e-01      5.627e-03      8.179e+02
       6             12          4.692e+00      5.856e-01      8.703e-03      1.637e+03
       7             13          4.113e+00      5.794e-01      5.893e-03      5.518e+02
       8             14          3.658e+00      4.547e-01      1.003e-02      3.154e+03
       9             15          2.785e+00      8.730e-01      8.626e-03      1.575e+03
      10             16          2.187e+00      5.985e-01      1.336e-02      7.123e+02
      11             18          1.893e+00      2.937e-01      5.728e-03      5.760e+02
      12             19          1.880e+00      1.294e-02      1.193e-02      2.821e+03
      13             20          1.445e+00      4.353e-01      3.216e-03      1.391e+02
      14             21          1.299e+00      1.459e-01      6.089e-03      4.461e+02
      15             22          1.182e+00      1.169e-01      1.410e-02      1.220e+03
      16             23          1.007e+00      1.744e-01      1.629e-02      1.973e+03
      17             25          7.627e-01      2.447e-01      5.088e-03      4.127e+02
      18             26          7.460e-01      1.672e-02      9.078e-03      1.233e+03
      19             27          6.547e-01      9.127e-02      2.390e-03      1.025e+02
      20             28          6.215e-01      3.321e-02      4.337e-03      3.748e+02
Warning: Maximum number of iterations has been exceeded.
         Current function value: 6.215e-01
         Total delta_x: 1.502e-01
         Iterations: 20
         Function evaluations: 28
         Jacobian evaluations: 21
Timer: Solution time = 3.26 min
Timer: Avg time per step = 9.33 sec
Start of solver
Total (sum of squares):  3.109e+01,
Maximum absolute Quasi-symmetry (1,4) two-term error:  4.818e-01 (T^3)
Minimum absolute Quasi-symmetry (1,4) two-term error:  9.029e-05 (T^3)
Average absolute Quasi-symmetry (1,4) two-term error:  7.068e-02 (T^3)
Maximum absolute Quasi-symmetry (1,4) two-term error:  9.421e-01 (normalized)
Minimum absolute Quasi-symmetry (1,4) two-term error:  1.765e-04 (normalized)
Average absolute Quasi-symmetry (1,4) two-term error:  1.382e-01 (normalized)
Aspect ratio:  7.998e+00 (dimensionless)
Maximum absolute Force error:  1.253e+03 (N)
Minimum absolute Force error:  1.489e-01 (N)
Average absolute Force error:  9.588e+01 (N)
Maximum absolute Force error:  1.804e-03 (normalized)
Minimum absolute Force error:  2.144e-07 (normalized)
Average absolute Force error:  1.381e-04 (normalized)
R boundary error:  0.000e+00 (m)
Z boundary error:  0.000e+00 (m)
Fixed-pressure profile error:  0.000e+00 (Pa)
Fixed-current profile error:  0.000e+00 (A)
Fixed-Psi error:  0.000e+00 (Wb)
End of solver
Total (sum of squares):  6.215e-01,
Maximum absolute Quasi-symmetry (1,4) two-term error:  1.234e-01 (T^3)
Minimum absolute Quasi-symmetry (1,4) two-term error:  6.713e-06 (T^3)
Average absolute Quasi-symmetry (1,4) two-term error:  1.165e-02 (T^3)
Maximum absolute Quasi-symmetry (1,4) two-term error:  2.412e-01 (normalized)
Minimum absolute Quasi-symmetry (1,4) two-term error:  1.313e-05 (normalized)
Average absolute Quasi-symmetry (1,4) two-term error:  2.278e-02 (normalized)
Aspect ratio:  7.999e+00 (dimensionless)
Maximum absolute Force error:  1.232e+03 (N)
Minimum absolute Force error:  1.190e-01 (N)
Average absolute Force error:  7.949e+01 (N)
Maximum absolute Force error:  1.774e-03 (normalized)
Minimum absolute Force error:  1.714e-07 (normalized)
Average absolute Force error:  1.145e-04 (normalized)
R boundary error:  0.000e+00 (m)
Z boundary error:  0.000e+00 (m)
Fixed-pressure profile error:  0.000e+00 (Pa)
Fixed-current profile error:  0.000e+00 (A)
Fixed-Psi error:  0.000e+00 (Wb)
../../_images/notebooks_tutorials_advanced_optimization_14_1.png
[8]:
eq3 = run_qh_step(3, eq2)
eqfam.append(eq3)
plot_boozer_surface(eq3);
Building objective: QS two-term
Precomputing transforms
Timer: Precomputing transforms = 266 ms
Building objective: aspect ratio
Precomputing transforms
Timer: Precomputing transforms = 101 ms
Timer: Objective build = 835 ms
Building objective: force
Precomputing transforms
Timer: Precomputing transforms = 315 ms
Timer: Objective build = 749 ms
Timer: Proximal projection build = 4.70 sec
Timer: Linear constraint projection build = 3.65 sec
Compiling objective function and derivatives: ['QS two-term', 'aspect ratio']
Timer: Objective compilation time = 3.28 sec
Timer: Jacobian compilation time = 10.2 sec
Timer: Total compilation time = 13.5 sec
Compiling objective function and derivatives: ['force']
Timer: Objective compilation time = 3.42 sec
Timer: Jacobian compilation time = 8.46 sec
Timer: Total compilation time = 11.8 sec
Number of parameters: 48
Number of objectives: 460
Starting optimization
Using method: proximal-lsq-exact
   Iteration     Total nfev        Cost      Cost reduction    Step norm     Optimality
       0              1          1.867e-01                                    2.779e+02
       1              4          1.362e-01      5.049e-02      8.403e-03      1.093e+03
       2              5          7.282e-02      6.336e-02      6.335e-03      2.703e+02
       3              6          5.950e-02      1.332e-02      1.046e-02      2.943e+02
       4              8          4.629e-02      1.321e-02      2.567e-03      6.922e+01
       5             10          4.329e-02      3.003e-03      1.527e-03      8.364e+01
       6             11          4.197e-02      1.322e-03      2.638e-03      2.095e+02
       7             12          4.034e-02      1.622e-03      2.950e-03      7.675e+01
       8             13          4.014e-02      2.049e-04      2.807e-03      5.107e+01
       9             14          3.734e-02      2.804e-03      9.085e-04      2.310e+01
      10             15          3.416e-02      3.172e-03      8.279e-04      1.280e+01
      11             17          3.317e-02      9.911e-04      4.345e-04      1.135e+01
      12             18          3.288e-02      2.940e-04      8.289e-04      2.862e+01
      13             19          3.211e-02      7.696e-04      2.738e-04      9.855e+00
      14             20          3.172e-02      3.871e-04      2.293e-04      5.621e+00
      15             21          3.147e-02      2.544e-04      2.039e-04      4.856e+00
Optimization terminated successfully.
`ftol` condition satisfied.
         Current function value: 3.147e-02
         Total delta_x: 3.196e-02
         Iterations: 15
         Function evaluations: 21
         Jacobian evaluations: 16
Timer: Solution time = 2.12 min
Timer: Avg time per step = 7.97 sec
Start of solver
Total (sum of squares):  1.867e-01,
Maximum absolute Quasi-symmetry (1,4) two-term error:  1.234e-01 (T^3)
Minimum absolute Quasi-symmetry (1,4) two-term error:  6.713e-06 (T^3)
Average absolute Quasi-symmetry (1,4) two-term error:  1.165e-02 (T^3)
Maximum absolute Quasi-symmetry (1,4) two-term error:  1.315e-01 (normalized)
Minimum absolute Quasi-symmetry (1,4) two-term error:  7.157e-06 (normalized)
Average absolute Quasi-symmetry (1,4) two-term error:  1.242e-02 (normalized)
Aspect ratio:  7.999e+00 (dimensionless)
Maximum absolute Force error:  1.232e+03 (N)
Minimum absolute Force error:  1.190e-01 (N)
Average absolute Force error:  7.949e+01 (N)
Maximum absolute Force error:  1.174e-03 (normalized)
Minimum absolute Force error:  1.134e-07 (normalized)
Average absolute Force error:  7.576e-05 (normalized)
R boundary error:  0.000e+00 (m)
Z boundary error:  0.000e+00 (m)
Fixed-pressure profile error:  0.000e+00 (Pa)
Fixed-current profile error:  0.000e+00 (A)
Fixed-Psi error:  0.000e+00 (Wb)
End of solver
Total (sum of squares):  3.147e-02,
Maximum absolute Quasi-symmetry (1,4) two-term error:  7.439e-02 (T^3)
Minimum absolute Quasi-symmetry (1,4) two-term error:  4.349e-05 (T^3)
Average absolute Quasi-symmetry (1,4) two-term error:  4.727e-03 (T^3)
Maximum absolute Quasi-symmetry (1,4) two-term error:  7.931e-02 (normalized)
Minimum absolute Quasi-symmetry (1,4) two-term error:  4.636e-05 (normalized)
Average absolute Quasi-symmetry (1,4) two-term error:  5.040e-03 (normalized)
Aspect ratio:  8.000e+00 (dimensionless)
Maximum absolute Force error:  1.053e+03 (N)
Minimum absolute Force error:  2.290e-02 (N)
Average absolute Force error:  7.573e+01 (N)
Maximum absolute Force error:  1.003e-03 (normalized)
Minimum absolute Force error:  2.183e-08 (normalized)
Average absolute Force error:  7.217e-05 (normalized)
R boundary error:  0.000e+00 (m)
Z boundary error:  0.000e+00 (m)
Fixed-pressure profile error:  0.000e+00 (Pa)
Fixed-current profile error:  0.000e+00 (A)
Fixed-Psi error:  0.000e+00 (Wb)
../../_images/notebooks_tutorials_advanced_optimization_15_1.png

We see that after only 3 multigrid steps we have achieved very straight contours of magnetic field strength. These could be further refined by running for more iterations, using higher resolution, tighter tolerances, etc.

As a final comparison, we’ll look at the maximum symmetry breaking boozer harmonic for each step of the equilibrium

[9]:
import matplotlib.pyplot as plt
from desc.plotting import plot_boozer_modes, plot_boundaries

fig, ax = plt.subplots()
colors = ["r", "g", "c", "m"]

for i, (eq, color) in enumerate(zip(eqfam, colors)):
    plot_boozer_modes(
        eq, color=color, helicity=(1, eq.NFP), max_only=True, label=f"Step {i}", ax=ax
    )
../../_images/notebooks_tutorials_advanced_optimization_17_0.png

Constrained Optimization

Next, we’ll do a similar optimization but this time treating it as a constrained optimization problem, where we attempt to minimize QS error subject to more complicated constraints. We’ll start with the same QS objective:

[10]:
# create grid where we want to minimize QS error. Here we do it on 3 surfaces
grid = LinearGrid(
    M=eq0.M_grid, N=eq0.N_grid, NFP=eq0.NFP, rho=np.array([0.6, 0.8, 1.0]), sym=True
)

objective = ObjectiveFunction(
    (
        # pass in the grid we defined, and don't forget the target helicity!
        QuasisymmetryTwoTerm(eq=eq0, helicity=(1, eq.NFP), grid=grid),
    ),
)

For constraints, we’ll include the standard force balance to start. In the previous example, fixing certain boundary modes served as a form of regularization to prevent the solution from going into a bad local minimum. In this case however, instead of fixing a range of boundary modes we will only fix the \(R_{00}\) mode, and include constraints on aspect ratio, volume, and elongation to keep the solution from going off in a bad direction.

Finally, we also include a constraint on the average rotational transform:

[11]:
from desc.objectives import Elongation, RotationalTransform, Volume

constraints = (
    ForceBalance(eq=eq0),
    # try to keep the aspect ratio between 7 and 9
    AspectRatio(eq=eq0, bounds=(7, 9)),
    # similarly, try to keep it from getting too elongated
    Elongation(eq=eq0, bounds=(0, 3)),
    # Keep volume the same as the initial volume
    Volume(eq=eq0, target=eq0.compute("V")["V"]),
    # target for average iota
    RotationalTransform(eq=eq0, target=1.1, loss_function="mean"),
    # fix major radius
    FixBoundaryR(eq=eq0, modes=[0, 0, 0]),
    # fix vacuum profiles
    FixPressure(eq=eq0),
    FixCurrent(eq=eq0),
    FixPsi(eq=eq0),
)

Finally, we’ll use an optimizer that can handle general nonlinear constraints (the proximal-lsq-exact optimizer can only handle equilibrium constraints such as ForceBalance and regular linear constraints like Fix*). In this case we use a least-squares augmented Lagrangian method.

[12]:
optimizer = Optimizer("lsq-auglag")

eqa, history = eq0.optimize(
    objective=objective,
    constraints=constraints,
    optimizer=optimizer,
    # each iteration of the augmented Lagrangian optimizer is cheaper than a step of a
    # proximal optimizer, but it generally requires more iterations to converge
    maxiter=200,
    copy=True,
    verbose=3,
    options={},
)
Building objective: QS two-term
Precomputing transforms
Timer: Precomputing transforms = 299 ms
Timer: Objective build = 674 ms
Building objective: force
Precomputing transforms
Timer: Precomputing transforms = 410 ms
Building objective: aspect ratio
Precomputing transforms
Timer: Precomputing transforms = 91.8 ms
Building objective: elongation
Precomputing transforms
Timer: Precomputing transforms = 103 ms
Building objective: volume
Precomputing transforms
Timer: Precomputing transforms = 123 ms
Building objective: rotational transform
Precomputing transforms
Timer: Precomputing transforms = 333 ms
Timer: Objective build = 1.95 sec
Timer: Linear constraint projection build = 2.60 sec
Timer: Linear constraint projection build = 579 ms
Compiling objective function and derivatives: ['QS two-term']
Timer: Objective compilation time = 4.04 sec
Timer: Jacobian compilation time = 5.62 sec
Timer: Total compilation time = 9.66 sec
Compiling objective function and derivatives: ['force', 'aspect ratio', 'elongation', 'volume', 'rotational transform']
Timer: Objective compilation time = 6.23 sec
Timer: Jacobian compilation time = 19.7 sec
Timer: Total compilation time = 25.9 sec
Number of parameters: 200
Number of objectives: 459
Number of equality constraints: 852
Number of inequality constraints: 2
Starting optimization
Using method: lsq-auglag
   Iteration     Total nfev        Cost      Cost reduction    Step norm     Optimality    Constr viol.   Penalty param  max(|mltplr|)
       0              1          9.423e+01                                    2.535e+04      8.524e-01      1.000e+01      0.000e+00
       1              2          8.928e+01      4.946e+00      2.366e-03      2.432e+04      8.529e-01      1.000e+01      0.000e+00
       2              3          7.155e+01      1.773e+01      1.011e-02      2.052e+04      8.549e-01      1.000e+01      0.000e+00
       3              4          2.579e+01      4.576e+01      4.726e-02      9.456e+03      8.631e-01      1.000e+01      0.000e+00
       4              5          7.248e-01      2.506e+01      1.965e-01      1.096e+03      7.395e-01      1.000e+01      0.000e+00
       5              6          3.209e-01      4.039e-01      2.309e-01      6.392e+02      6.714e-01      1.000e+01      0.000e+00
       6              8          3.874e-01     -6.645e-02      2.018e-01      9.620e+02      6.040e-01      1.000e+01      0.000e+00
       7              9          3.286e-01      5.881e-02      1.856e-01      1.071e+03      4.975e-01      1.000e+01      0.000e+00
       8             11          2.261e-01      1.025e-01      1.753e-01      7.539e+02      3.956e-01      1.000e+01      0.000e+00
       9             13          1.919e-01      3.420e-02      1.454e-01      9.533e+02      2.664e-01      1.000e+01      0.000e+00
      10             15          2.009e-01     -9.069e-03      1.664e-01      1.204e+03      1.662e-01      1.000e+01      0.000e+00
      11             16          1.208e-01      8.011e-02      1.170e-01      1.195e+03      9.163e-02      1.000e+01      0.000e+00
      12             18          1.180e-01      2.802e-03      8.148e-02      1.063e+03      5.671e-02      1.000e+01      0.000e+00
      13             19          4.382e-02      7.419e-02      2.402e-02      7.702e+01      5.216e-02      1.000e+01      0.000e+00
      14             21          4.199e-02      1.835e-03      1.966e-02      8.617e+01      4.792e-02      1.000e+01      0.000e+00
      15             23          3.987e-02      2.114e-03      1.873e-02      8.328e+01      4.405e-02      1.000e+01      0.000e+00
      16             25          3.790e-02      1.977e-03      1.983e-02      8.068e+01      4.071e-02      1.000e+01      0.000e+00
      17             27          3.598e-02      1.922e-03      1.909e-02      8.079e+01      3.770e-02      1.000e+01      0.000e+00
      18             29          3.414e-02      1.839e-03      1.900e-02      8.224e+01      3.496e-02      1.000e+01      0.000e+00
      19             31          3.236e-02      1.778e-03      1.899e-02      8.423e+01      3.244e-02      1.000e+01      0.000e+00
      20             33          3.064e-02      1.721e-03      1.902e-02      8.703e+01      3.009e-02      1.000e+01      0.000e+00
      21             35          2.897e-02      1.667e-03      1.907e-02      9.055e+01      2.841e-02      1.000e+01      0.000e+00
      22             37          2.737e-02      1.604e-03      1.912e-02      9.454e+01      2.705e-02      1.000e+01      0.000e+00
      23             39          2.584e-02      1.526e-03      2.061e-02      9.853e+01      2.575e-02      1.000e+01      0.000e+00
      24             41          2.442e-02      1.423e-03      2.017e-02      1.022e+02      2.452e-02      1.000e+01      0.000e+00
      25             43          2.311e-02      1.303e-03      2.017e-02      1.048e+02      2.337e-02      1.000e+01      0.000e+00
      26             45          2.194e-02      1.172e-03      2.010e-02      1.063e+02      2.230e-02      1.000e+01      0.000e+00
      27             47          2.090e-02      1.044e-03      1.995e-02      1.063e+02      2.133e-02      1.000e+01      0.000e+00
      28             49          1.996e-02      9.333e-04      1.972e-02      1.105e+02      2.045e-02      1.000e+01      0.000e+00
      29             51          1.912e-02      8.465e-04      1.941e-02      1.123e+02      1.966e-02      1.000e+01      0.000e+00
      30             53          1.833e-02      7.852e-04      1.904e-02      1.117e+02      1.911e-02      1.000e+01      0.000e+00
      31             55          1.759e-02      7.459e-04      1.861e-02      1.088e+02      1.896e-02      1.000e+01      0.000e+00
      32             57          1.686e-02      7.229e-04      1.815e-02      1.043e+02      1.878e-02      1.000e+01      0.000e+00
      33             59          1.615e-02      7.110e-04      1.767e-02      9.863e+01      1.857e-02      1.000e+01      0.000e+00
      34             61          1.545e-02      7.067e-04      1.719e-02      9.222e+01      1.833e-02      1.000e+01      0.000e+00
      35             63          1.474e-02      7.059e-04      1.672e-02      8.610e+01      1.806e-02      1.000e+01      0.000e+00
      36             65          1.403e-02      7.057e-04      1.626e-02      8.282e+01      1.778e-02      1.000e+01      0.000e+00
      37             67          1.333e-02      7.048e-04      1.582e-02      7.694e+01      1.748e-02      1.000e+01      0.000e+00
      38             69          1.263e-02      7.022e-04      1.538e-02      6.840e+01      1.717e-02      1.000e+01      0.000e+00
      39             71          1.193e-02      6.959e-04      1.494e-02      5.748e+01      1.686e-02      1.000e+01      0.000e+00
      40             73          1.125e-02      6.838e-04      1.447e-02      4.850e+01      1.683e-02      1.000e+01      0.000e+00
      41             75          1.058e-02      6.626e-04      1.399e-02      4.105e+01      1.679e-02      1.000e+01      0.000e+00
      42             77          9.955e-03      6.295e-04      1.347e-02      3.383e+01      1.673e-02      1.000e+01      0.000e+00
      43             79          9.371e-03      5.834e-04      1.293e-02      3.898e+01      1.664e-02      1.000e+01      0.000e+00
      44             81          8.844e-03      5.272e-04      1.237e-02      4.512e+01      1.653e-02      1.000e+01      0.000e+00
      45             83          8.377e-03      4.672e-04      1.180e-02      5.044e+01      1.640e-02      1.000e+01      0.000e+00
      46             85          7.967e-03      4.100e-04      1.127e-02      5.488e+01      1.624e-02      1.000e+01      0.000e+00
      47             87          7.607e-03      3.602e-04      1.078e-02      5.841e+01      1.607e-02      1.000e+01      0.000e+00
      48             89          7.289e-03      3.182e-04      1.031e-02      6.095e+01      1.589e-02      1.000e+01      0.000e+00
      49             91          7.005e-03      2.833e-04      9.854e-03      6.230e+01      1.571e-02      1.000e+01      0.000e+00
      50             93          6.749e-03      2.563e-04      9.365e-03      6.240e+01      1.553e-02      1.000e+01      0.000e+00
      51             95          6.510e-03      2.387e-04      8.852e-03      6.161e+01      1.535e-02      1.000e+01      0.000e+00
      52             97          6.281e-03      2.295e-04      8.352e-03      6.058e+01      1.518e-02      1.000e+01      0.000e+00
      53             99          6.055e-03      2.254e-04      7.899e-03      5.977e+01      1.500e-02      1.000e+01      0.000e+00
      54             101         5.833e-03      2.224e-04      7.502e-03      5.939e+01      1.483e-02      1.000e+01      0.000e+00
      55             103         5.616e-03      2.166e-04      7.142e-03      5.960e+01      1.465e-02      1.000e+01      0.000e+00
      56             105         5.410e-03      2.068e-04      6.800e-03      6.052e+01      1.448e-02      1.000e+01      0.000e+00
      57             107         5.215e-03      1.949e-04      6.682e-03      6.195e+01      1.429e-02      1.000e+01      0.000e+00
      58             109         5.032e-03      1.828e-04      6.355e-03      6.351e+01      1.411e-02      1.000e+01      0.000e+00
      59             111         4.860e-03      1.717e-04      6.113e-03      6.478e+01      1.392e-02      1.000e+01      0.000e+00
      60             113         4.699e-03      1.614e-04      5.896e-03      6.564e+01      1.372e-02      1.000e+01      0.000e+00
      61             115         4.547e-03      1.515e-04      5.703e-03      6.605e+01      1.352e-02      1.000e+01      0.000e+00
      62             117         4.405e-03      1.423e-04      5.535e-03      6.607e+01      1.332e-02      1.000e+01      0.000e+00
      63             119         4.271e-03      1.336e-04      5.394e-03      6.578e+01      1.311e-02      1.000e+01      0.000e+00
      64             121         4.146e-03      1.256e-04      5.280e-03      6.524e+01      1.291e-02      1.000e+01      0.000e+00
      65             123         4.027e-03      1.186e-04      5.193e-03      6.449e+01      1.270e-02      1.000e+01      0.000e+00
      66             125         3.915e-03      1.123e-04      5.132e-03      6.361e+01      1.250e-02      1.000e+01      0.000e+00
      67             127         3.808e-03      1.067e-04      5.093e-03      6.265e+01      1.230e-02      1.000e+01      0.000e+00
      68             129         3.707e-03      1.017e-04      5.072e-03      6.168e+01      1.210e-02      1.000e+01      0.000e+00
      69             131         3.609e-03      9.711e-05      5.067e-03      6.077e+01      1.191e-02      1.000e+01      0.000e+00
      70             133         3.516e-03      9.296e-05      5.074e-03      6.001e+01      1.172e-02      1.000e+01      0.000e+00
      71             135         3.427e-03      8.918e-05      5.091e-03      5.948e+01      1.154e-02      1.000e+01      0.000e+00
      72             137         3.342e-03      8.572e-05      5.119e-03      5.926e+01      1.136e-02      1.000e+01      0.000e+00
      73             139         3.259e-03      8.249e-05      5.156e-03      5.944e+01      1.119e-02      1.000e+01      0.000e+00
      74             141         3.180e-03      7.937e-05      5.202e-03      6.008e+01      1.102e-02      1.000e+01      0.000e+00
      75             143         3.103e-03      7.624e-05      5.257e-03      6.120e+01      1.086e-02      1.000e+01      0.000e+00
      76             145         3.030e-03      7.302e-05      5.318e-03      6.278e+01      1.070e-02      1.000e+01      0.000e+00
      77             147         2.961e-03      6.971e-05      5.383e-03      6.472e+01      1.055e-02      1.000e+01      0.000e+00
      78             149         2.894e-03      6.641e-05      5.446e-03      6.682e+01      1.039e-02      1.000e+01      0.000e+00
      79             151         2.831e-03      6.337e-05      5.502e-03      6.881e+01      1.025e-02      1.000e+01      0.000e+00
      80             153         2.770e-03      6.092e-05      5.545e-03      7.037e+01      1.011e-02      1.000e+01      0.000e+00
      81             155         2.711e-03      5.948e-05      5.573e-03      7.116e+01      9.983e-03      1.000e+01      0.000e+00
      82             157         2.651e-03      5.924e-05      5.588e-03      7.092e+01      9.859e-03      1.000e+01      0.000e+00
      83             159         2.591e-03      5.988e-05      5.595e-03      6.954e+01      9.736e-03      1.000e+01      0.000e+00
      84             161         2.531e-03      6.059e-05      5.598e-03      6.706e+01      9.617e-03      1.000e+01      0.000e+00
      85             163         2.470e-03      6.057e-05      5.601e-03      6.365e+01      9.500e-03      1.000e+01      0.000e+00
      86             165         2.411e-03      5.943e-05      5.605e-03      5.954e+01      9.385e-03      1.000e+01      0.000e+00
      87             167         2.354e-03      5.723e-05      5.608e-03      5.495e+01      9.272e-03      1.000e+01      0.000e+00
      88             169         2.299e-03      5.425e-05      5.609e-03      5.008e+01      9.159e-03      1.000e+01      0.000e+00
      89             171         2.249e-03      5.082e-05      5.608e-03      4.509e+01      9.047e-03      1.000e+01      0.000e+00
      90             173         2.201e-03      4.719e-05      5.604e-03      4.012e+01      8.934e-03      1.000e+01      0.000e+00
      91             175         2.158e-03      4.361e-05      5.597e-03      3.528e+01      8.819e-03      1.000e+01      0.000e+00
      92             177         2.118e-03      4.023e-05      5.587e-03      3.066e+01      8.704e-03      1.000e+01      0.000e+00
      93             179         2.080e-03      3.719e-05      5.576e-03      2.632e+01      8.586e-03      1.000e+01      0.000e+00
      94             181         2.046e-03      3.458e-05      5.564e-03      2.380e+01      8.467e-03      1.000e+01      0.000e+00
      95             183         2.013e-03      3.241e-05      5.552e-03      2.253e+01      8.347e-03      1.000e+01      0.000e+00
      96             185         1.983e-03      3.069e-05      5.540e-03      2.186e+01      8.225e-03      1.000e+01      0.000e+00
      97             187         1.953e-03      2.941e-05      5.527e-03      2.129e+01      8.103e-03      1.000e+01      0.000e+00
      98             189         1.925e-03      2.854e-05      5.514e-03      2.078e+01      7.980e-03      1.000e+01      0.000e+00
      99             191         1.897e-03      2.805e-05      5.499e-03      2.114e+01      7.858e-03      1.000e+01      0.000e+00
      100            193         1.869e-03      2.792e-05      5.481e-03      2.153e+01      7.736e-03      1.000e+01      0.000e+00
      101            195         1.841e-03      2.811e-05      5.461e-03      2.180e+01      7.616e-03      1.000e+01      0.000e+00
      102            197         1.812e-03      2.860e-05      5.437e-03      2.191e+01      7.497e-03      1.000e+01      0.000e+00
      103            199         1.783e-03      2.937e-05      5.409e-03      2.181e+01      7.380e-03      1.000e+01      0.000e+00
      104            201         1.752e-03      3.037e-05      5.373e-03      2.146e+01      7.266e-03      1.000e+01      0.000e+00
      105            203         1.721e-03      3.154e-05      5.328e-03      2.087e+01      7.157e-03      1.000e+01      0.000e+00
      106            205         1.688e-03      3.275e-05      5.269e-03      2.005e+01      7.052e-03      1.000e+01      0.000e+00
      107            207         1.654e-03      3.382e-05      5.193e-03      1.919e+01      6.953e-03      1.000e+01      0.000e+00
      108            209         1.620e-03      3.451e-05      5.106e-03      1.936e+01      6.861e-03      1.000e+01      0.000e+00
      109            211         1.585e-03      3.460e-05      5.019e-03      1.966e+01      6.777e-03      1.000e+01      0.000e+00
      110            213         1.551e-03      3.390e-05      4.949e-03      2.038e+01      6.701e-03      1.000e+01      0.000e+00
      111            215         1.519e-03      3.232e-05      4.912e-03      2.182e+01      6.634e-03      1.000e+01      0.000e+00
      112            217         1.489e-03      3.012e-05      4.920e-03      2.404e+01      6.575e-03      1.000e+01      0.000e+00
      113            219         1.460e-03      2.847e-05      4.970e-03      2.675e+01      6.520e-03      1.000e+01      0.000e+00
      114            221         1.430e-03      2.990e-05      5.040e-03      2.932e+01      6.468e-03      1.000e+01      0.000e+00
      115            223         1.394e-03      3.649e-05      5.094e-03      3.102e+01      6.416e-03      1.000e+01      0.000e+00
      116            225         1.348e-03      4.539e-05      5.106e-03      3.125e+01      6.363e-03      1.000e+01      0.000e+00
      117            227         1.299e-03      4.952e-05      5.088e-03      2.925e+01      6.306e-03      1.000e+01      0.000e+00
      118            229         1.252e-03      4.664e-05      5.084e-03      2.765e+01      6.245e-03      1.000e+01      0.000e+00
      119            231         1.211e-03      4.108e-05      5.122e-03      2.790e+01      6.179e-03      1.000e+01      0.000e+00
      120            233         1.175e-03      3.655e-05      5.204e-03      2.708e+01      6.109e-03      1.000e+01      0.000e+00
      121            235         1.141e-03      3.399e-05      5.319e-03      2.568e+01      6.036e-03      1.000e+01      0.000e+00
      122            237         1.108e-03      3.304e-05      5.747e-03      2.671e+01      5.962e-03      1.000e+01      0.000e+00
      123            239         1.074e-03      3.321e-05      5.678e-03      2.698e+01      5.887e-03      1.000e+01      0.000e+00
      124            241         1.041e-03      3.334e-05      5.862e-03      2.637e+01      5.813e-03      1.000e+01      0.000e+00
      125            243         1.008e-03      3.353e-05      6.041e-03      2.513e+01      5.740e-03      1.000e+01      0.000e+00
      126            245         9.744e-04      3.315e-05      6.206e-03      2.346e+01      5.668e-03      1.000e+01      0.000e+00
      127            247         9.423e-04      3.219e-05      6.353e-03      2.154e+01      5.597e-03      1.000e+01      0.000e+00
      128            249         9.115e-04      3.072e-05      6.482e-03      1.957e+01      5.526e-03      1.000e+01      0.000e+00
      129            251         8.827e-04      2.889e-05      6.591e-03      1.767e+01      5.454e-03      1.000e+01      0.000e+00
      130            253         8.558e-04      2.683e-05      6.685e-03      1.891e+01      5.380e-03      1.000e+01      0.000e+00
      131            255         8.312e-04      2.464e-05      6.768e-03      2.024e+01      5.304e-03      1.000e+01      0.000e+00
      132            257         8.087e-04      2.246e-05      6.845e-03      2.136e+01      5.225e-03      1.000e+01      0.000e+00
      133            259         7.882e-04      2.048e-05      6.918e-03      2.240e+01      5.142e-03      1.000e+01      0.000e+00
      134            261         7.693e-04      1.893e-05      6.987e-03      2.357e+01      5.055e-03      1.000e+01      0.000e+00
      135            263         7.513e-04      1.804e-05      7.047e-03      2.518e+01      4.999e-03      1.000e+01      0.000e+00
      136            265         7.333e-04      1.797e-05      7.093e-03      2.773e+01      4.966e-03      1.000e+01      0.000e+00
      137            267         7.146e-04      1.870e-05      7.124e-03      3.231e+01      4.931e-03      1.000e+01      0.000e+00
      138            269         6.949e-04      1.970e-05      1.100e-02      4.113e+01      4.897e-03      1.000e+01      0.000e+00
      139            271         6.904e-04      4.540e-06      9.924e-03      6.028e+01      4.865e-03      1.000e+01      0.000e+00
      140            273         7.199e-04     -2.951e-05      9.468e-03      9.279e+01      4.850e-03      1.000e+01      0.000e+00
      141            274         6.753e-04      4.455e-05      8.923e-03      1.030e+02      4.795e-03      1.000e+01      0.000e+00
      142            275         6.404e-04      3.497e-05      9.047e-03      9.258e+01      4.707e-03      1.000e+01      0.000e+00
      143            276         5.915e-04      4.888e-05      9.906e-03      7.440e+01      4.617e-03      1.000e+01      0.000e+00
      144            278         5.427e-04      4.874e-05      1.062e-02      4.786e+01      4.526e-03      1.000e+01      0.000e+00
      145            280         5.225e-04      2.026e-05      1.091e-02      2.831e+01      4.435e-03      1.000e+01      0.000e+00
      146            282         5.171e-04      5.351e-06      1.092e-02      1.804e+01      4.343e-03      1.000e+01      0.000e+00
      147            284         5.150e-04      2.168e-06      1.081e-02      1.541e+01      4.252e-03      1.000e+01      0.000e+00
      148            286         5.132e-04      1.797e-06      1.064e-02      1.519e+01      4.161e-03      1.000e+01      0.000e+00
      149            288         5.111e-04      2.112e-06      1.453e-02      1.585e+01      4.073e-03      1.000e+01      0.000e+00
      150            290         5.086e-04      2.441e-06      1.449e-02      1.581e+01      3.984e-03      1.000e+01      0.000e+00
      151            292         5.059e-04      2.705e-06      1.443e-02      1.648e+01      3.896e-03      1.000e+01      0.000e+00
      152            294         5.025e-04      3.394e-06      1.441e-02      1.792e+01      3.810e-03      1.000e+01      0.000e+00
      153            296         4.984e-04      4.132e-06      1.441e-02      1.961e+01      3.725e-03      1.000e+01      0.000e+00
      154            298         4.934e-04      4.962e-06      1.444e-02      2.114e+01      3.641e-03      1.000e+01      0.000e+00
      155            300         4.876e-04      5.822e-06      1.449e-02      2.239e+01      3.568e-03      1.000e+01      0.000e+00
      156            301         4.809e-04      6.694e-06      1.697e-02      2.428e+01      3.514e-03      1.000e+01      0.000e+00
      157            303         4.717e-04      9.185e-06      2.099e-02      2.353e+01      3.436e-03      1.000e+01      0.000e+00
      158            305         4.636e-04      8.080e-06      2.017e-02      2.307e+01      3.364e-03      1.000e+01      0.000e+00
      159            307         4.543e-04      9.319e-06      1.882e-02      2.095e+01      3.302e-03      1.000e+01      0.000e+00
      160            309         4.468e-04      7.549e-06      2.429e-02      2.257e+01      3.229e-03      1.000e+01      0.000e+00
      161            311         4.371e-04      9.710e-06      2.342e-02      2.098e+01      3.158e-03      1.000e+01      0.000e+00
      162            313         4.280e-04      9.087e-06      2.350e-02      1.983e+01      3.089e-03      1.000e+01      0.000e+00
      163            315         4.189e-04      9.074e-06      2.369e-02      1.850e+01      3.019e-03      1.000e+01      0.000e+00
      164            317         4.097e-04      9.246e-06      2.393e-02      1.701e+01      2.950e-03      1.000e+01      0.000e+00
      165            319         4.004e-04      9.254e-06      2.418e-02      1.538e+01      2.882e-03      1.000e+01      0.000e+00
      166            321         3.912e-04      9.244e-06      2.443e-02      1.400e+01      2.816e-03      1.000e+01      0.000e+00
      167            323         3.820e-04      9.204e-06      2.467e-02      1.279e+01      2.751e-03      1.000e+01      0.000e+00
      168            325         3.728e-04      9.189e-06      2.491e-02      1.174e+01      2.688e-03      1.000e+01      0.000e+00
      169            327         3.636e-04      9.213e-06      2.512e-02      1.057e+01      2.627e-03      1.000e+01      0.000e+00
      170            329         3.543e-04      9.269e-06      2.532e-02      1.012e+01      2.569e-03      1.000e+01      0.000e+00
      171            331         3.450e-04      9.322e-06      2.549e-02      1.117e+01      2.513e-03      1.000e+01      0.000e+00
      172            333         3.356e-04      9.335e-06      2.563e-02      1.184e+01      2.460e-03      1.000e+01      0.000e+00
      173            335         3.263e-04      9.283e-06      2.574e-02      1.219e+01      2.410e-03      1.000e+01      0.000e+00
      174            337         3.172e-04      9.158e-06      2.582e-02      1.230e+01      2.362e-03      1.000e+01      0.000e+00
      175            339         3.082e-04      8.968e-06      2.586e-02      1.225e+01      2.316e-03      1.000e+01      0.000e+00
      176            341         2.995e-04      8.728e-06      2.587e-02      1.209e+01      2.273e-03      1.000e+01      0.000e+00
      177            343         2.910e-04      8.453e-06      2.584e-02      1.187e+01      2.231e-03      1.000e+01      0.000e+00
      178            345         2.829e-04      8.150e-06      2.574e-02      1.214e+01      2.192e-03      1.000e+01      0.000e+00
      179            347         2.751e-04      7.817e-06      2.555e-02      1.274e+01      2.154e-03      1.000e+01      0.000e+00
      180            349         2.676e-04      7.430e-06      2.519e-02      1.347e+01      2.119e-03      1.000e+01      0.000e+00
      181            351         2.607e-04      6.913e-06      2.454e-02      1.446e+01      2.086e-03      1.000e+01      0.000e+00
      182            353         2.547e-04      6.061e-06      2.336e-02      1.598e+01      2.057e-03      1.000e+01      0.000e+00
      183            355         2.504e-04      4.297e-06      2.116e-02      1.847e+01      2.032e-03      1.000e+01      0.000e+00
      184            357         2.501e-04      2.855e-07      1.717e-02      2.247e+01      2.015e-03      1.000e+01      0.000e+00
      185            358         2.572e-04     -7.100e-06      1.117e-02      3.080e+01      2.022e-03      1.000e+01      0.000e+00
      186            359         2.193e-04      3.784e-05      3.320e-03      3.273e+00      2.019e-03      1.000e+01      0.000e+00
      187            361         2.176e-04      1.789e-06      2.101e-03      2.592e+00      2.021e-03      1.000e+01      0.000e+00
      188            363         2.161e-04      1.480e-06      1.102e-03      2.598e+00      2.027e-03      1.000e+01      0.000e+00
      189            365         2.142e-04      1.881e-06      1.196e-03      2.707e+00      2.032e-03      1.000e+01      0.000e+00
      190            367         2.121e-04      2.091e-06      1.289e-03      3.089e+00      2.038e-03      1.000e+01      0.000e+00
      191            369         2.099e-04      2.148e-06      1.281e-03      3.158e+00      2.042e-03      1.000e+01      0.000e+00
      192            371         2.079e-04      2.046e-06      1.339e-03      3.613e+00      2.046e-03      1.000e+01      0.000e+00
      193            373         2.061e-04      1.850e-06      1.386e-03      4.257e+00      2.049e-03      1.000e+01      0.000e+00
      194            375         2.045e-04      1.580e-06      1.426e-03      4.759e+00      2.051e-03      1.000e+01      0.000e+00
      195            377         2.032e-04      1.308e-06      1.465e-03      5.132e+00      2.053e-03      1.000e+01      0.000e+00
      196            379         2.021e-04      1.069e-06      1.503e-03      5.426e+00      2.053e-03      1.000e+01      0.000e+00
      197            381         2.012e-04      8.669e-07      1.541e-03      5.684e+00      2.054e-03      1.000e+01      0.000e+00
      198            383         2.005e-04      6.989e-07      1.580e-03      5.928e+00      2.053e-03      1.000e+01      0.000e+00
      199            385         2.000e-04      5.598e-07      1.617e-03      6.164e+00      2.052e-03      1.000e+01      0.000e+00
      200            387         1.995e-04      4.455e-07      1.654e-03      6.394e+00      2.051e-03      1.000e+01      0.000e+00
Warning: Maximum number of iterations has been exceeded.
         Current function value: 1.995e-04
         Constraint violation: 2.051e-03
         Total delta_x: 4.208e-01
         Iterations: 200
         Function evaluations: 387
         Jacobian evaluations: 200
Timer: Solution time = 1.97 min
Timer: Avg time per step = 589 ms
Start of solver
Total (sum of squares):  9.423e+01,
Maximum absolute Quasi-symmetry (1,4) two-term error:  6.254e-01 (T^3)
Minimum absolute Quasi-symmetry (1,4) two-term error:  2.245e-04 (T^3)
Average absolute Quasi-symmetry (1,4) two-term error:  1.502e-01 (T^3)
Maximum absolute Quasi-symmetry (1,4) two-term error:  1.057e+00 (normalized)
Minimum absolute Quasi-symmetry (1,4) two-term error:  3.795e-04 (normalized)
Average absolute Quasi-symmetry (1,4) two-term error:  2.539e-01 (normalized)
Maximum absolute Force error:  4.313e+01 (N)
Minimum absolute Force error:  9.195e-04 (N)
Average absolute Force error:  3.601e+00 (N)
Maximum absolute Force error:  6.234e-05 (normalized)
Minimum absolute Force error:  1.329e-09 (normalized)
Average absolute Force error:  5.205e-06 (normalized)
Aspect ratio:  8.000e+00 (dimensionless)
Elongation:  1.058e+00 (dimensionless)
Plasma volume:  3.084e-01 (m^3)
Plasma volume:  0.000e+00 (normalized error)
Maximum Rotational transform:  2.476e-01 (dimensionless)
Minimum Rotational transform:  2.476e-01 (dimensionless)
Average Rotational transform:  2.476e-01 (dimensionless)
R boundary error:  0.000e+00 (m)
Fixed-pressure profile error:  0.000e+00 (Pa)
Fixed-current profile error:  0.000e+00 (A)
Fixed-Psi error:  0.000e+00 (Wb)
End of solver
Total (sum of squares):  1.995e-04,
Maximum absolute Quasi-symmetry (1,4) two-term error:  4.092e-03 (T^3)
Minimum absolute Quasi-symmetry (1,4) two-term error:  6.760e-09 (T^3)
Average absolute Quasi-symmetry (1,4) two-term error:  2.300e-04 (T^3)
Maximum absolute Quasi-symmetry (1,4) two-term error:  6.918e-03 (normalized)
Minimum absolute Quasi-symmetry (1,4) two-term error:  1.143e-08 (normalized)
Average absolute Quasi-symmetry (1,4) two-term error:  3.888e-04 (normalized)
Maximum absolute Force error:  2.243e+03 (N)
Minimum absolute Force error:  1.088e-01 (N)
Average absolute Force error:  1.715e+02 (N)
Maximum absolute Force error:  3.242e-03 (normalized)
Minimum absolute Force error:  1.573e-07 (normalized)
Average absolute Force error:  2.479e-04 (normalized)
Aspect ratio:  7.917e+00 (dimensionless)
Elongation:  3.000e+00 (dimensionless)
Plasma volume:  3.084e-01 (m^3)
Plasma volume:  6.587e-05 (normalized error)
Maximum Rotational transform:  1.102e+00 (dimensionless)
Minimum Rotational transform:  1.102e+00 (dimensionless)
Average Rotational transform:  1.102e+00 (dimensionless)
R boundary error:  0.000e+00 (m)
Fixed-pressure profile error:  0.000e+00 (Pa)
Fixed-current profile error:  0.000e+00 (A)
Fixed-Psi error:  0.000e+00 (Wb)

As before, results can be improved by running for more iterations. Note the constraint violation may be larger than desired, so it can be helpful to call eq.solve() at the end to decrease the force error without changing the boundary.

[13]:
eqa.solve();
Building objective: force
Precomputing transforms
Compiling objective function and derivatives: ['force']
Number of parameters: 120
Number of objectives: 850
Starting optimization
Using method: lsq-exact
Optimization terminated successfully.
`ftol` condition satisfied.
         Current function value: 3.103e-06
         Total delta_x: 7.049e-02
         Iterations: 3
         Function evaluations: 4
         Jacobian evaluations: 4
Start of solver
Total (sum of squares):  5.427e-05,
Maximum absolute Force error:  2.243e+03 (N)
Minimum absolute Force error:  1.088e-01 (N)
Average absolute Force error:  1.715e+02 (N)
Maximum absolute Force error:  1.870e-03 (normalized)
Minimum absolute Force error:  9.071e-08 (normalized)
Average absolute Force error:  1.430e-04 (normalized)
R boundary error:  0.000e+00 (m)
Z boundary error:  0.000e+00 (m)
Fixed-Psi error:  0.000e+00 (Wb)
Fixed-pressure profile error:  0.000e+00 (Pa)
Fixed-current profile error:  0.000e+00 (A)
End of solver
Total (sum of squares):  3.103e-06,
Maximum absolute Force error:  5.148e+02 (N)
Minimum absolute Force error:  6.621e-03 (N)
Average absolute Force error:  4.227e+01 (N)
Maximum absolute Force error:  4.293e-04 (normalized)
Minimum absolute Force error:  5.520e-09 (normalized)
Average absolute Force error:  3.524e-05 (normalized)
R boundary error:  2.776e-17 (m)
Z boundary error:  2.239e-19 (m)
Fixed-Psi error:  0.000e+00 (Wb)
Fixed-pressure profile error:  0.000e+00 (Pa)
Fixed-current profile error:  0.000e+00 (A)

From the Boozer plot below we see that we are already doing fairly good for QS:

[14]:
plot_boozer_surface(eqa);
../../_images/notebooks_tutorials_advanced_optimization_28_0.png

As a final comparison, we can look at the boundary shapes obtained by the different methods. We see that the final shapes are fairly similar, with the proximal method giving slightly more elongation and tighter curvature. We could include additional objectives or constraints to try to reduce this if desired.

[15]:
plot_boundaries(
    [eq0, eqa, eqfam[-1]], labels=["Initial", "Augmented Lagrangian", "Proximal"]
);
../../_images/notebooks_tutorials_advanced_optimization_30_0.png

Further example scripts for precise QS optimization can be found in the desc/examples folder