Skip to content

Commit e100313

Browse files
authored
Merge pull request #132 from avik-pal/ap/control_precompile
2 parents 09beb00 + 55f4cc9 commit e100313

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1414
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
1515
PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
1616
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
17+
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
1718
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
1819
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1920
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
@@ -46,6 +47,7 @@ ODEInterface = "0.5"
4647
OrdinaryDiffEq = "6"
4748
PreallocationTools = "0.4"
4849
PrecompileTools = "1"
50+
Preferences = "1"
4951
RecursiveArrayTools = "2.38.10"
5052
Reexport = "0.2, 1.0"
5153
SciMLBase = "2.5"

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,19 @@ sol = solve(prob, MIRK4(), dt = 0.05)
4040
## Available Solvers
4141

4242
For the list of available solvers, please refer to the [DifferentialEquations.jl BVP Solvers page](https://docs.sciml.ai/DiffEqDocs/stable/solvers/bvp_solve/). For options for the `solve` command, see the [common solver options page](https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/).
43+
44+
## Controlling Precompilation
45+
46+
Precompilation can be controlled via `Preferences.jl`
47+
48+
- `PrecompileMIRK` -- Precompile the MIRK2 - MIRK6 algorithms (default: `true`).
49+
- `PrecompileShooting` -- Precompile the single shooting algorithms (default: `true`). This is triggered when `OrdinaryDiffEq` is loaded.
50+
- `PrecompileMultipleShooting` -- Precompile the multiple shooting algorithms (default: `true`). This is triggered when `OrdinaryDiffEq` is loaded.
51+
52+
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):
53+
54+
```julia
55+
using Preferences, UUIDs
56+
Preferences.set_preferences!(UUID("764a87c0-6b3e-53db-9096-fe964310641d"),
57+
"PrecompileShooting" => false)
58+
```

ext/BoundaryValueDiffEqOrdinaryDiffEqExt.jl

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module BoundaryValueDiffEqOrdinaryDiffEqExt
33
# This extension doesn't add any new feature atm but is used to precompile some common
44
# shooting workflows
55

6+
import Preferences: @load_preference
67
import PrecompileTools: @compile_workload, @setup_workload, @recompile_invalidations
78

89
@recompile_invalidations begin
@@ -39,16 +40,23 @@ end
3940
TwoPointBVProblem(f1, (bc1_a, bc1_b), u0, tspan; bcresid_prototype),
4041
]
4142

42-
algs = [
43-
Shooting(Tsit5();
44-
nlsolve = NewtonRaphson(; autodiff = AutoForwardDiff(chunksize = 2))),
45-
MultipleShooting(10,
46-
Tsit5();
47-
nlsolve = NewtonRaphson(; autodiff = AutoForwardDiff(chunksize = 2)),
48-
jac_alg = BVPJacobianAlgorithm(;
49-
bc_diffmode = AutoForwardDiff(; chunksize = 2),
50-
nonbc_diffmode = AutoSparseForwardDiff(; chunksize = 2))),
51-
]
43+
algs = []
44+
45+
if @load_preference("PrecompileShooting", true)
46+
push!(algs,
47+
Shooting(Tsit5();
48+
nlsolve = NewtonRaphson(; autodiff = AutoForwardDiff(chunksize = 2))))
49+
end
50+
51+
if @load_preference("PrecompileMultipleShooting", true)
52+
push!(algs,
53+
MultipleShooting(10,
54+
Tsit5();
55+
nlsolve = NewtonRaphson(; autodiff = AutoForwardDiff(chunksize = 2)),
56+
jac_alg = BVPJacobianAlgorithm(;
57+
bc_diffmode = AutoForwardDiff(; chunksize = 2),
58+
nonbc_diffmode = AutoSparseForwardDiff(; chunksize = 2))))
59+
end
5260

5361
@compile_workload begin
5462
for prob in probs, alg in algs

src/BoundaryValueDiffEq.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import PrecompileTools: @compile_workload, @setup_workload, @recompile_invalidat
44

55
@recompile_invalidations begin
66
using ADTypes, Adapt, BandedMatrices, DiffEqBase, ForwardDiff, LinearAlgebra,
7-
NonlinearSolve, PreallocationTools, RecursiveArrayTools, Reexport, SciMLBase,
8-
Setfield, SparseArrays, SparseDiffTools
7+
NonlinearSolve, PreallocationTools, Preferences, RecursiveArrayTools, Reexport,
8+
SciMLBase, Setfield, SparseArrays, SparseDiffTools
99

1010
import ADTypes: AbstractADType
1111
import ArrayInterface: matrix_colors,
@@ -74,13 +74,18 @@ end
7474
TwoPointBVProblem(f1, (bc1_a, bc1_b), u0, tspan; bcresid_prototype),
7575
]
7676

77+
algs = []
78+
7779
jac_alg = BVPJacobianAlgorithm(AutoForwardDiff(; chunksize = 2))
7880

79-
@compile_workload begin
80-
for prob in probs,
81-
alg in (MIRK2(; jac_alg), MIRK3(; jac_alg), MIRK4(; jac_alg),
82-
MIRK5(; jac_alg), MIRK6(; jac_alg))
81+
if Preferences.@load_preference("PrecompileMIRK", true)
82+
append!(algs,
83+
[MIRK2(; jac_alg), MIRK3(; jac_alg), MIRK4(; jac_alg),
84+
MIRK5(; jac_alg), MIRK6(; jac_alg)])
85+
end
8386

87+
@compile_workload begin
88+
for prob in probs, alg in algs
8489
solve(prob, alg; dt = 0.2)
8590
end
8691
end

0 commit comments

Comments
 (0)