Skip to content

Commit eb05214

Browse files
Merge pull request #239 from SciML/docs_overhaul
Overhaul the documentation
2 parents 3d85a52 + cdfe16c commit eb05214

16 files changed

+240
-97
lines changed

README.md

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,13 @@ using NonlinearSolve, StaticArrays
2424

2525
f(u, p) = u .* u .- 2
2626
u0 = @SVector[1.0, 1.0]
27-
probN = NonlinearProblem(f, u0)
28-
solver = solve(probN, NewtonRaphson(), abstol = 1e-9)
27+
prob = NonlinearProblem(f, u0)
28+
solver = solve(prob)
2929

3030
## Bracketing Methods
3131

3232
f(u, p) = u .* u .- 2.0
3333
u0 = (1.0, 2.0) # brackets
34-
probB = IntervalNonlinearProblem(f, u0)
35-
sol = solve(probB, ITP())
34+
prob = IntervalNonlinearProblem(f, u0)
35+
sol = solve(prob)
3636
```
37-
38-
## v1.0 Breaking Release Highlights!
39-
40-
v1.0 has been released for NonlinearSolve.jl, making it a decentralized solver library
41-
akin to DifferentialEquations.jl. For simple implementations of nonlinear solvers,
42-
you can now use SimpleNonlinearSolve.jl. `Falsi`, `Bisection`, and `NewtonRaphson`
43-
implementations designed for scalar and static vector inputs have all moved to the
44-
lower dependency version. NonlinearSolve.jl is thus designed for the larger scale
45-
more complex implementations, with `NewtonRaphson` now sporting support for
46-
LinearSolve.jl and soon SparseDiffTools.jl to allow for preconditioned Newton-Krylov and
47-
exploitation of sparsity. The two pieces will continue to grow in this direction,
48-
with NonlinearSolve.jl gaining more and more wrapped solver libraries and support
49-
for more complex methods, while SimpleNonlinearSolve.jl will keep a lower dependency
50-
version with implementations for small scale problems that do not need all of the
51-
extra tooling.
52-
53-
Additionally, `NonlinearProblem` was split into `NonlinearProblem` and `IntervalNonlinearProblem`,
54-
i.e. the bracketing versions now have their own problem definition, rather than using
55-
a `Tuple` for `u0` in a `NonlinearProblem`. This helps for finding problem-algorithm
56-
pairing errors at type time and overall improves the documentation / makes the roles
57-
more clear.

docs/pages.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Put in a separate page so it can be used by SciMLDocs.jl
22

33
pages = ["index.md",
4-
"Tutorials" => Any["tutorials/nonlinear.md",
5-
"tutorials/advanced.md",
4+
"tutorials/getting_started.md",
5+
"Tutorials" => Any[
6+
"tutorials/code_optimization.md",
7+
"tutorials/large_systems.md",
8+
"tutorials/small_compile.md",
9+
"tutorials/termination_conditions.md",
610
"tutorials/iterator_interface.md"],
711
"Basics" => Any["basics/NonlinearProblem.md",
812
"basics/NonlinearFunctions.md",

docs/src/api/simplenonlinearsolve.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ These methods are suited for any general nonlinear root-finding problem , i.e. `
2323
```@docs
2424
SimpleNewtonRaphson
2525
Broyden
26-
Halley
26+
SimpleHalley
2727
Klement
2828
SimpleTrustRegion
2929
SimpleDFSane

docs/src/basics/NonlinearProblem.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Nonlinear Problems
1+
# [Nonlinear Problems](@id problems)
22

33
## The Three Types of Nonlinear Problems
44

docs/src/basics/NonlinearSolution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Nonlinear Solutions
1+
# [Nonlinear Solutions](@id solution)
22

33
```@docs
44
SciMLBase.NonlinearSolution

docs/src/basics/TerminationCondition.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Termination Conditions
1+
# [Termination Conditions](@id termination_condition)
22

33
Provides a API to specify termination conditions for [`NonlinearProblem`](@ref) and
44
[`SteadyStateProblem`](@ref). For details on the various termination modes, i.e.,

docs/src/solvers/BracketingSolvers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Interval Rootfinding Methods (Bracketing Solvers)
1+
# [Interval Rootfinding Methods (Bracketing Solvers)](@id bracketing)
22

33
`solve(prob::IntervalNonlinearProblem,alg;kwargs)`
44

