Skip to content

Commit 6fbb4ee

Browse files
Merge pull request #840 from jClugstor/scimllogging
Add a docs page for verbosity with SciMLLogging
2 parents 51017df + 406d4e3 commit 6fbb4ee

File tree

3 files changed

+162
-1
lines changed

3 files changed

+162
-1
lines changed

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ makedocs(
133133
"https://github.com/SciML/DiffEqProblemLibrary.jl/blob/master/lib/BVProblemLibrary/src/BVProblemLibrary.jl",
134134
"https://github.com/SciML/DiffEqProblemLibrary.jl/blob/master/lib/DDEProblemLibrary/src/DDEProblemLibrary.jl",
135135
"https://docs.sciml.ai/DiffEqDocs/stable/features/dae_initialization/",
136-
"https://www.sciencedirect.com/science/article/pii/S0096300304009683"
136+
"https://www.sciencedirect.com/science/article/pii/S0096300304009683",
137137
],
138138
doctest = false, clean = true,
139139
warnonly = [:missing_docs, :docs_block],

docs/pages.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pages = Any[
134134
"features/io.md",
135135
"features/low_dep.md",
136136
"features/progress_bar.md",
137+
"features/verbosity.md",
137138
],
138139
"Solver Package APIs" => Any[
139140
"Native Julia Solvers" => Any[

docs/src/features/verbosity.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Verbosity Specification with SciMLLogging.jl
2+
3+
DifferentialEquations.jl uses [SciMLLogging.jl](https://docs.sciml.ai/SciMLLogging/stable/) to provide users with fine-grained control over logging and diagnostic output during ODE solving. The `DEVerbosity` struct allows you to customize which messages are displayed, from critical errors to detailed debugging information.
4+
5+
## Basic Usage
6+
7+
Pass a `DEVerbosity` object to `solve` or `init` using the `verbose` keyword argument:
8+
9+
```julia
10+
using OrdinaryDiffEq
11+
12+
# Define an ODE problem
13+
function lorenz!(du, u, p, t)
14+
du[1] = 10.0 * (u[2] - u[1])
15+
du[2] = u[1] * (28.0 - u[3]) - u[2]
16+
du[3] = u[1] * u[2] - (8/3) * u[3]
17+
end
18+
19+
u0 = [1.0, 0.0, 0.0]
20+
tspan = (0.0, 100.0)
21+
prob = ODEProblem(lorenz!, u0, tspan)
22+
23+
# Solve with detailed verbosity
24+
verbose = DEVerbosity(SciMLLogging.Detailed())
25+
sol = solve(prob, Tsit5(), verbose = verbose)
26+
```
27+
28+
## Example Use Cases
29+
30+
### Debugging Algorithm Switching
31+
32+
When using auto-switching algorithms, see when and why switches occur:
33+
34+
```julia
35+
using ODEProblemLibrary: prob_ode_vanderpol_stiff
36+
37+
verbose = DEVerbosity(alg_switch = SciMLLogging.InfoLevel())
38+
sol = solve(prob_ode_vanderpol_stiff, AutoTsit5(Rodas5()), verbose = verbose)
39+
```
40+
41+
### Monitoring Stiff Solver Performance
42+
43+
Get detailed information about Jacobian updates, factorizations, and linear solver behavior:
44+
45+
```julia
46+
function rober(du, u, p, t)
47+
y₁, y₂, y₃ = u
48+
k₁, k₂, k₃ = p
49+
du[1] = -k₁ * y₁ + k₃ * y₂ * y₃
50+
du[2] = k₁ * y₁ - k₃ * y₂ * y₃ - k₂ * y₂^2
51+
du[3] = y₁ + y₂ + y₃ - 1
52+
end
53+
54+
u0 = [1.0, 0.0, 0.0]
55+
tspan = (0.0, 0.1)
56+
p = [0.04, 3e7, 1e4]
57+
prob = ODEProblem(rober, u0, tspan, p)
58+
59+
# Monitor performance-related events and linear solver details
60+
verbose = DEVerbosity(
61+
performance = SciMLLogging.InfoLevel(),
62+
linear_verbosity = SciMLLogging.Detailed()
63+
)
64+
sol = solve(prob, Rosenbrock23(), verbose = verbose)
65+
```
66+
67+
### Debugging Step Acceptance/Rejection
68+
69+
For adaptive methods, monitor which steps are accepted or rejected:
70+
71+
```julia
72+
verbose = DEVerbosity(
73+
step_accepted = SciMLLogging.InfoLevel(),
74+
step_rejected = SciMLLogging.InfoLevel()
75+
)
76+
sol = solve(prob, Tsit5(), verbose = verbose)
77+
```
78+
79+
### Silent Operation
80+
81+
Completely disable all output:
82+
83+
```julia
84+
verbose = DEVerbosity(SciMLLogging.None())
85+
solve(prob, Tsit5(), verbose = verbose)
86+
```
87+
88+
## Using with `init`
89+
90+
The verbosity settings work the same way with `init` for manual stepping:
91+
92+
```julia
93+
verbose = DEVerbosity(
94+
alg_switch = SciMLLogging.InfoLevel(),
95+
linear_verbosity = SciMLLogging.Detailed()
96+
)
97+
integrator = init(prob, Rosenbrock23(), verbose = verbose)
98+
99+
# Step through the solution
100+
step!(integrator)
101+
```
102+
103+
## Controlling Subsolver Verbosity
104+
105+
When using implicit methods, `linear_verbosity` and `nonlinear_verbosity` are automatically passed to the linear and nonlinear solver caches, enabling diagnostics from LinearSolve.jl and NonlinearSolve.jl.
106+
107+
### Using SciMLLogging Presets
108+
109+
The simplest approach is to pass a SciMLLogging preset, which is automatically converted to the appropriate verbosity type:
110+
111+
```julia
112+
using OrdinaryDiffEqNonlinearSolve: NonlinearSolveAlg
113+
114+
# Enable detailed nonlinear solver diagnostics
115+
verbose = DEVerbosity(nonlinear_verbosity = SciMLLogging.Detailed())
116+
sol = solve(prob, ImplicitEuler(nlsolve = NonlinearSolveAlg()), verbose = verbose)
117+
```
118+
119+
### Using LinearVerbosity and NonlinearVerbosity Explicitly
120+
121+
You can also explicitly use `LinearVerbosity` and `NonlinearVerbosity` types from LinearSolve.jl and NonlinearSolve.jl:
122+
123+
```julia
124+
using LinearSolve: LinearVerbosity
125+
using NonlinearSolve: NonlinearVerbosity
126+
127+
# Create explicit verbosity objects
128+
linear_verb = LinearVerbosity(SciMLLogging.Detailed())
129+
nonlinear_verb = NonlinearVerbosity(SciMLLogging.Minimal())
130+
131+
# Pass them to DEVerbosity
132+
verbose = DEVerbosity(
133+
linear_verbosity = linear_verb,
134+
nonlinear_verbosity = nonlinear_verb
135+
)
136+
137+
# Use with a stiff solver
138+
sol = solve(prob, Rosenbrock23(), verbose = verbose)
139+
```
140+
141+
## Combining Settings Flexibly
142+
143+
Individual field settings override group settings, allowing precise control:
144+
145+
```julia
146+
# Set all error_control messages to WarnLevel,
147+
# but make step_rejected silent and dt_NaN an error
148+
verbose = DEVerbosity(
149+
error_control = SciMLLogging.WarnLevel(),
150+
step_rejected = SciMLLogging.Silent(),
151+
dt_NaN = SciMLLogging.ErrorLevel()
152+
)
153+
sol = solve(prob, Tsit5(), verbose = verbose)
154+
```
155+
156+
## API Reference
157+
158+
```@docs
159+
DEVerbosity
160+
```

0 commit comments

Comments
 (0)