Skip to content

Commit 3db75f0

Browse files
committed
Address some of the comments
1 parent 210e544 commit 3db75f0

File tree

9 files changed

+30
-18
lines changed

9 files changed

+30
-18
lines changed

docs/src/basics/faq.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,12 @@ computation and the type of this chunksize can't be statically inferred. To fix
138138
directly specify the chunksize:
139139

140140
```@example type_unstable
141-
@code_warntype solve(prob, NewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 2)))
141+
@code_warntype solve(prob, NewtonRaphson(;
142+
autodiff = AutoForwardDiff(; chunksize = NonlinearSolve.pickchunksize(prob.u0))))
142143
nothing # hide
143144
```
144145

145-
And boom! Type stable again. For selecting the chunksize the method is:
146-
147-
1. For small inputs `≤ 12` use `chunksize = <length of input>`
148-
2. For larger inputs, use `chunksize = 12`
149-
150-
In general, the chunksize should be `≤ length of input`. However, a very large chunksize
151-
can lead to excessive compilation times and slowdown.
146+
And boom! Type stable again. We always recommend picking the chunksize via
147+
[`NonlinearSolve.pickchunksize`](@ref), however, if you manually specify the chunksize, it
148+
must be `≤ length of input`. However, a very large chunksize can lead to excessive
149+
compilation times and slowdown.

docs/src/solvers/fixed_point_solvers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Using [native NonlinearSolve.jl methods](@ref nonlinearsystemsolvers) is the rec
2727
approach. For systems where constructing Jacobian Matrices are expensive, we recommend
2828
using a Krylov Method with one of those solvers.
2929

30-
## Full List of Methods
30+
## [Full List of Methods](@id fixed_point_methods_full_list)
3131

3232
We are only listing the methods that natively solve fixed point problems.
3333

docs/src/solvers/nonlinear_least_squares_solvers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ arrays.
3636
- `SimpleGaussNewton()`: Simple Gauss Newton implementation using QR factorizations for
3737
numerical stability (aliased to [`SimpleNewtonRaphson`](@ref)).
3838

39-
### FastLevenbergMarquardt.jl
39+
### [FastLevenbergMarquardt.jl](@id fastlm_wrapper_summary)
4040

