Skip to content

Limit backtracking iterations #2189

@Huite

Description

@Huite

In discussion with @visr

The number of backtracking iterations is currently set at its default value of 1000:

https://github.com/JuliaNLSolvers/LineSearches.jl/blob/3259cd240144b96a5a3a309ea96dfb19181058b2/src/backtracking.jl#L15

This is likely far too many. Note that every backtracking iteration requires an evaluation of the Newton-Raphson residual --- basically the rhs! -- which isn't that cheap. In my opinion, it makes more sense to put the maximum backtracking iterations at a value of 10 or so (the values I see "in the wild" for other nonlinear solves vary between 5-20). If you need more than 10 iterations are so, you're probably better off decreasing the time step, reformulating, and trying again.

In testing this with Martijn, the models crashes with a LineSearchException with a value of 10. This shouldn't happen, this should be a reason to signal convergence failure and to apply the failfactor (by default 2, i.e. cut the step size in half).

To address this, we can catch the exception and reset the residual so that it'll be rejected. See #2190

For the particular model, this doesn't give any performance benefit, but:

  • It should give performance benefits for very poorly converging models (since we spend less time on a difficult problem and move to an easier problem earlier)
  • It is more robust: with adaptive time stepping, there should always be an option to decrease the time step (until dtmin). The exception basically blocks this, because the exception isn't caught / shouldn't be raised in this context.

Note that LineSearch.jl doesn't raise this exception, but communicates a ReturnCode instead. The return code can be used to e.g. decrease the time step.

https://github.com/SciML/LineSearch.jl/blob/dca4be86debb63fde9d1d4b4555f27c5139afe3a/src/backtracking.jl#L131

So this is another reason to move to LineSearch.jl (once it's past its teething problems and growing pains), see #1784.

Metadata

Metadata

Assignees

Labels

coreIssues related to the computational core in JuliaperformanceRelates to runtime performance or convergence

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions