Skip to content

Commit eeb8c53

Browse files
Merge pull request #796 from SciML/fix-issue-718-truncate-output
Truncate long solve output in documentation
2 parents da6b151 + ce9cf0e commit eeb8c53

File tree

4 files changed

+79
-19
lines changed

4 files changed

+79
-19
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: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,35 @@ After defining a problem, you solve it using `solve`.
8181
sol = DE.solve(prob)
8282
```
8383

84+
This gives us an object `sol` which contains the solution. Looking at the solution object:
85+
86+
```@example ODE2
87+
typeof(sol)
88+
```
89+
90+
The solution object contains the time points and corresponding solution values:
91+
92+
```@example ODE2
93+
@info "Solution contains $(length(sol.t)) time points from t=$(sol.t[1]) to t=$(sol.t[end])"
94+
```
95+
8496
The solvers can be controlled using the available options are described on the
8597
[Common Solver Options manual page](@ref solver_options). For example,
8698
we can lower the relative tolerance (in order to get a more correct result, at
8799
the cost of more timesteps) by using the command `reltol`:
88100

89101
```@example ODE2
90-
sol = DE.solve(prob, reltol = 1e-6)
102+
sol = DE.solve(prob, reltol = 1e-6);
103+
nothing # hide
91104
```
92105

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

97110
```@example ODE2
98-
sol = DE.solve(prob, reltol = 1e-6, saveat = 0.1)
111+
sol = DE.solve(prob, reltol = 1e-6, saveat = 0.1);
112+
nothing # hide
99113
```
100114

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

106120
```@example ODE2
107-
sol = DE.solve(prob, reltol = 1e-6, save_everystep = false)
121+
sol = DE.solve(prob, reltol = 1e-6, save_everystep = false);
122+
nothing # hide
108123
```
109124

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

124139
```@example ODE2
125-
sol = DE.solve(prob, alg_hints = [:stiff], reltol = 1e-8, abstol = 1e-8)
140+
sol = DE.solve(prob, alg_hints = [:stiff], reltol = 1e-8, abstol = 1e-8);
141+
nothing # hide
126142
```
127143

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

134150
```@example ODE2
135-
sol = DE.solve(prob, DE.Tsit5())
151+
sol = DE.solve(prob, DE.Tsit5());
152+
nothing # hide
136153
```
137154

138155
Note that the solver controls can be combined with the algorithm choice. Thus
139156
we can for example solve the problem using `DE.Tsit5()` with a lower tolerance
140157
via:
141158

142159
```@example ODE2
143-
sol = DE.solve(prob, DE.Tsit5(), reltol = 1e-8, abstol = 1e-8)
160+
sol = DE.solve(prob, DE.Tsit5(), reltol = 1e-8, abstol = 1e-8);
161+
nothing # hide
144162
```
145163

146164
In DifferentialEquations.jl, some good “go-to” choices for ODEs are:
@@ -282,6 +300,8 @@ u0 = [1.0; 0.0; 0.0]
282300
tspan = (0.0, 100.0)
283301
prob = DE.ODEProblem(lorenz!, u0, tspan)
284302
sol = DE.solve(prob)
303+
@info "Solution has $(length(sol.t)) timesteps" # hide
304+
nothing # hide
285305
```
286306

287307
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)