Skip to content

Commit 347f22a

Browse files
committed
Use preferences
1 parent 33f9763 commit 347f22a

File tree

3 files changed

+86
-65
lines changed

3 files changed

+86
-65
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ Precompilation can be controlled via `Preferences.jl`
4848
- `PrecompileMIRK` -- Precompile the MIRK2 - MIRK6 algorithms (default: `true`).
4949
- `PrecompileShooting` -- Precompile the single shooting algorithms (default: `true`). This is triggered when `OrdinaryDiffEq` is loaded.
5050
- `PrecompileMultipleShooting` -- Precompile the multiple shooting algorithms (default: `true`). This is triggered when `OrdinaryDiffEq` is loaded.
51+
- `PrecompileMIRKNLLS` -- Precompile the MIRK2 - MIRK6 algorithms for under-determined and over-determined BVPs (default: `true` on Julia Version 1.10 and above).
52+
- `PrecompileShootingNLLS` -- Precompile the single shooting algorithms for under-determined and over-determined BVPs (default: `true` on Julia Version 1.10 and above). This is triggered when `OrdinaryDiffEq` is loaded.
53+
- `PrecompileMultipleShootingNLLS` -- Precompile the multiple shooting algorithms for under-determined and over-determined BVPs (default: `true` on Julia Version 1.10 and above). This is triggered when `OrdinaryDiffEq` is loaded.
5154

5255
To set these preferences before loading the package, do the following (replacing `PrecompileShooting` with the preference you want to set, or pass in multiple pairs to set them together):
5356

ext/BoundaryValueDiffEqOrdinaryDiffEqExt.jl

Lines changed: 69 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -64,69 +64,78 @@ end
6464
end
6565
end
6666

67-
if VERSION v"1.10-"
68-
function f1_nlls!(du, u, p, t)
69-
du[1] = u[2]
70-
du[2] = -u[1]
71-
end
67+
function f1_nlls!(du, u, p, t)
68+
du[1] = u[2]
69+
du[2] = -u[1]
70+
end
7271

73-
f1_nlls(u, p, t) = [u[2], -u[1]]
72+
f1_nlls(u, p, t) = [u[2], -u[1]]
7473

75-
function bc1_nlls!(resid, sol, p, t)
76-
solₜ₁ = sol(0.0)
77-
solₜ₂ = sol(100.0)
78-
resid[1] = solₜ₁[1]
79-
resid[2] = solₜ₂[1] - 1
80-
resid[3] = solₜ₂[2] + 1.729109
81-
return nothing
82-
end
83-
bc1_nlls(sol, p, t) = [sol(0.0)[1], sol(100.0)[1] - 1, sol(100.0)[2] + 1.729109]
84-
85-
bc1_nlls_a!(resid, ua, p) = (resid[1] = ua[1])
86-
bc1_nlls_b!(resid, ub, p) = (resid[1] = ub[1] - 1; resid[2] = ub[2] + 1.729109)
87-
88-
bc1_nlls_a(ua, p) = [ua[1]]
89-
bc1_nlls_b(ub, p) = [ub[1] - 1, ub[2] + 1.729109]
90-
91-
tspan = (0.0, 100.0)
92-
u0 = [0.0, 1.0]
93-
bcresid_prototype1 = Array{Float64}(undef, 3)
94-
bcresid_prototype2 = (Array{Float64}(undef, 1), Array{Float64}(undef, 2))
95-
96-
probs = [
97-
BVProblem(BVPFunction(f1_nlls!, bc1_nlls!; bcresid_prototype = bcresid_prototype1),
98-
u0, tspan),
99-
BVProblem(BVPFunction(f1_nlls, bc1_nlls; bcresid_prototype = bcresid_prototype1),
100-
u0, tspan),
101-
TwoPointBVProblem(f1_nlls!, (bc1_nlls_a!, bc1_nlls_b!), u0, tspan;
102-
bcresid_prototype = bcresid_prototype2),
103-
TwoPointBVProblem(f1_nlls, (bc1_nlls_a, bc1_nlls_b), u0, tspan;
104-
bcresid_prototype = bcresid_prototype2),
105-
]
106-
107-
algs = [
108-
Shooting(Tsit5();
109-
nlsolve = LevenbergMarquardt(; autodiff = AutoForwardDiff(chunksize = 2))),
110-
Shooting(Tsit5();
111-
nlsolve = GaussNewton(; autodiff = AutoForwardDiff(chunksize = 2))),
112-
MultipleShooting(10,
113-
Tsit5();
114-
nlsolve = LevenbergMarquardt(; autodiff = AutoForwardDiff(chunksize = 2)),
115-
jac_alg = BVPJacobianAlgorithm(;
116-
bc_diffmode = AutoForwardDiff(; chunksize = 2),
117-
nonbc_diffmode = AutoSparseForwardDiff(; chunksize = 2))),
118-
MultipleShooting(10,
119-
Tsit5();
120-
nlsolve = GaussNewton(; autodiff = AutoForwardDiff(chunksize = 2)),
121-
jac_alg = BVPJacobianAlgorithm(;
122-
bc_diffmode = AutoForwardDiff(; chunksize = 2),
123-
nonbc_diffmode = AutoSparseForwardDiff(; chunksize = 2))),
124-
]
74+
function bc1_nlls!(resid, sol, p, t)
75+
solₜ₁ = sol(0.0)
76+
solₜ₂ = sol(100.0)
77+
resid[1] = solₜ₁[1]
78+
resid[2] = solₜ₂[1] - 1
79+
resid[3] = solₜ₂[2] + 1.729109
80+
return nothing
81+
end
82+
bc1_nlls(sol, p, t) = [sol(0.0)[1], sol(100.0)[1] - 1, sol(100.0)[2] + 1.729109]
12583

