Skip to content

Commit 380cc55

Browse files
Use explicit imports
1 parent e0090e5 commit 380cc55

21 files changed

+230
-227
lines changed

docs/src/basics/faq.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,9 @@ function func(du, u, p, t)
478478
du[2] = -3 * u[2] + u[1] * u[2]
479479
end
480480
function f(p)
481-
prob = ODEProblem(func, eltype(p).([1.0, 1.0]), (0.0, 10.0), p)
481+
prob = DE.ODEProblem(func, eltype(p).([1.0, 1.0]), (0.0, 10.0), p)
482482
# Lower tolerances to show the methods converge to the same value
483-
solve(prob, Tsit5(), save_everystep = false, abstol = 1e-12, reltol = 1e-12)[end]
483+
DE.solve(prob, DE.Tsit5(), save_everystep = false, abstol = 1e-12, reltol = 1e-12)[end]
484484
end
485485
```
486486

@@ -508,14 +508,14 @@ This is because you're using a cache which is incompatible with autodifferentiat
508508
via ForwardDiff.jl. For example, if we use the ODE function:
509509

510510
```julia
511-
import LinearAlgebra, OrdinaryDiffEq
511+
import LinearAlgebra, OrdinaryDiffEq as ODE, DifferentialEquations
512512
function foo(du, u, (A, tmp), t)
513513
mul!(tmp, A, u)
514514
@. du = u + tmp
515515
nothing
516516
end
517-
prob = ODEProblem(foo, ones(5, 5), (0.0, 1.0), (ones(5, 5), zeros(5, 5)))
518-
solve(prob, Rosenbrock23())
517+
prob = DE.ODEProblem(foo, ones(5, 5), (0.0, 1.0), (ones(5, 5), zeros(5, 5)))
518+
DE.solve(prob, ODE.Rosenbrock23())
519519
```
520520

521521
Here we use a cached temporary array to avoid the allocations of matrix
@@ -527,8 +527,9 @@ option in the solver. Every solver which uses autodifferentiation has this optio
527527
Thus, we'd solve this with:
528528

529529
```julia
530-
prob = ODEProblem(f, ones(5, 5), (0.0, 1.0))
531-
sol = solve(prob, Rosenbrock23(autodiff = false))
530+
import DifferentialEquations, OrdinaryDiffEq as ODE
531+
prob = DE.ODEProblem(f, ones(5, 5), (0.0, 1.0))
532+
sol = DE.solve(prob, ODE.Rosenbrock23(autodiff = false))
532533
```
533534

534535
and it will use a numerical differentiation fallback (DiffEqDiffTools.jl) to
@@ -539,16 +540,16 @@ We could use `get_tmp` and `dualcache` functions from
539540
to solve this issue, e.g.,
540541

541542
```julia
542-
import LinearAlgebra, OrdinaryDiffEq, PreallocationTools
543+
import LinearAlgebra, OrdinaryDiffEq as ODE, PreallocationTools, DifferentialEquations
543544
function foo(du, u, (A, tmp), t)
544-
tmp = get_tmp(tmp, first(u) * t)
545+
tmp = PreallocationTools.get_tmp(tmp, first(u) * t)
545546
mul!(tmp, A, u)
546547
@. du = u + tmp
547548
nothing
548549
end
549-
prob = ODEProblem(foo, ones(5, 5), (0.0, 1.0),
550+
prob = DE.ODEProblem(foo, ones(5, 5), (0.0, 1.0),
550551
(ones(5, 5), PreallocationTools.dualcache(zeros(5, 5))))
551-
solve(prob, TRBDF2())
552+
DE.solve(prob, ODE.TRBDF2())
552553
```
553554

554555
## Sparse Jacobians
@@ -570,7 +571,8 @@ ERROR: ArgumentError: pattern of the matrix changed
570571
though, an `Error: SingularException` is also possible if the linear solver fails to detect that the sparsity structure changed. To address this issue, you'll need to disable caching the symbolic factorization, e.g.,
571572

572573
```julia
573-
solve(prob, Rodas4(linsolve = KLUFactorization(; reuse_symbolic = false)))
574+
import DifferentialEquations, OrdinaryDiffEq as ODE, LinearSolve
575+
DE.solve(prob, ODE.Rodas4(linsolve = LinearSolve.KLUFactorization(; reuse_symbolic = false)))
574576
```
575577

576578
For more details about possible linear solvers, consult the [LinearSolve.jl documentation](https://docs.sciml.ai/LinearSolve/stable/)

docs/src/basics/problem.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ which outputs a tuple.
6969

7070
```@example problem
7171
import DifferentialEquations
72-
prob = DifferentialEquations.ODEProblem((u, p, t) -> u, (p, t0) -> p[1], (p) -> (0.0, p[2]), (2.0, 1.0))
72+
prob = DE.ODEProblem((u, p, t) -> u, (p, t0) -> p[1], (p) -> (0.0, p[2]), (2.0, 1.0))
7373
```
7474

7575
```@example problem
7676
import Distributions
77-
prob = DifferentialEquations.ODEProblem((u, p, t) -> u, (p, t) -> Distributions.Normal(p, 1), (0.0, 1.0), 1.0)
77+
prob = DE.ODEProblem((u, p, t) -> u, (p, t) -> Distributions.Normal(p, 1), (0.0, 1.0), 1.0)
7878
```
7979

8080
## Lower Level `__init` and `__solve`
@@ -101,8 +101,8 @@ example, to simulate it for longer timespan. It can be done by the
101101
`remake` function:
102102

103103
```@example problem
104-
prob1 = DifferentialEquations.ODEProblem((u, p, t) -> u / 2, 1.0, (0.0, 1.0))
105-
prob2 = DifferentialEquations.remake(prob1; tspan = (0.0, 2.0))
104+
prob1 = DE.ODEProblem((u, p, t) -> u / 2, 1.0, (0.0, 1.0))
105+
prob2 = DE.remake(prob1; tspan = (0.0, 2.0))
106106
```
107107

108108
A general syntax of `remake` is

docs/src/examples/beeler_reuter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,6 @@ Plots.heatmap(sol.u[end])
667667
We achieve around a 6x speedup with running the explicit portion of our IMEX solver on a GPU. The major bottleneck of this technique is the communication between CPU and GPU. In its current form, not all the internals of the method utilize GPU acceleration. In particular, the implicit equations solved by GMRES are performed on the CPU. This partial CPU nature also increases the amount of data transfer that is required between the GPU and CPU (performed every f call). Compiling the full ODE solver to the GPU would solve both of these issues and potentially give a much larger speedup. [JuliaDiffEq developers are currently working on solutions to alleviate these issues](http://www.stochasticlifestyle.com/solving-systems-stochastic-pdes-using-gpus-julia/), but these will only be compatible with native Julia solvers (and not Sundials).
668668

669669
```julia, echo = false, skip="notebook"
670-
using SciMLTutorials
670+
import SciMLTutorials
671671
SciMLTutorials.tutorial_footer(WEAVE_ARGS[:folder], WEAVE_ARGS[:file])
672672
```

docs/src/extras/timestepping.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,5 +218,6 @@ end
218218
and used via
219219

220220
```julia
221-
sol = solve(prob, EM(), dt = dt, adaptive = true, controller = CustomController())
221+
# Assuming: import DifferentialEquations as DE
222+
sol = DE.solve(prob, DE.EM(), dt = dt, adaptive = true, controller = CustomController())
222223
```

docs/src/features/callback_functions.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ u0 = [10.0]
8585
const V = 1
8686
prob = DE.ODEProblem(f, u0, (0.0, 10.0))
8787
sol = DE.solve(prob, DE.Tsit5())
88-
using Plots;
89-
plot(sol);
88+
import Plots;
89+
Plots.plot(sol);
9090
```
9191

9292
Now assume we wish to give the patient a dose of 10 at time `t==4`. For this,
@@ -102,7 +102,7 @@ If we then solve with this callback enabled, we see no change:
102102

103103
```@example callback1
104104
sol = DE.solve(prob, DE.Tsit5(), callback = cb)
105-
plot(sol)
105+
Plots.plot(sol)
106106
```
107107

108108
The reason there is no change is because the `DiscreteCallback` only applies at
@@ -112,7 +112,7 @@ We can do that with the `tstops` argument:
112112

113113
```@example callback1
114114
sol = DE.solve(prob, DE.Tsit5(), callback = cb, tstops = [4.0])
115-
plot(sol)
115+
Plots.plot(sol)
116116
```
117117

118118
and thus we achieve the desired result.
@@ -126,7 +126,7 @@ condition(u, t, integrator) = t ∈ dosetimes
126126
affect!(integrator) = integrator.u[1] += 10
127127
cb = DE.DiscreteCallback(condition, affect!)
128128
sol = DE.solve(prob, DE.Tsit5(), callback = cb, tstops = dosetimes)
129-
plot(sol)
129+
Plots.plot(sol)
130130
```
131131

132132
We can then use this mechanism to make the model arbitrarily complex. For
@@ -140,7 +140,7 @@ condition(u, t, integrator) = t ∈ dosetimes && (u[1] < 1.0)
140140
affect!(integrator) = integrator.u[1] += 10integrator.t
141141
cb = DE.DiscreteCallback(condition, affect!)
142142
sol = DE.solve(prob, DE.Tsit5(), callback = cb, tstops = dosetimes)
143-
plot(sol)
143+
Plots.plot(sol)
144144
```
145145

146146
#### PresetTimeCallback
@@ -156,7 +156,7 @@ dosetimes = [4.0, 8.0]
156156
affect!(integrator) = integrator.u[1] += 10
157157
cb = DE.PresetTimeCallback(dosetimes, affect!)
158158
sol = DE.solve(prob, DE.Tsit5(), callback = cb)
159-
plot(sol)
159+
Plots.plot(sol)
160160
```
161161

162162
Notice that this version will automatically set the `tstops` for you.
@@ -237,8 +237,8 @@ Lastly we solve the problem. Note that we must pass `tstop` values of `5.0` and
237237
```@example callback2
238238
const tstop = [5.0; 8.0]
239239
sol = DE.solve(prob, DE.Tsit5(), callback = cbs, tstops = tstop)
240-
using Plots;
241-
plot(sol);
240+
import Plots;
241+
Plots.plot(sol);
242242
```
243243

244244
It's clear from the plot how the controls affected the outcome.
@@ -382,8 +382,8 @@ tspan = (0.0, 15.0)
382382
p = 9.8
383383
prob = DE.ODEProblem(f, u0, tspan, p)
384384
sol = DE.solve(prob, DE.Tsit5(), callback = cb)
385-
using Plots;
386-
plot(sol);
385+
import Plots;
386+
Plots.plot(sol);
387387
```
388388

389389
As you can see from the resulting image, DifferentialEquations.jl is smart enough
@@ -400,7 +400,7 @@ u0 = [50.0, 0.0]
400400
tspan = (0.0, 100.0)
401401
prob = DE.ODEProblem(f, u0, tspan, p)
402402
sol = DE.solve(prob, DE.Tsit5(), callback = cb)
403-
plot(sol)
403+
Plots.plot(sol)
404404
```
405405

406406
#### Handling Changing Dynamics and Exactness
@@ -424,7 +424,7 @@ u0 = [1.0, 0.0]
424424
p = [1.0]
425425
prob = DE.ODEProblem{true}(dynamics!, u0, (0.0, 1.75), p)
426426
sol = DE.solve(prob, DE.Tsit5(), callback = floor_event)
427-
plot(sol)
427+
Plots.plot(sol)
428428
```
429429

430430
Notice that at the end, the ball is not at `0.0` like the condition would let
@@ -494,7 +494,7 @@ u0 = [1.0, 0.0]
494494
p = [0.0, 0.0]
495495
prob = ODEProblem{true}(dynamics!, u0, (0.0, 2.0), p)
496496
sol = solve(prob, Tsit5(), callback = floor_event)
497-
plot(sol)
497+
Plots.plot(sol)
498498
```
499499

500500
From the readout, we can see the ball only bounced 8 times before it went below
@@ -555,19 +555,19 @@ u0 = [1.0, 0.0]
555555
p = [1.0, 0.0, 0.0]
556556
prob = DE.ODEProblem{true}(dynamics!, u0, (0.0, 2.0), p)
557557
sol = DE.solve(prob, DE.Tsit5(), callback = floor_event)
558-
plot(sol)
558+
Plots.plot(sol)
559559
```
560560

561561
With this corrected version, we see that after 41 bounces, the accumulation
562562
point is reached at `t = 1.355261854357056`. To really see the accumulation,
563563
let's zoom in:
564564

565565
```@example callback4
566-
p1 = plot(sol, idxs = 1, tspan = (1.25, 1.40))
567-
p2 = plot(sol, idxs = 1, tspan = (1.35, 1.36))
568-
p3 = plot(sol, idxs = 1, tspan = (1.354, 1.35526))
569-
p4 = plot(sol, idxs = 1, tspan = (1.35526, 1.35526185))
570-
plot(p1, p2, p3, p4)
566+
p1 = Plots.plot(sol, idxs = 1, tspan = (1.25, 1.40))
567+
p2 = Plots.plot(sol, idxs = 1, tspan = (1.35, 1.36))
568+
p3 = Plots.plot(sol, idxs = 1, tspan = (1.354, 1.35526))
569+
p4 = Plots.plot(sol, idxs = 1, tspan = (1.35526, 1.35526185))
570+
Plots.plot(p1, p2, p3, p4)
571571
```
572572

573573
I think Zeno would be proud of our solution.
@@ -614,8 +614,8 @@ condition(u, t, integrator) = u[2]
614614
affect!(integrator) = DE.terminate!(integrator)
615615
cb = DE.ContinuousCallback(condition, affect!)
616616
sol = DE.solve(prob, DE.Tsit5(), callback = cb)
617-
using Plots;
618-
plot(sol);
617+
import Plots;
618+
Plots.plot(sol);
619619
```
620620

621621
Note that this uses rootfinding to approximate the “exact” moment of the crossing.
@@ -642,7 +642,7 @@ condition(u, t, integrator) = u[2]
642642
affect!(integrator) = DE.terminate!(integrator)
643643
cb = DE.ContinuousCallback(condition, nothing, affect!)
644644
sol = DE.solve(prob, DE.Tsit5(), callback = cb)
645-
plot(sol)
645+
Plots.plot(sol)
646646
```
647647

648648
Notice that passing only one `affect!` is the same as
@@ -716,8 +716,8 @@ many cells there are at each time. Since these are discrete values, we calculate
716716
and plot them directly:
717717

718718
```@example callback5
719-
using Plots
720-
plot(sol.t, map((x) -> length(x), sol[:]), lw = 3,
719+
import Plots
720+
Plots.plot(sol.t, map((x) -> length(x), sol[:]), lw = 3,
721721
ylabel = "Number of Cells", xlabel = "Time")
722722
```
723723

@@ -726,7 +726,7 @@ plot of the concentration of cell 1 over time. This is done with the command:
726726

727727
```@example callback5
728728
ts = range(0, stop = 10, length = 100)
729-
plot(ts, map((x) -> x[1], sol.(ts)), lw = 3,
729+
Plots.plot(ts, map((x) -> x[1], sol.(ts)), lw = 3,
730730
ylabel = "Amount of X in Cell 1", xlabel = "Time")
731731
```
732732

@@ -786,6 +786,6 @@ tspan = (0.0, 15.0)
786786
p = 9.8
787787
prob = DE.ODEProblem(f, u0, tspan, p)
788788
sol = DE.solve(prob, DE.Tsit5(), callback = cb, dt = 1e-3, adaptive = false)
789-
using Plots;
790-
plot(sol, idxs = (1, 3));
789+
import Plots;
790+
Plots.plot(sol, idxs = (1, 3));
791791
```

docs/src/features/ensemble.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,11 @@ achieved with
271271
[`@everywhere` macro](https://docs.julialang.org/en/v1.2/stdlib/Distributed/#Distributed.@everywhere):
272272

273273
```julia
274-
using Distributed
274+
import Distributed
275275
import DifferentialEquations as DE
276-
using Plots
276+
import Plots
277277

278-
addprocs()
278+
Distributed.addprocs()
279279
@everywhere import DifferentialEquations as DE
280280
```
281281

@@ -308,7 +308,7 @@ sim = DE.solve(ensemble_prob, DE.Tsit5(), DE.EnsembleDistributed(), trajectories
308308
We can use the plot recipe to plot what the 10 ODEs look like:
309309

310310
```julia
311-
plot(sim, linealpha = 0.4)
311+
Plots.plot(sim, linealpha = 0.4)
312312
```
313313

314314
We note that if we wanted to find out what the initial condition was for a given
@@ -335,8 +335,8 @@ function prob_func(prob, i, repeat)
335335
end
336336
ensemble_prob = DE.EnsembleProblem(prob, prob_func = prob_func)
337337
sim = DE.solve(ensemble_prob, DE.Tsit5(), DE.EnsembleThreads(), trajectories = 10)
338-
using Plots;
339-
plot(sim);
338+
import Plots;
339+
Plots.plot(sim);
340340
```
341341

342342
The number of threads to be used has to be defined outside of Julia, in
@@ -415,9 +415,9 @@ Now we solve the problem 10 times and plot all of the trajectories in phase spac
415415
```@example ensemble2
416416
ensemble_prob = DE.EnsembleProblem(prob, prob_func = prob_func)
417417
sim = DE.solve(ensemble_prob, DE.SRIW1(), trajectories = 10)
418-
using Plots;
419-
plot(sim, linealpha = 0.6, color = :blue, idxs = (0, 1), title = "Phase Space Plot");
420-
plot!(sim, linealpha = 0.6, color = :red, idxs = (0, 2), title = "Phase Space Plot")
418+
import Plots;
419+
Plots.plot(sim, linealpha = 0.6, color = :blue, idxs = (0, 1), title = "Phase Space Plot");
420+
Plots.plot!(sim, linealpha = 0.6, color = :red, idxs = (0, 2), title = "Phase Space Plot")
421421
```
422422

423423
We can then summarize this information with the mean/variance bounds using a
@@ -426,7 +426,7 @@ units and directly plot the summary:
426426

427427
```@example ensemble2
428428
summ = DE.EnsembleSummary(sim, 0:0.1:10)
429-
plot(summ, fillalpha = 0.5)
429+
Plots.plot(summ, fillalpha = 0.5)
430430
```
431431

432432
Note that here we used the quantile bounds, which default to `[0.05,0.95]` in
@@ -463,10 +463,10 @@ batch, and declare convergence if the standard error of the mean is calculated
463463
as sufficiently small:
464464

465465
```@example ensemble3
466-
using Statistics
466+
import Statistics
467467
function reduction(u, batch, I)
468468
u = append!(u, batch)
469-
finished = (var(u) / sqrt(last(I))) / mean(u) < 0.5
469+
finished = (Statistics.var(u) / sqrt(last(I))) / Statistics.mean(u) < 0.5
470470
u, finished
471471
end
472472
```
@@ -589,19 +589,19 @@ the differential equation, this can get messy, so let's only plot the
589589
3rd component:
590590

591591
```@example ensemble4
592-
using Plots;
593-
plot(summ; idxs = 3);
592+
import Plots;
593+
Plots.plot(summ; idxs = 3);
594594
```
595595

596596
We can change to errorbars instead of ribbons and plot two different
597597
indices:
598598

599599
```@example ensemble4
600-
plot(summ; idxs = (3, 5), error_style = :bars)
600+
Plots.plot(summ; idxs = (3, 5), error_style = :bars)
601601
```
602602

603603
Or we can simply plot the mean of every component over time:
604604

605605
```@example ensemble4
606-
plot(summ; error_style = :none)
606+
Plots.plot(summ; error_style = :none)
607607
```

0 commit comments

Comments
 (0)