docs/src/solvers/NonlinearSystemSolvers.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,19 @@ methods excel at small problems and problems defined with static arrays.
7171

7272
- `SimpleNewtonRaphson()`: A simplified implementation of the Newton-Raphson method.
7373
- `Broyden()`: The classic Broyden's quasi-Newton method.
74+
- `LBroyden()`: A low-memory Broyden implementation, similar to L-BFGS. This method is
75+
common in machine learning contexts but is known to be unstable in comparison to many
76+
other choices.
7477
- `Klement()`: A quasi-Newton method due to Klement. It's supposed to be more efficient
7578
than Broyden's method, and it seems to be in the cases that have been tried, but more
7679
benchmarking is required.
7780
- `SimpleTrustRegion()`: A dogleg trust-region Newton method. Improved globalizing stability
7881
for more robust fitting over basic Newton methods, though potentially with a cost.
7982
- `SimpleDFSane()`: A low-overhead implementation of the df-sane method for solving
8083
large-scale nonlinear systems of equations.
84+
- `SimpleHalley()`: A low-overhead implementation of the Halley method. This is a higher order
85+
method and thus can converge faster to low tolerances than a Newton method. Requires higher
86+
order derivatives, so best used when automatic differentiation is available.
8187

8288
!!! note
8389

@@ -102,7 +108,6 @@ This is a wrapper package for importing solvers from NLsolve.jl into the SciML i
102108

103109
Submethod choices for this algorithm include:
104110

105-
- `:fixedpoint`: Fixed-point iteration
106111
- `:anderson`: Anderson-accelerated fixed-point iteration
107112
- `:newton`: Classical Newton method with an optional line search
108113
- `:trust_region`: Trust region Newton method (the default choice)

docs/src/solvers/SteadyStateSolvers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Steady State Solvers
1+
# [Steady State Solvers](@id ss_solvers)
22

33
`solve(prob::SteadyStateProblem,alg;kwargs)`
44

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# [Code Optimization for Solving Nonlinear Systems](@id code_optimization)
2+
3+
## Code Optimization in Julia
4+
5+
Before starting this tutorial, we recommend the reader to check out one of the
6+
many tutorials for optimization Julia code. The following is an incomplete
7+
list:
8+
9+
- [The Julia Performance Tips](https://docs.julialang.org/en/v1/manual/performance-tips/)
10+
- [MIT 18.337 Course Notes on Optimizing Serial Code](https://mitmath.github.io/18337/lecture2/optimizing)
11+
- [What scientists must know about hardware to write fast code](https://viralinstruction.com/posts/hardware/)
12+
13+
User-side optimizations are important because, for sufficiently difficult problems,
14+
most time will be spent inside your `f` function, the function you are
15+
trying to solve. “Efficient solvers" are those that reduce the required
16+
number of `f` calls to hit the error tolerance. The main ideas for optimizing
17+
your nonlinear solver code, or any Julia function, are the following:
18+
19+
- Make it non-allocating
20+
- Use StaticArrays for small arrays
21+
- Use broadcast fusion
22+
- Make it type-stable
23+
- Reduce redundant calculations
24+
- Make use of BLAS calls
25+
- Optimize algorithm choice
26+
27+
We'll discuss these strategies in the context of nonlinear solvers.
28+
Let's start with small systems.
29+
30+
## Optimizing Nonlinear Solver Code for Small Systems
31+
32+
```@example
33+
using NonlinearSolve, StaticArrays
34+
35+
f(u, p) = u .* u .- p
36+
u0 = @SVector[1.0, 1.0]
37+
p = 2.0
38+
probN = NonlinearProblem(f, u0, p)
39+
sol = solve(probN, NewtonRaphson(), reltol = 1e-9)
40+
```
41+
42+
## Using Jacobian Free Newton Krylov (JNFK) Methods
43+
44+
If we want to solve the first example, without constructing the entire Jacobian
45+
46+
```@example
47+
using NonlinearSolve, LinearSolve
48+
49+
function f!(res, u, p)
50+
@. res = u * u - p
51+
end
52+
u0 = [1.0, 1.0]
53+
p = 2.0
54+
prob = NonlinearProblem(f!, u0, p)
55+
56+
linsolve = LinearSolve.KrylovJL_GMRES()
57+
sol = solve(prob, NewtonRaphson(; linsolve), reltol = 1e-9)
58+
```

0 commit comments

Comments
 (0)