126-
@compile_workload begin
127-
for prob in probs, alg in algs
128-
solve(prob, alg)
129-
end
84+
bc1_nlls_a!(resid, ua, p) = (resid[1] = ua[1])
85+
bc1_nlls_b!(resid, ub, p) = (resid[1] = ub[1] - 1; resid[2] = ub[2] + 1.729109)
86+
87+
bc1_nlls_a(ua, p) = [ua[1]]
88+
bc1_nlls_b(ub, p) = [ub[1] - 1, ub[2] + 1.729109]
89+
90+
tspan = (0.0, 100.0)
91+
u0 = [0.0, 1.0]
92+
bcresid_prototype1 = Array{Float64}(undef, 3)
93+
bcresid_prototype2 = (Array{Float64}(undef, 1), Array{Float64}(undef, 2))
94+
95+
probs = [
96+
BVProblem(BVPFunction(f1_nlls!, bc1_nlls!; bcresid_prototype = bcresid_prototype1),
97+
u0, tspan),
98+
BVProblem(BVPFunction(f1_nlls, bc1_nlls; bcresid_prototype = bcresid_prototype1),
99+
u0, tspan),
100+
TwoPointBVProblem(f1_nlls!, (bc1_nlls_a!, bc1_nlls_b!), u0, tspan;
101+
bcresid_prototype = bcresid_prototype2),
102+
TwoPointBVProblem(f1_nlls, (bc1_nlls_a, bc1_nlls_b), u0, tspan;
103+
bcresid_prototype = bcresid_prototype2),
104+
]
105+
106+
algs = []
107+
108+
if @load_preference("PrecompileShootingNLLS", VERSIONv"1.10-")
109+
append!(algs,
110+
[
111+
Shooting(Tsit5();
112+
nlsolve = LevenbergMarquardt(;
113+
autodiff = AutoForwardDiff(chunksize = 2))),
114+
Shooting(Tsit5();
115+
nlsolve = GaussNewton(; autodiff = AutoForwardDiff(chunksize = 2))),
116+
])
117+
end
118+
119+
if @load_preference("PrecompileMultipleShootingNLLS", VERSIONv"1.10-")
120+
append!(algs,
121+
[
122+
MultipleShooting(10, Tsit5();
123+
nlsolve = LevenbergMarquardt(;
124+
autodiff = AutoForwardDiff(chunksize = 2)),
125+
jac_alg = BVPJacobianAlgorithm(;
126+
bc_diffmode = AutoForwardDiff(; chunksize = 2),
127+
nonbc_diffmode = AutoSparseForwardDiff(; chunksize = 2))),
128+
MultipleShooting(10, Tsit5();
129+
nlsolve = GaussNewton(; autodiff = AutoForwardDiff(chunksize = 2)),
130+
jac_alg = BVPJacobianAlgorithm(;
131+
bc_diffmode = AutoForwardDiff(; chunksize = 2),
132+
nonbc_diffmode = AutoSparseForwardDiff(; chunksize = 2))),
133+
])
134+
end
135+
136+
@compile_workload begin
137+
for prob in probs, alg in algs
138+
solve(prob, alg)
130139
end
131140
end
132141
end

src/BoundaryValueDiffEq.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,21 @@ end
133133

134134
nlsolvers = [LevenbergMarquardt(), GaussNewton()]
135135

136-
@compile_workload begin
137-
for prob in probs, nlsolve in nlsolvers,
138-
alg in (MIRK2(; jac_alg, nlsolve), MIRK3(; jac_alg, nlsolve),
139-
MIRK4(; jac_alg, nlsolve), MIRK5(; jac_alg, nlsolve),
140-
MIRK6(; jac_alg, nlsolve))
136+
algs = []
141137

138+
if Preferences.@load_preference("PrecompileMIRKNLLS", VERSIONv"1.10-")
139+
for nlsolve in nlsolvers
140+
append!(algs,
141+
[
142+
MIRK2(; jac_alg, nlsolve), MIRK3(; jac_alg, nlsolve),
143+
MIRK4(; jac_alg, nlsolve), MIRK5(; jac_alg, nlsolve),
144+
MIRK6(; jac_alg, nlsolve),
145+
])
146+
end
147+
end
148+
149+
@compile_workload begin
150+
for prob in probs, alg in algs
142151
solve(prob, alg; dt = 0.2)
143152
end
144153
end

0 commit comments

Comments
 (0)