Skip to content

Commit c0e6d7d

Browse files
Truncate long solve output in documentation (fixes #718)
- Add semicolons to suppress verbose solve output display - Add `nothing # hide` to prevent output from showing in docs - Split solve and plot commands for better readability - Add informative messages for some outputs (e.g., ensemble solutions) - Applied changes to getting_started.md, sde_example.md, dde_example.md, and ensemble.md This addresses the issue where solve() outputs display long arrays of numbers that don't add value to the documentation and create excessive scrolling. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 7bc71f7 commit c0e6d7d

File tree

4 files changed

+81
-20
lines changed

4 files changed

+81
-20
lines changed

docs/src/features/ensemble.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,11 @@ Now we solve the problem 10 times and plot all of the trajectories in phase spac
414414

415415
```@example ensemble2
416416
ensemble_prob = DE.EnsembleProblem(prob, prob_func = prob_func)
417-
sim = DE.solve(ensemble_prob, DE.SRIW1(), trajectories = 10)
417+
sim = DE.solve(ensemble_prob, DE.SRIW1(), trajectories = 10);
418+
nothing # hide
419+
```
420+
421+
```@example ensemble2
418422
import Plots;
419423
Plots.plot(sim, linealpha = 0.6, color = :blue, idxs = (0, 1), title = "Phase Space Plot");
420424
Plots.plot!(sim, linealpha = 0.6, color = :red, idxs = (0, 2), title = "Phase Space Plot")
@@ -531,7 +535,9 @@ explicitly give a `dt`.
531535

532536
```@example ensemble4
533537
prob2 = DE.EnsembleProblem(prob)
534-
sim = DE.solve(prob2, DE.SRIW1(), dt = 1 // 2^(3), trajectories = 10, adaptive = false)
538+
sim = DE.solve(prob2, DE.SRIW1(), dt = 1 // 2^(3), trajectories = 10, adaptive = false);
539+
@info "Ensemble solution computed with $(length(sim)) trajectories" # hide
540+
nothing # hide
535541
```
536542

537543
**Note that if you don't do the `timeseries_steps` calculations, this code is

docs/src/getting_started.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,20 @@ function in order to speed up the solvers. These are detailed
7878
After defining a problem, you solve it using `solve`.
7979

8080
```@example ODE2
81-
sol = DE.solve(prob)
81+
sol = DE.solve(prob);
82+
nothing # hide
83+
```
84+
85+
This gives us an object `sol` which contains the solution. Looking at the solution object:
86+
87+
```@example ODE2
88+
typeof(sol)
89+
```
90+
91+
The solution object contains the time points and corresponding solution values:
92+
93+
```@example ODE2
94+
@info "Solution contains $(length(sol.t)) time points from t=$(sol.t[1]) to t=$(sol.t[end])"
8295
```
8396

8497
The solvers can be controlled using the available options are described on the
@@ -87,15 +100,17 @@ we can lower the relative tolerance (in order to get a more correct result, at
87100
the cost of more timesteps) by using the command `reltol`:
88101

89102
```@example ODE2
90-
sol = DE.solve(prob, reltol = 1e-6)
103+
sol = DE.solve(prob, reltol = 1e-6);
104+
nothing # hide
91105
```
92106

93107
There are many controls for handling outputs. For example, we can choose to have
94108
the solver save every `0.1` time points by setting `saveat=0.1`. Chaining this
95109
with the tolerance choice looks like:
96110

97111
```@example ODE2
98-
sol = DE.solve(prob, reltol = 1e-6, saveat = 0.1)
112+
sol = DE.solve(prob, reltol = 1e-6, saveat = 0.1);
113+
nothing # hide
99114
```
100115

101116
More generally, `saveat` can be any collection of time points to save at.
@@ -104,7 +119,8 @@ up the solution. In addition, if we only care about the endpoint, we can turn
104119
off intermediate saving in general:
105120

106121
```@example ODE2
107-
sol = DE.solve(prob, reltol = 1e-6, save_everystep = false)
122+
sol = DE.solve(prob, reltol = 1e-6, save_everystep = false);
123+
nothing # hide
108124
```
109125

110126
which will only save the final time point.
@@ -122,7 +138,8 @@ For example, if we have a stiff problem where we need high accuracy,
122138
but don't know the best stiff algorithm for this problem, we can use:
123139

124140
```@example ODE2
125-
sol = DE.solve(prob, alg_hints = [:stiff], reltol = 1e-8, abstol = 1e-8)
141+
sol = DE.solve(prob, alg_hints = [:stiff], reltol = 1e-8, abstol = 1e-8);
142+
nothing # hide
126143
```
127144

128145
You can also explicitly choose the algorithm to use. DifferentialEquations.jl
@@ -132,15 +149,17 @@ been shown to be more efficient than the “standard” algorithms.
132149
For example, we can choose a 5th order Tsitouras method:
133150

134151
```@example ODE2
135-
sol = DE.solve(prob, DE.Tsit5())
152+
sol = DE.solve(prob, DE.Tsit5());
153+
nothing # hide
136154
```
137155

138156
Note that the solver controls can be combined with the algorithm choice. Thus
139157
we can for example solve the problem using `DE.Tsit5()` with a lower tolerance
140158
via:
141159

142160
```@example ODE2
143-
sol = DE.solve(prob, DE.Tsit5(), reltol = 1e-8, abstol = 1e-8)
161+
sol = DE.solve(prob, DE.Tsit5(), reltol = 1e-8, abstol = 1e-8);
162+
nothing # hide
144163
```
145164

146165
In DifferentialEquations.jl, some good “go-to” choices for ODEs are:
@@ -282,6 +301,8 @@ u0 = [1.0; 0.0; 0.0]
282301
tspan = (0.0, 100.0)
283302
prob = DE.ODEProblem(lorenz!, u0, tspan)
284303
sol = DE.solve(prob)
304+
@info "Solution has $(length(sol.t)) timesteps" # hide
305+
nothing # hide
285306
```
286307

287308
Using the plot recipe tools

docs/src/tutorials/dde_example.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ To solve the problem with this algorithm, we do the same thing we'd do with othe
109109
methods on the common interface:
110110

111111
```@example dde
112-
sol = DDE.solve(prob, alg)
112+
sol = DDE.solve(prob, alg);
113+
@info "Solution computed with $(length(sol.t)) timesteps" # hide
114+
nothing # hide
113115
```
114116

115117
Note that everything available to OrdinaryDiffEq.jl can be used here, including
@@ -202,7 +204,8 @@ from above with residual control:
202204
```@example dde
203205
prob = DDE.DDEProblem(bc_model, u0, h, tspan)
204206
alg = DDE.MethodOfSteps(DE.RK4())
205-
sol = DDE.solve(prob, alg)
207+
sol = DDE.solve(prob, alg);
208+
nothing # hide
206209
```
207210

208211
Note that this method can solve problems with state-dependent delays.
@@ -222,7 +225,8 @@ dependent lags and solving with a `MethodOfSteps` algorithm:
222225
```@example dde
223226
prob = DDE.DDEProblem(bc_model, u0, h, tspan; dependent_lags = ((u, p, t) -> tau,))
224227
alg = DDE.MethodOfSteps(DE.Tsit5())
225-
sol = DDE.solve(prob, alg)
228+
sol = DDE.solve(prob, alg);
229+
nothing # hide
226230
```
227231

228232
Here, we treated the single lag `t-tau` as a state-dependent delay. Of course, you

docs/src/tutorials/sde_example.md

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ The `solve` interface is then the same as ODEs. Here, we will use the classic
3737
Euler-Maruyama algorithm `EM` and plot the solution:
3838

3939
```@example sde
40-
sol = SDE.solve(prob, SDE.EM(), dt = dt)
40+
sol = SDE.solve(prob, SDE.EM(), dt = dt);
41+
nothing # hide
42+
```
43+
44+
```@example sde
4145
import Plots
4246
Plots.plot(sol)
4347
```
@@ -60,7 +64,11 @@ prob = SDE.SDEProblem(ff, u₀, (0.0, 1.0))
6064
We can now compare the `SDE.EM()` solution with the analytic one:
6165

6266
```@example sde
63-
sol = SDE.solve(prob, SDE.EM(), dt = dt)
67+
sol = SDE.solve(prob, SDE.EM(), dt = dt);
68+
nothing # hide
69+
```
70+
71+
```@example sde
6472
Plots.plot(sol, plot_analytic = true)
6573
```
6674

@@ -69,22 +77,34 @@ the higher order methods are adaptive. Let's first switch off adaptivity and
6977
compare the numerical and analytic solutions :
7078

7179
```@example sde
72-
sol = SDE.solve(prob, SDE.SRIW1(), dt = dt, adaptive = false)
80+
sol = SDE.solve(prob, SDE.SRIW1(), dt = dt, adaptive = false);
81+
nothing # hide
82+
```
83+
84+
```@example sde
7385
Plots.plot(sol, plot_analytic = true)
7486
```
7587

7688
Now, let's allow the solver to automatically determine a starting `dt`. This estimate
7789
at the beginning is conservative (small) to ensure accuracy.
7890

7991
```@example sde
80-
sol = SDE.solve(prob, SDE.SRIW1())
92+
sol = SDE.solve(prob, SDE.SRIW1());
93+
nothing # hide
94+
```
95+
96+
```@example sde
8197
Plots.plot(sol, plot_analytic = true)
8298
```
8399

84100
We can instead start the method with a larger `dt` by passing it to `solve`:
85101

86102
```@example sde
87-
sol = SDE.solve(prob, SDE.SRIW1(), dt = dt)
103+
sol = SDE.solve(prob, SDE.SRIW1(), dt = dt);
104+
nothing # hide
105+
```
106+
107+
```@example sde
88108
Plots.plot(sol, plot_analytic = true)
89109
```
90110

@@ -105,7 +125,9 @@ are added via `addprocs()`, but we can change this to use multithreading via
105125
`SDE.EnsembleThreads()`. Together, this looks like:
106126

107127
```@example sde
108-
sol = SDE.solve(ensembleprob, SDE.EnsembleThreads(), trajectories = 1000)
128+
sol = SDE.solve(ensembleprob, SDE.EnsembleThreads(), trajectories = 1000);
129+
@info "Ensemble solution computed with $(length(sol)) trajectories" # hide
130+
nothing # hide
109131
```
110132

111133
!!! warn
@@ -166,7 +188,11 @@ function g!(du, u, p, t) # It actually represents a diagonal matrix [3.0 0 0; 0
166188
end
167189
168190
prob_sde_lorenz = SDE.SDEProblem(f!, g!, [1.0, 0.0, 0.0], (0.0, 10.0))
169-
sol = SDE.solve(prob_sde_lorenz)
191+
sol = SDE.solve(prob_sde_lorenz);
192+
nothing # hide
193+
```
194+
195+
```@example sde
170196
Plots.plot(sol, idxs = (1, 2, 3))
171197
```
172198

@@ -202,7 +228,11 @@ u0 = rand(4, 2)
202228
203229
W = SDE.WienerProcess(0.0, 0.0, 0.0)
204230
prob = SDE.SDEProblem(f!, g!, u0, (0.0, 1.0), noise = W)
205-
sol = SDE.solve(prob, SDE.SRIW1())
231+
sol = SDE.solve(prob, SDE.SRIW1());
232+
nothing # hide
233+
```
234+
235+
```@example sde
206236
Plots.plot(sol)
207237
```
208238

0 commit comments

Comments
 (0)