Skip to content

Commit a00ec0b

Browse files
Merge pull request #244 from avik-pal/ap/defaults
Better Defaults: Auto AD Selection for Newton Methods
2 parents 7a5e231 + 91c0ca0 commit a00ec0b

18 files changed

+416
-504
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ PrecompileTools = "1"
5050
RecursiveArrayTools = "2"
5151
Reexport = "0.2, 1"
5252
SciMLBase = "2.4"
53-
SimpleNonlinearSolve = "0.1"
53+
SimpleNonlinearSolve = "0.1.22"
5454
SparseDiffTools = "2.6"
5555
StaticArraysCore = "1.4"
5656
UnPack = "1.0"

docs/pages.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
pages = ["index.md",
44
"tutorials/getting_started.md",
5-
"Tutorials" => Any[
6-
"tutorials/code_optimization.md",
5+
"Tutorials" => Any["tutorials/code_optimization.md",
76
"tutorials/large_systems.md",
87
"tutorials/small_compile.md",
98
"tutorials/termination_conditions.md",

docs/src/solvers/NonlinearSystemSolvers.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ it will make sure to work.
1616

1717
If one is looking for more robustness then `RobustMultiNewton` is a good choice.
1818
It attempts a set of the most robust methods in succession and only fails if
19-
all of the methods fail to converge. Additionally, `DynamicSS` can be a good choice
19+
all of the methods fail to converge. Additionally, `DynamicSS` can be a good choice
2020
for high stability.
2121

2222
As a balance, `NewtonRaphson` is a good choice for most problems that aren't too
@@ -25,13 +25,13 @@ but more stable. If the problem is well-conditioned, `Klement` or `Broyden`
2525
may be faster, but highly dependent on the eigenvalues of the Jacobian being
2626
sufficiently small.
2727

28-
`NewtonRaphson` and `TrustRegion` are designed for for large systems.
28+
`NewtonRaphson` and `TrustRegion` are designed for for large systems.
2929
They can make use of sparsity patterns for sparse automatic differentiation
3030
and sparse linear solving of very large systems. Meanwhile,
3131
`SimpleNewtonRaphson` and `SimpleTrustRegion` are implementations which is specialized for
3232
small equations. They are non-allocating on static arrays and thus really well-optimized
3333
for small systems, thus usually outperforming the other methods when such types are
34-
used for `u0`.
34+
used for `u0`.
3535

3636
## Full List of Methods
3737

@@ -57,7 +57,7 @@ features, but have a bit of overhead on very small problems.
5757
large-scale and numerically-difficult nonlinear systems.
5858
- `RobustMultiNewton()`: A polyalgorithm that mixes highly robust methods (line searches and
5959
trust regions) in order to be as robust as possible for difficult problems. If this method
60-
fails to converge, then one can be pretty certain that most (all?) other choices would
60+
fails to converge, then one can be pretty certain that most (all?) other choices would
6161
likely fail.
6262
- `FastShortcutNonlinearPolyalg`: The default method. A polyalgorithm that mixes fast methods
6363
with fallbacks to robust methods to allow for solving easy problems quickly without sacrificing

docs/src/tutorials/code_optimization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ prob = NonlinearProblem(f!, u0, p)
5555
5656
linsolve = LinearSolve.KrylovJL_GMRES()
5757
sol = solve(prob, NewtonRaphson(; linsolve), reltol = 1e-9)
58-
```
58+
```

docs/src/tutorials/getting_started.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ to understanding the deeper parts of the documentation.
99

1010
There are three types of nonlinear systems:
1111

12-
1. The "standard nonlinear system", i.e. the `NonlinearProblem`. This is a
13-
system of equations with an initial condition where you want to satisfy
14-
all equations simultaniously.
15-
2. The "interval rootfinding problem", i.e. the `IntervalNonlinearProblem`.
16-
This is the case where you're given an interval `[a,b]` and need to find
17-
where `f(u) = 0` for `u` inside the bounds.
18-
3. The "steady state problem", i.e. find the `u` such that `u' = f(u) = 0`.
19-
While related to (1), it's not entirely the same because there's a uniquely
20-
defined privledged root.
21-
4. The nonlinear least squares problem, which is an overconstrained nonlinear
22-
system (i.e. more equations than states) which might not be satisfiable, i.e.
23-
there may be no `u` such that `f(u) = 0`, and thus we find the `u` which
24-
minimizes `||f(u)||` in the least squares sense.
12+
1. The "standard nonlinear system", i.e. the `NonlinearProblem`. This is a
13+
system of equations with an initial condition where you want to satisfy
14+
all equations simultaniously.
15+
2. The "interval rootfinding problem", i.e. the `IntervalNonlinearProblem`.
16+
This is the case where you're given an interval `[a,b]` and need to find
17+
where `f(u) = 0` for `u` inside the bounds.
18+
3. The "steady state problem", i.e. find the `u` such that `u' = f(u) = 0`.
19+
While related to (1), it's not entirely the same because there's a uniquely
20+
defined privledged root.
21+
4. The nonlinear least squares problem, which is an overconstrained nonlinear
22+
system (i.e. more equations than states) which might not be satisfiable, i.e.
23+
there may be no `u` such that `f(u) = 0`, and thus we find the `u` which
24+
minimizes `||f(u)||` in the least squares sense.
2525

2626
For now let's focus on the first two. The other two are covered in later tutorials,
2727
but from the first two we can show the general flow of the NonlinearSolve.jl package.
@@ -105,7 +105,7 @@ For a complete list of solver choices, see [the nonlinear system solvers page](@
105105
Next we can modify the tolerances. Here let's set some really low tolerances to force a tight solution:
106106

107107
```@example 1
108-
solve(prob, TrustRegion(), reltol=1e-12, abstol=1e-12)
108+
solve(prob, TrustRegion(), reltol = 1e-12, abstol = 1e-12)
109109
```
110110

111111
There are many more options for doing this configuring. Specifically for handling termination conditions,
@@ -139,10 +139,10 @@ sol = solve(prob_int, ITP(), abstol = 0.01)
139139
Congrats, you now know how to use the basics of NonlinearSolve.jl! However, there is so much more to
140140
see. Next check out:
141141

142-
- [Some code optimization tricks to know about with NonlinearSolve.jl](@ref code_optimization)
143-
- [An iterator interface which lets you step through the solving process step by step](@ref iterator)
144-
- [How to handle large systems of equations efficiently](@ref large_systems)
145-
- [Ways to use NonlinearSolve.jl that is faster to startup and can statically compile](@ref fast_startup)
146-
- [More detailed termination conditions](@ref termination_conditions_tutorial)
142+
- [Some code optimization tricks to know about with NonlinearSolve.jl](@ref code_optimization)
143+
- [An iterator interface which lets you step through the solving process step by step](@ref iterator)
144+
- [How to handle large systems of equations efficiently](@ref large_systems)
145+
- [Ways to use NonlinearSolve.jl that is faster to startup and can statically compile](@ref fast_startup)
146+
- [More detailed termination conditions](@ref termination_conditions_tutorial)
147147

148-
And also check out the rest of the manual.
148+
And also check out the rest of the manual.

docs/src/tutorials/iterator_interface.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# [Nonlinear Solver Iterator Interface](@id iterator)
22

33
!!! warn
4-
4+
55
This iterator interface will be expanded with a `step!` function soon!
66

77
There is an iterator form of the nonlinear solver which mirrors the DiffEq integrator interface:

docs/src/tutorials/large_systems.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ function incompletelu(W, du, u, p, t, newW, Plprev, Prprev, solverdata)
209209
end
210210
211211
@btime solve(prob_brusselator_2d_sparse,
212-
NewtonRaphson(linsolve = KrylovJL_GMRES(), precs = incompletelu,
213-
concrete_jac = true));
212+
NewtonRaphson(linsolve = KrylovJL_GMRES(), precs = incompletelu, concrete_jac = true));
214213
nothing # hide
215214
```
216215

@@ -275,28 +274,3 @@ nothing # hide
275274

276275
For more information on the preconditioner interface, see the
277276
[linear solver documentation](https://docs.sciml.ai/LinearSolve/stable/basics/Preconditioners/).
278-
279-
## Speed up Jacobian computation with sparsity exploitation and matrix coloring
280-
281-
To cut down the of Jacobian building overhead, we can choose to exploit the sparsity pattern and deploy matrix coloring during Jacobian construction. With NonlinearSolve.jl, we can simply use `autodiff=AutoSparseForwardDiff()` to automatically exploit the sparsity pattern of Jacobian matrices:
282-
283-
```@example ill_conditioned_nlprob
284-
@btime solve(prob_brusselator_2d,
285-
NewtonRaphson(linsolve = KrylovJL_GMRES(), precs = incompletelu, concrete_jac = true,
286-
autodiff = AutoSparseForwardDiff()));
287-
nothing # hide
288-
```
289-
290-
To setup matrix coloring for the jacobian sparsity pattern, we can simply get the coloring vector by using [ArrayInterface.jl](https://github.com/JuliaArrays/ArrayInterface.jl) for the sparsity pattern of `jac_prototype`:
291-
292-
```@example ill_conditioned_nlprob
293-
using ArrayInterface
294-
colorvec = ArrayInterface.matrix_colors(jac_sparsity)
295-
ff = NonlinearFunction(brusselator_2d_loop; jac_prototype = float.(jac_sparsity), colorvec)
296-
prob_brusselator_2d_sparse = NonlinearProblem(ff, u0, p)
297-
298-
@btime solve(prob_brusselator_2d_sparse,
299-
NewtonRaphson(linsolve = KrylovJL_GMRES(), precs = incompletelu, concrete_jac = true,
300-
autodiff = AutoSparseForwardDiff()));
301-
nothing # hide
302-
```

docs/src/tutorials/small_compile.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Faster Startup and and Static Compilation
22

3-
This is a stub article to be completed soon.
3+
This is a stub article to be completed soon.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# [More Detailed Termination Conditions](@id termination_conditions_tutorial)
22

3-
This is a stub article to be completed soon.
3+
This is a stub article to be completed soon.

0 commit comments

Comments
 (0)