PlasmaControl / DESC

Stellarator Equilibrium and Optimization Suite
MIT License
97 stars 26 forks source link

Running DESC until tolerance reached #1387

Open Mandelbr0t opened 2 hours ago

Mandelbr0t commented 2 hours ago

Hi All,

If one wants to run a given desc converted Vmec input file to convergence for the given M, N, is it enough to do the following:

ftol, gtol, xtol = 1e-16, 1e-16, 1e-16

eq_fam = EquilibriaFamily.solve_continuation_automatic(
        eq=eq, objective="force", optimizer=optimizer, verbose=2, ftol=ftol, gtol=gtol, xtol=xtol
    )

This iteration then stops with

`xtol` condition satisfied.
         Current function value: 2.498e-05
         Total delta_x: 7.862e-02
         ...

I noticed that

InputReader.vmec_to_desc_input(
            path_to_some_vmec_input,
            path_to_desc_input,
        )

inp  = InputReader().parse_inputs(path_to_desc_input)

does not add any solver tolerances to the inp container, is this intended?

Thanks!

f0uriest commented 2 hours ago

what do you mean "to convergence" here? With tolerances that low its likely you'll run into floating point issues before actually reaching them (and you'd also need to set maxiter=inf or something)

When converting a vmec input to desc we don't write any tolerances and use the defaults, since the tolerances in vmec mean different things than the ones in desc so its not clear how to translate them.

Mandelbr0t commented 1 hour ago

By "to convergence" I mean finding the lowest possible force error for a given M and N.

Edit: I noticed that the iterations of most continuation steps stop due to near-zero or zero step norm.

f0uriest commented 1 hour ago

finding the lowest possible force would generally be done by setting ftol=0, xtol=0, gtol=eps. then you're finding the actual proper mininum, or at least some ball around it where the gradient is finite but tiny (in finite precision you'll basically never get the gradient to actual zero).

The problem is often that the landscape isn't particularly well scaled, so you can get early termination because either f or x stops changing, and you usually won't be able to do better in finite precision. This is a general problem in nonlinear (and linear) optimization and isn't unique to desc.

Another problem is that f, x, and df/dx all have units which makes it tricky because just rescaling the problem can change the convergence criteria, even though it shouldn't. You can check out #1073 for one attempt at a fix for this, which might help in your case as well.

f0uriest commented 1 hour ago

the larger point though is that usually solving to super low tolerances is generally not advised. Formally the problem is only solved in the limit of high resolution, so enforcing optimality at any finite resolution effectively guarantees that you're not solving the actual problem (you usually don't want an exact answer to an approximate problem, it's better to have an answer that is "as approximate" as the problem).

So if you want lower force error, its pretty much always better to increase resolution rather than reducing tolerances beyond a certain point