Skip to content

Commit eef3665

Browse files
committed
Finish diagnostics API tutorial
1 parent f669ce7 commit eef3665

File tree

6 files changed

+53
-26
lines changed

6 files changed

+53
-26
lines changed

docs/pages.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pages = ["index.md",
2626
"native/steadystatediffeq.md",
2727
"native/descent.md",
2828
"native/globalization.md",
29-
"native/diagnostics.md",],
29+
"native/diagnostics.md"],
3030
"Wrapped Solver APIs" => Any["api/fastlevenbergmarquardt.md",
3131
"api/fixedpointacceleration.md",
3232
"api/leastsquaresoptim.md",

docs/src/basics/diagnostics_api.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# [Diagnostics API](@id diagnostics_api)
22

33
Detailed API Documentation is provided at
4-
[Diagonstics API Reference](@ref diagnostics_api_reference).
4+
[Diagnostics API Reference](@ref diagnostics_api_reference).
55

6-
# Logging the Solve Process
6+
## Logging the Solve Process
77

88
All NonlinearSolve.jl native solvers allow storing and displaying the trace of the nonlinear
99
solve process. This is controlled by 3 keyword arguments to `solve`:
@@ -16,9 +16,17 @@ solve process. This is controlled by 3 keyword arguments to `solve`:
1616
3. `store_trace`: Must be `Val(true)` or `Val(false)`. This controls whether the trace is
1717
stored in the solution object. (Defaults to `Val(false)`)
1818

19+
## Detailed Internal Timings
20+
21+
All the native NonlinearSolve.jl algorithms come with in-built
22+
[TimerOutputs.jl](https://github.com/KristofferC/TimerOutputs.jl) support. However, this
23+
is disabled by default and can be enabled via [`NonlinearSolve.enable_timer_outputs`](@ref).
24+
25+
Note that you will have to restart Julia to disable the timer outputs once enabled.
26+
1927
## Example Usage
2028

21-
```@example tracing
29+
```@example diagnostics_example
2230
using ModelingToolkit, NonlinearSolve
2331
2432
@variables x y z
@@ -42,19 +50,37 @@ solve(prob)
4250
This produced the output, but it is hard to diagnose what is going on. We can turn on
4351
the trace to see what is happening:
4452

45-
```@example tracing
53+
```@example diagnostics_example
4654
solve(prob; show_trace = Val(true), trace_level = TraceAll(10))
4755
nothing; # hide
4856
```
4957

5058
You can also store the trace in the solution object:
5159

52-
```@example tracing
60+
```@example diagnostics_example
5361
sol = solve(prob; trace_level = TraceAll(), store_trace = Val(true));
5462
5563
sol.trace
5664
```
5765

66+
Now, let's try to investigate the time it took for individual internal steps. We will have
67+
to use the `init` and `solve!` API for this. The `TimerOutput` will be present in
68+
`cache.timer`. However, note that for poly-algorithms this is currently not implemented.
69+
70+
```@example diagnostics_example
71+
cache = init(prob, NewtonRaphson(); show_trace = Val(true));
72+
solve!(cache)
73+
cache.timer
74+
```
75+
76+
Let's try for some other solver:
77+
78+
```@example diagnostics_example
79+
cache = init(prob, DFSane(); show_trace = Val(true), trace_level = TraceMinimal(50));
80+
solve!(cache)
81+
cache.timer
82+
```
83+
5884
!!! note
5985

6086
For `iteration == 0` only the `norm(fu, Inf)` is guaranteed to be meaningful. The other

docs/src/basics/faq.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ sol = solve(prob_oop, LevenbergMarquardt(; autodiff = AutoFiniteDiff()); maxiter
7777

7878
This worked but, Finite Differencing is not the recommended approach in any scenario.
7979

80-
2. Rewrite the function to use
81-
[PreallocationTools.jl](https://github.com/SciML/PreallocationTools.jl) or write it as
80+
2. Rewrite the function to use
81+
[PreallocationTools.jl](https://github.com/SciML/PreallocationTools.jl) or write it as
8282

8383
```@example dual_error_faq
8484
function fff_correct(var, p)
@@ -144,8 +144,8 @@ nothing # hide
144144

145145
And boom! Type stable again. For selecting the chunksize the method is:
146146

147-
1. For small inputs `≤ 12` use `chunksize = <length of input>`
148-
2. For larger inputs, use `chunksize = 12`
147+
1. For small inputs `≤ 12` use `chunksize = <length of input>`
148+
2. For larger inputs, use `chunksize = 12`
149149

150150
In general, the chunksize should be `≤ length of input`. However, a very large chunksize
151151
can lead to excessive compilation times and slowdown.

docs/src/native/simplenonlinearsolve.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,18 @@ These methods are suited for any general nonlinear root-finding problem, i.e.
2626
`NonlinearProblem`.
2727

2828
| Solver | In-place | Out of Place | Non-Allocating (Scalars) | Non-Allocating (`SArray`) |
29-
| ------------------------------------ | -------- | ------------ | ------------------------ | ------------------------- |
30-
| [`SimpleNewtonRaphson`](@ref) | ✔️ | ✔️ | ✔️ | ✔️ |
31-
| [`SimpleBroyden`](@ref) | ✔️ | ✔️ | ✔️ | ✔️ |
32-
| [`SimpleHalley`](@ref) || ✔️ | ✔️ ||
33-
| [`SimpleKlement`](@ref) | ✔️ | ✔️ | ✔️ | ✔️ |
34-
| [`SimpleTrustRegion`](@ref) | ✔️ | ✔️ | ✔️ | ✔️ |
35-
| [`SimpleDFSane`](@ref) | ✔️ | ✔️ | ✔️[^1] | ✔️ |
36-
| [`SimpleLimitedMemoryBroyden`](@ref) | ✔️ | ✔️ | ✔️ | ✔️[^2] |
29+
|:------------------------------------ |:-------- |:------------ |:------------------------ |:------------------------- |
30+
| [`SimpleNewtonRaphson`](@ref) | ✔️ | ✔️ | ✔️ | ✔️ |
31+
| [`SimpleBroyden`](@ref) | ✔️ | ✔️ | ✔️ | ✔️ |
32+
| [`SimpleHalley`](@ref) || ✔️ | ✔️ ||
33+
| [`SimpleKlement`](@ref) | ✔️ | ✔️ | ✔️ | ✔️ |
34+
| [`SimpleTrustRegion`](@ref) | ✔️ | ✔️ | ✔️ | ✔️ |
35+
| [`SimpleDFSane`](@ref) | ✔️ | ✔️ | ✔️[^1] | ✔️ |
36+
| [`SimpleLimitedMemoryBroyden`](@ref) | ✔️ | ✔️ | ✔️ | ✔️[^2] |
3737

3838
The algorithms which are non-allocating can be used directly inside GPU Kernels[^3].
3939
See [PSOGPU.jl](https://github.com/SciML/PSOGPU.jl) for more details.
4040

41-
[^1]: Needs [`StaticArrays.jl`](https://github.com/JuliaArrays/StaticArrays.jl) to be
42-
installed and loaded for the non-allocating version.
43-
[^2]: This method is non-allocating if the termination condition is set to either `nothing`
44-
(default) or [`AbsNormTerminationMode`](@ref).
45-
[^3]: Only the defaults are guaranteed to work inside kernels. We try to provide warnings
46-
if the used version is not non-allocating.
47-
4841
```@docs
4942
SimpleNewtonRaphson
5043
SimpleBroyden
@@ -57,3 +50,10 @@ SimpleLimitedMemoryBroyden
5750

5851
`SimpleGaussNewton` is aliased to [`SimpleNewtonRaphson`](@ref) for solving Nonlinear Least
5952
Squares problems.
53+
54+
[^1]: Needs [`StaticArrays.jl`](https://github.com/JuliaArrays/StaticArrays.jl) to be
55+
installed and loaded for the non-allocating version.
56+
[^2]: This method is non-allocating if the termination condition is set to either `nothing`
57+
(default) or [`AbsNormTerminationMode`](@ref).
58+
[^3]: Only the defaults are guaranteed to work inside kernels. We try to provide warnings
59+
if the used version is not non-allocating.

src/algorithms/levenberg_marquardt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ nonlinear systems.
2424
a minimum value of the elements in `DᵀD` to prevent the damping from being too small.
2525
Defaults to `1e-8`.
2626
- `disable_geodesic`: Disables Geodesic Acceleration if set to `Val(true)`. It provides
27-
a way to trade-off robustness for speed, though in most sitations Geodesic Acceleration
27+
a way to trade-off robustness for speed, though in most situations Geodesic Acceleration
2828
should not be disabled.
2929
3030
For the remaining arguments, see [`GeodesicAcceleration`](@ref) and

src/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ end
120120
Statistics from the nonlinear equation solver about the solution process.
121121
122122
## Fields
123+
123124
- nf: Number of function evaluations.
124125
- njacs: Number of Jacobians created during the solve.
125126
- nfactors: Number of factorzations of the jacobian required for the solve.

0 commit comments

Comments
 (0)