4141
A wrapper over
4242
[FastLevenbergMarquardt.jl](https://github.com/kamesy/FastLevenbergMarquardt.jl). Note that
@@ -46,7 +46,7 @@ benchmarks demonstrate [`LevenbergMarquardt()`](@ref) usually outperforms.
4646
- [`FastLevenbergMarquardtJL(linsolve = :cholesky)`](@ref), can also choose
4747
`linsolve = :qr`.
4848

49-
### LeastSquaresOptim.jl
49+
### [LeastSquaresOptim.jl](@id lso_wrapper_summary)
5050

5151
A wrapper over
5252
[LeastSquaresOptim.jl](https://github.com/matthieugomez/LeastSquaresOptim.jl). Has a core

docs/src/solvers/nonlinear_system_solvers.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ solving of very large systems. Meanwhile, [`SimpleNewtonRaphson`](@ref) and
3232
[`SimpleTrustRegion`](@ref) are implementations which are specialized for small equations.
3333
They are non-allocating on static arrays and thus really well-optimized for small systems,
3434
thus usually outperforming the other methods when such types are used for `u0`.
35+
Additionally, these solvers can be used inside GPU kernels. See
36+
[PSOGPU.jl](https://github.com/SciML/PSOGPU.jl) for an example of this.
3537

3638
## Full List of Methods
3739

@@ -134,8 +136,9 @@ Submethod choices for this algorithm include:
134136

135137
### MINPACK.jl
136138

137-
MINPACK.jl methods are good for medium-sized nonlinear solves. It does not scale due to
138-
the lack of sparse Jacobian support, though the methods are very robust and stable.
139+
MINPACK.jl is a wrapper package for bringing the Fortran solvers from MINPACK. However, our
140+
benchmarks reveal that these methods are rarely competitive with our native solvers. Thus,
141+
our recommendation is to use these only for benchmarking and debugging purposes.
139142

140143
- [`CMINPACK()`](@ref): A wrapper for using the classic MINPACK method through
141144
[MINPACK.jl](https://github.com/sglyon/MINPACK.jl)
@@ -161,3 +164,7 @@ SIAMFANLEquations.jl is a wrapper for the methods in the SIAMFANLEquations.jl li
161164

162165
- [`SIAMFANLEquationsJL()`](@ref): A wrapper for using the methods in
163166
[SIAMFANLEquations.jl](https://github.com/ctkelley/SIAMFANLEquations.jl)
167+
168+
Other solvers listed in [Fixed Point Solvers](@ref fixed_point_methods_full_list),
169+
[FastLevenbergMarquardt.jl](@ref fastlm_wrapper_summary) and
170+
[LeastSquaresOptim.jl](@ref lso_wrapper_summary) can also solve nonlinear systems.

docs/src/solvers/steady_state_solvers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ the direct [`SteadyStateProblem`](@ref) approach can give different answers (i.e
2323
correct unique fixed point) on ODEs with non-autonomous dynamics.
2424

2525
If you have an unstable equilibrium and you want to solve for the unstable equilibrium,
26-
then [`DynamicSS`](@ref) might converge to the equilibrium based on the initial condition.
26+
then [`DynamicSS`](@ref) will not converge to that equilibrium for any initial condition.
2727
However, Nonlinear Solvers don't suffer from this issue, and thus it's recommended to
2828
use a nonlinear solver if you want to solve for the unstable equilibrium.
2929

ext/NonlinearSolveFastLevenbergMarquardtExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import StaticArraysCore: SArray
1717
end
1818
@inline _fast_lm_solver(::FastLevenbergMarquardtJL{linsolve}, ::SArray) where {linsolve} = linsolve
1919

20-
function SciMLBase.__solve(prob::NonlinearLeastSquaresProblem,
20+
function SciMLBase.__solve(prob::Union{NonlinearLeastSquaresProblem, NonlinearProblem},
2121
alg::FastLevenbergMarquardtJL, args...; alias_u0 = false, abstol = nothing,
2222
reltol = nothing, maxiters = 1000, termination_condition = nothing, kwargs...)
2323
NonlinearSolve.__test_termination_condition(termination_condition,

src/default.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function RobustMultiNewton(::Type{T} = Float64; concrete_jac = nothing, linsolve
189189
# Let's atleast have something here for complex numbers
190190
algs = (NewtonRaphson(; concrete_jac, linsolve, precs, autodiff),)
191191
else
192-
algs = (TrustRegion(; concrete_jac, linsolve, precs),
192+
algs = (TrustRegion(; concrete_jac, linsolve, precs, autodiff),
193193
TrustRegion(; concrete_jac, linsolve, precs, autodiff,
194194
radius_update_scheme = RadiusUpdateSchemes.Bastin),
195195
NewtonRaphson(; concrete_jac, linsolve, precs,

src/internal/helpers.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ function get_concrete_forward_ad(autodiff::ADTypes.AbstractADType, prob,
5353
end
5454
function get_concrete_forward_ad(autodiff, prob, sp::Val{test_sparse} = True, args...;
5555
kwargs...) where {test_sparse}
56-
# TODO: Default to PolyesterForwardDiff for non sparse problems
5756
if test_sparse
5857
(; sparsity, jac_prototype) = prob.f
5958
use_sparse_ad = sparsity !== nothing || jac_prototype !== nothing
@@ -96,7 +95,6 @@ function get_concrete_reverse_ad(autodiff::ADTypes.AbstractADType, prob,
9695
end
9796
function get_concrete_reverse_ad(autodiff, prob, sp::Val{test_sparse} = True, args...;
9897
kwargs...) where {test_sparse}
99-
# TODO: Default to Enzyme / ReverseDiff for inplace problems?
10098
if test_sparse
10199
(; sparsity, jac_prototype) = prob.f
102100
use_sparse_ad = sparsity !== nothing || jac_prototype !== nothing

src/utils.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,12 @@ function Base.merge(s1::ImmutableNLStats, s2::ImmutableNLStats)
148148
return ImmutableNLStats(s1.nf + s2.nf, s1.njacs + s2.njacs, s1.nfactors + s2.nfactors,
149149
s1.nsolve + s2.nsolve, s1.nsteps + s2.nsteps)
150150
end
151+
152+
"""
153+
pickchunksize(x) = pickchunksize(length(x))
154+
pickchunksize(x::Int)
155+
156+
Determine the chunk size for ForwardDiff and PolyesterForwardDiff based on the input length.
157+
"""
158+
@inline pickchunksize(x) = pickchunksize(length(x))
159+
@inline pickchunksize(x::Int) = ForwardDiff.pickchunksize(x)

0 commit comments

Comments
 (0)