Skip to content

Commit e37b0a8

Browse files
Document public API coverage
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
1 parent fa36d42 commit e37b0a8

14 files changed

Lines changed: 544 additions & 3 deletions

File tree

docs/src/basics/autodiff.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Automatic Differentiation Backends
22

3+
```@docs
4+
BVPJacobianAlgorithm
5+
```
6+
37
!!! note
48

59
We support ForwardDiff.jl, FiniteDiff.jl, Enzyme.jl, Mooncake.jl and PolyesterForwardDiff.jl(PolyesterForwardDiff only for collocation methods) via DifferentiationInterface.jl. Please refer to

docs/src/basics/solve.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# [Common Solver Options (Solve Keyword Arguments)](@id solver_options)
22

3+
```@docs
4+
integral
5+
```
6+
37
- `abstol::Number`: The absolute tolerance. Defaults to `1e-6`.
48
- `adaptive::Bool`: Whether the error control adaptivity is on, default as `true`.
59
- `controller`: Error controller for collocation methods, default as `DefectControl()`, more controller options in [Error Control Adaptivity](@ref error_control).

docs/src/basics/verbosity.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ sol = solve(prob, MIRK4(optimize = OptimizationOptimJL.BFGS()), dt = 0.1, verbos
7070

7171
```@docs
7272
BVPVerbosity
73+
DEFAULT_VERBOSE
7374
```

docs/src/devdocs/internal_interfaces.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,71 @@
55
```@docs
66
BoundaryValueDiffEqCore.AbstractBoundaryValueDiffEqAlgorithm
77
```
8+
9+
## Core Internal Interfaces
10+
11+
```@docs
12+
BoundaryValueDiffEqCore.AbstractBoundaryValueDiffEqCache
13+
BoundaryValueDiffEqCore.AbstractErrorControl
14+
BoundaryValueDiffEqCore.DiffCacheNeeded
15+
BoundaryValueDiffEqCore.EvalSol
16+
BoundaryValueDiffEqCore.NoDiffCacheNeeded
17+
BoundaryValueDiffEqCore.__FastShortcutNonlinearPolyalg
18+
BoundaryValueDiffEqCore.__Fix3
19+
BoundaryValueDiffEqCore.__add_singular_term!
20+
BoundaryValueDiffEqCore.__any_sparse_ad
21+
BoundaryValueDiffEqCore.__build_cost
22+
BoundaryValueDiffEqCore.__build_solution
23+
BoundaryValueDiffEqCore.__cache_trait
24+
BoundaryValueDiffEqCore.__concrete_kwargs
25+
BoundaryValueDiffEqCore.__concrete_solve_algorithm
26+
BoundaryValueDiffEqCore.__construct_internal_problem
27+
BoundaryValueDiffEqCore.__default_coloring_algorithm
28+
BoundaryValueDiffEqCore.__default_nonsparse_ad
29+
BoundaryValueDiffEqCore.__default_sparse_ad
30+
BoundaryValueDiffEqCore.__default_sparsity_detector
31+
BoundaryValueDiffEqCore.__extract_mesh
32+
BoundaryValueDiffEqCore.__extract_problem_details
33+
BoundaryValueDiffEqCore.__extract_u0
34+
BoundaryValueDiffEqCore.__flatten_initial_guess
35+
BoundaryValueDiffEqCore.__get_bcresid_prototype
36+
BoundaryValueDiffEqCore.__get_non_sparse_ad
37+
BoundaryValueDiffEqCore.__has_initial_guess
38+
BoundaryValueDiffEqCore.__initial_guess
39+
BoundaryValueDiffEqCore.__initial_guess_length
40+
BoundaryValueDiffEqCore.__initial_guess_on_mesh
41+
BoundaryValueDiffEqCore.__internal_nlsolve_problem
42+
BoundaryValueDiffEqCore.__internal_optimization_problem
43+
BoundaryValueDiffEqCore.__internal_solve
44+
BoundaryValueDiffEqCore.__materialize_jacobian_algorithm
45+
BoundaryValueDiffEqCore.__maybe_allocate_diffcache
46+
BoundaryValueDiffEqCore.__maybe_matmul!
47+
BoundaryValueDiffEqCore.__needs_diffcache
48+
BoundaryValueDiffEqCore.__resize!
49+
BoundaryValueDiffEqCore.__restructure_sol
50+
BoundaryValueDiffEqCore.__split_kwargs
51+
BoundaryValueDiffEqCore.__tunable_part
52+
BoundaryValueDiffEqCore.__use_both_error_control
53+
BoundaryValueDiffEqCore.__vec
54+
BoundaryValueDiffEqCore.__vec_bc
55+
BoundaryValueDiffEqCore.__vec_bc!
56+
BoundaryValueDiffEqCore.__vec_f
57+
BoundaryValueDiffEqCore.__vec_f!
58+
BoundaryValueDiffEqCore.__vec_so_bc
59+
BoundaryValueDiffEqCore.__vec_so_bc!
60+
BoundaryValueDiffEqCore._process_verbose_param
61+
BoundaryValueDiffEqCore._sparse_like
62+
BoundaryValueDiffEqCore._unwrap_val
63+
BoundaryValueDiffEqCore.concrete_jacobian_algorithm
64+
BoundaryValueDiffEqCore.diff!
65+
BoundaryValueDiffEqCore.eval_bc_residual
66+
BoundaryValueDiffEqCore.eval_bc_residual!
67+
BoundaryValueDiffEqCore.get_dense_ad
68+
BoundaryValueDiffEqCore.interval
69+
BoundaryValueDiffEqCore.nodual_value
70+
BoundaryValueDiffEqCore.recursive_flatten
71+
BoundaryValueDiffEqCore.recursive_flatten!
72+
BoundaryValueDiffEqCore.recursive_flatten_twopoint!
73+
BoundaryValueDiffEqCore.recursive_unflatten!
74+
BoundaryValueDiffEqCore.safe_similar
75+
```

docs/src/solvers/mirk.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ MIRK3
2828
MIRK4
2929
MIRK5
3030
MIRK6
31+
MIRK6I
32+
maxsol
33+
minsol
3134
```

lib/BoundaryValueDiffEqCore/src/calc_errors.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,10 @@ struct REErrorControl <: GlobalErrorControlMethod end
115115

116116
# Some utils for error control adaptivity
117117
# If error control use both defect and global error or not
118+
"""
119+
__use_both_error_control(controller) -> Bool
120+
121+
Return whether an error controller combines defect and global error control.
122+
"""
118123
@inline __use_both_error_control(::HybridErrorControl) = true
119124
@inline __use_both_error_control(_) = false

lib/BoundaryValueDiffEqCore/src/default_internal_solve.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ function __FastShortcutBVPCompatibleNonlinearPolyalg(
4444
return NonlinearSolvePolyAlgorithm(algs)
4545
end
4646

47+
"""
48+
__FastShortcutNonlinearPolyalg(T = Float64; concrete_jac = nothing, linsolve = nothing,
49+
autodiff = nothing)
50+
51+
Build the default nonlinear solver polyalgorithm used when a BVP algorithm does not supply
52+
an explicit nonlinear solver.
53+
"""
4754
function __FastShortcutNonlinearPolyalg(
4855
::Type{T} = Float64; concrete_jac = nothing,
4956
linsolve = nothing, autodiff = nothing
@@ -91,7 +98,12 @@ end
9198
end
9299
end
93100

94-
# Some optimization algorithms (solvers from interfacing packages) don't support the __solve(prob) interface
101+
"""
102+
__internal_solve(prob, alg; kwargs...)
103+
104+
Dispatch to the appropriate solve entry point for internal nonlinear, nonlinear least
105+
squares, and optimization problems.
106+
"""
95107
@inline __internal_solve(
96108
prob::Union{SciMLBase.NonlinearProblem, SciMLBase.NonlinearLeastSquaresProblem},
97109
alg; kwargs...

lib/BoundaryValueDiffEqCore/src/internal_problems.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
@inline __default_cost(::Nothing) = (x, p) -> 0.0
22
@inline __default_cost(f) = f
3+
4+
"""
5+
__build_cost(fun, cache, mesh, M; tune_parameters = false, p = nothing)
6+
7+
Build the objective function used by optimization-based BVP solves from a user supplied
8+
cost functional.
9+
"""
310
@inline __build_cost(::Nothing, cache, mesh, M; kwargs...) = (x, p) -> 0.0
411
@inline function __build_cost(fun, cache, mesh, M; tune_parameters = false, p = nothing)
512
if tune_parameters && SciMLStructures.isscimlstructure(p)
@@ -79,6 +86,12 @@ end
7986
return lb, ub
8087
end
8188

89+
"""
90+
integral(fun, domain)
91+
92+
Evaluate a one-dimensional integral over `domain` using the default `Integrals.QuadGKJL`
93+
backend.
94+
"""
8295
function integral(fun, domain)
8396
prob = IntegralProblem(fun, domain)
8497
sol = SciMLBase.solve(prob, Integrals.QuadGKJL())

lib/BoundaryValueDiffEqCore/src/solution_utils.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# Intermediate solution evaluation
2+
"""
3+
EvalSol(u, t, cache)
4+
5+
Internal interpolatable solution wrapper used while forming collocation residuals and
6+
optimization objectives.
7+
"""
28
@concrete struct EvalSol{C}
39
u
410
t

lib/BoundaryValueDiffEqCore/src/types.jl

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
# Sparsity Detection
2+
"""
3+
BVPJacobianAlgorithm(diffmode = missing; nonbc_diffmode = missing, bc_diffmode = missing)
4+
5+
Select the automatic differentiation backends used to form boundary value problem
6+
Jacobians.
7+
8+
For two-point problems, `diffmode` is used for the whole residual. For standard
9+
multi-point problems, `nonbc_diffmode` is used for the differential equation residual and
10+
`bc_diffmode` is used for the boundary condition residual. Passing `diffmode` fills both
11+
specialized fields unless they are supplied explicitly.
12+
"""
213
@concrete struct BVPJacobianAlgorithm
314
bc_diffmode
415
nonbc_diffmode
516
diffmode
617
end
718

19+
"""
20+
__materialize_jacobian_algorithm(nlsolve, jac_alg)
21+
22+
Normalize a user supplied AD backend or Jacobian algorithm into a `BVPJacobianAlgorithm`.
23+
When `jac_alg` is not supplied, the nonlinear solver's `jacobian_ad` field is used if it
24+
exists.
25+
"""
826
@inline __materialize_jacobian_algorithm(_, alg::BVPJacobianAlgorithm) = alg
927
@inline __materialize_jacobian_algorithm(_, alg::ADTypes.AbstractADType) = BVPJacobianAlgorithm(alg)
1028
@inline __materialize_jacobian_algorithm(::Nothing, ::Nothing) = BVPJacobianAlgorithm()
@@ -30,6 +48,11 @@ function Base.show(io::IO, alg::BVPJacobianAlgorithm)
3048
return print(io, ")")
3149
end
3250

51+
"""
52+
__any_sparse_ad(ad_or_jac_alg) -> Bool
53+
54+
Return whether an AD backend or `BVPJacobianAlgorithm` contains an `AutoSparse` backend.
55+
"""
3356
@inline __any_sparse_ad(::AutoSparse) = true
3457
@inline function __any_sparse_ad(jac_alg::BVPJacobianAlgorithm)
3558
return __any_sparse_ad(jac_alg.bc_diffmode) ||
@@ -104,6 +127,11 @@ function concrete_jacobian_algorithm(jac_alg::BVPJacobianAlgorithm, prob_type, p
104127
return BVPJacobianAlgorithm(bc_diffmode, nonbc_diffmode, diffmode)
105128
end
106129

130+
"""
131+
__default_sparse_ad(x_or_type)
132+
133+
Choose the default sparse AD backend for an input value or element type.
134+
"""
107135
@inline function __default_sparse_ad(x::AbstractArray{T}) where {T}
108136
return isbitstype(T) ? __default_sparse_ad(T) : __default_sparse_ad(first(x))
109137
end
@@ -136,15 +164,33 @@ end
136164
)
137165
end
138166

167+
"""
168+
__default_coloring_algorithm(diffmode)
169+
170+
Return the sparse matrix coloring algorithm associated with `diffmode`, or the package
171+
default when none is specified.
172+
"""
139173
@inline __default_coloring_algorithm(_) = GreedyColoringAlgorithm()
140174
@inline __default_coloring_algorithm(diffmode::AutoSparse) = isnothing(diffmode) ?
141175
GreedyColoringAlgorithm() :
142176
diffmode.coloring_algorithm
177+
178+
"""
179+
__default_sparsity_detector(diffmode)
180+
181+
Return the sparsity detector associated with `diffmode`, or the package default when none
182+
is specified.
183+
"""
143184
@inline __default_sparsity_detector(_) = TracerLocalSparsityDetector()
144185
@inline __default_sparsity_detector(diffmode::AutoSparse) = isnothing(diffmode) ?
145186
TracerLocalSparsityDetector() :
146187
diffmode.sparsity_detector
147188

189+
"""
190+
__default_nonsparse_ad(x_or_type)
191+
192+
Choose the default dense AD backend for an input value or element type.
193+
"""
148194
@inline function __default_nonsparse_ad(x::AbstractArray{T}) where {T}
149195
return isbitstype(T) ? __default_nonsparse_ad(T) : __default_nonsparse_ad(first(x))
150196
end
@@ -160,6 +206,12 @@ function concretize_jacobian_algorithm(alg, prob)
160206
return alg
161207
end
162208

209+
"""
210+
__needs_diffcache(ad_or_jac_alg) -> Bool
211+
212+
Return whether the AD backend needs a `PreallocationTools.DiffCache` during residual or
213+
Jacobian evaluation.
214+
"""
163215
@inline __needs_diffcache(::AutoForwardDiff) = true
164216
@inline __needs_diffcache(::AutoPolyesterForwardDiff) = true
165217
@inline __needs_diffcache(ad::AutoSparse) = __needs_diffcache(ADTypes.dense_ad(ad))
@@ -170,6 +222,11 @@ end
170222
__needs_diffcache(jac_alg.nonbc_diffmode)
171223
end
172224

225+
"""
226+
__maybe_allocate_diffcache(x, chunksize, jac_alg)
227+
228+
Allocate a `DiffCache` for `x` when `jac_alg` requires one; otherwise return `x`.
229+
"""
173230
function __maybe_allocate_diffcache(x, chunksize, jac_alg)
174231
return __needs_diffcache(jac_alg) ?
175232
DiffCache(x, chunksize; warn_on_resize = false) : x
@@ -179,9 +236,26 @@ function __maybe_allocate_diffcache(x::DiffCache, chunksize)
179236
end
180237

181238
# DiffCache
239+
"""
240+
DiffCacheNeeded
241+
242+
Trait value indicating that a Jacobian backend needs a `DiffCache`.
243+
"""
182244
struct DiffCacheNeeded end
245+
246+
"""
247+
NoDiffCacheNeeded
248+
249+
Trait value indicating that a Jacobian backend does not need a `DiffCache`.
250+
"""
183251
struct NoDiffCacheNeeded end
184252

253+
"""
254+
__cache_trait(ad_or_jac_alg)
255+
256+
Return `DiffCacheNeeded()` or `NoDiffCacheNeeded()` for an AD backend or
257+
`BVPJacobianAlgorithm`.
258+
"""
185259
@inline __cache_trait(::AutoForwardDiff) = DiffCacheNeeded()
186260
@inline __cache_trait(ad::AutoSparse) = __cache_trait(ADTypes.dense_ad(ad))
187261
@inline function __cache_trait(jac_alg::BVPJacobianAlgorithm)

0 commit comments

Comments
 (0)