Skip to content

Commit 453dd52

Browse files
Merge pull request #1107 from ChrisRackauckas-Claude/docs/api-documentation-additions
Add documentation for undocumented SciMLBase API components
2 parents d401c28 + 01b77f9 commit 453dd52

File tree

3 files changed

+193
-0
lines changed

3 files changed

+193
-0
lines changed

src/clock.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,60 @@ discrete-time systems that assume a fixed sample time, such as PID controllers a
4747
filters.
4848
""" SolverStepClock
4949

50+
"""
51+
isclock(clock)
52+
53+
Returns `true` if the object is a valid clock type (specifically a `PeriodicClock`).
54+
This function is used for type checking in clock-dependent logic.
55+
"""
5056
isclock(c::Clocks.Type) = @match c begin
5157
PeriodicClock() => true
5258
_ => false
5359
end
5460
isclock(::TimeDomain) = false
5561

62+
"""
63+
issolverstepclock(clock)
64+
65+
Returns `true` if the clock is a `SolverStepClock` that triggers at every solver step.
66+
This is useful for monitoring solver progress or implementing step-dependent logic.
67+
"""
5668
issolverstepclock(c::Clocks.Type) = @match c begin
5769
SolverStepClock() => true
5870
_ => false
5971
end
6072
issolverstepclock(::TimeDomain) = false
6173

74+
"""
75+
iscontinuous(clock)
76+
77+
Returns `true` if the clock operates in continuous time (i.e., is a `ContinuousClock`).
78+
Continuous clocks allow events to occur at any real-valued time instant.
79+
"""
6280
iscontinuous(c::Clocks.Type) = @match c begin
6381
ContinuousClock() => true
6482
_ => false
6583
end
6684
iscontinuous(::TimeDomain) = false
6785

86+
"""
87+
iseventclock(clock)
88+
89+
Returns `true` if the clock is an `EventClock` that triggers based on specific events.
90+
Event clocks are used for condition-based triggering in hybrid systems.
91+
"""
6892
iseventclock(c::Clocks.Type) = @match c begin
6993
EventClock() => true
7094
_ => false
7195
end
7296
iseventclock(::TimeDomain) = false
7397

98+
"""
99+
is_discrete_time_domain(clock)
100+
101+
Returns `true` if the clock operates in discrete time (i.e., is not a continuous clock).
102+
Discrete time domains have specific sampling intervals or event-based triggering.
103+
"""
74104
is_discrete_time_domain(c::TimeDomain) = !iscontinuous(c)
75105

76106
# workaround for https://github.com/Roger-luo/Moshi.jl/issues/43

src/function_wrappers.jl

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
1+
"""
2+
AbstractWrappedFunction{iip}
3+
4+
Abstract base type for function wrappers used in automatic differentiation and sensitivity analysis.
5+
These wrappers provide specialized interfaces for computing derivatives with respect to different variables.
6+
7+
# Type Parameter
8+
- `iip`: Boolean indicating if the function is in-place (`true`) or out-of-place (`false`)
9+
"""
110
abstract type AbstractWrappedFunction{iip} end
211
isinplace(f::AbstractWrappedFunction{iip}) where {iip} = iip
12+
13+
"""
14+
TimeGradientWrapper{iip, fType, uType, P} <: AbstractWrappedFunction{iip}
15+
16+
Wraps functions to compute gradients with respect to time. This wrapper is particularly useful for
17+
sensitivity analysis and optimization problems where the time dependence of the solution is critical.
18+
19+
# Fields
20+
- `f`: The function to wrap
21+
- `uprev`: Previous state value
22+
- `p`: Parameters
23+
24+
# Type Parameters
25+
- `iip`: Boolean indicating if the function is in-place (`true`) or out-of-place (`false`)
26+
- `fType`: Type of the wrapped function
27+
- `uType`: Type of the state variables
28+
- `P`: Type of the parameters
29+
30+
This wrapper enables automatic differentiation with respect to time by providing a consistent
31+
interface for computing `∂f/∂t` across different AD systems.
32+
"""
333
mutable struct TimeGradientWrapper{iip, fType, uType, P} <: AbstractWrappedFunction{iip}
434
f::fType
535
uprev::uType
@@ -20,6 +50,27 @@ end
2050

2151
(ff::TimeGradientWrapper{false})(t) = ff.f(ff.uprev, ff.p, t)
2252

53+
"""
54+
UJacobianWrapper{iip, fType, tType, P} <: AbstractWrappedFunction{iip}
55+
56+
Wraps functions to compute Jacobians with respect to state variables `u`. This is one of the most
57+
commonly used wrappers in the SciML ecosystem for computing the derivative of the right-hand side
58+
function with respect to the state variables.
59+
60+
# Fields
61+
- `f`: The function to wrap
62+
- `t`: Time value
63+
- `p`: Parameters
64+
65+
# Type Parameters
66+
- `iip`: Boolean indicating if the function is in-place (`true`) or out-of-place (`false`)
67+
- `fType`: Type of the wrapped function
68+
- `tType`: Type of the time variable
69+
- `P`: Type of the parameters
70+
71+
This wrapper enables efficient computation of `∂f/∂u` for Jacobian calculations in numerical solvers
72+
and automatic differentiation systems.
73+
"""
2374
mutable struct UJacobianWrapper{iip, fType, tType, P} <: AbstractWrappedFunction{iip}
2475
f::fType
2576
t::tType
@@ -43,6 +94,26 @@ end
4394
(ff::UJacobianWrapper{false})(uprev) = ff.f(uprev, ff.p, ff.t)
4495
(ff::UJacobianWrapper{false})(uprev, p, t) = ff.f(uprev, p, t)
4596

97+
"""
98+
TimeDerivativeWrapper{iip, F, uType, P} <: AbstractWrappedFunction{iip}
99+
100+
Wraps functions to compute derivatives with respect to time. This wrapper is used when you need to
101+
compute `∂f/∂t` for sensitivity analysis or when the function has explicit time dependence.
102+
103+
# Fields
104+
- `f`: The function to wrap
105+
- `u`: State variables
106+
- `p`: Parameters
107+
108+
# Type Parameters
109+
- `iip`: Boolean indicating if the function is in-place (`true`) or out-of-place (`false`)
110+
- `F`: Type of the wrapped function
111+
- `uType`: Type of the state variables
112+
- `P`: Type of the parameters
113+
114+
This wrapper provides a consistent interface for time derivative computations across different
115+
automatic differentiation backends.
116+
"""
46117
mutable struct TimeDerivativeWrapper{iip, F, uType, P} <: AbstractWrappedFunction{iip}
47118
f::F
48119
u::uType
@@ -60,6 +131,26 @@ end
60131
(ff::TimeDerivativeWrapper{true})(du1, t) = ff.f(du1, ff.u, ff.p, t)
61132
(ff::TimeDerivativeWrapper{true})(t) = (du1 = similar(ff.u); ff.f(du1, ff.u, ff.p, t); du1)
62133

134+
"""
135+
UDerivativeWrapper{iip, F, tType, P} <: AbstractWrappedFunction{iip}
136+
137+
Wraps functions to compute derivatives with respect to state variables. This wrapper is used for
138+
computing `∂f/∂u` and is fundamental for Jacobian computations in numerical solvers.
139+
140+
# Fields
141+
- `f`: The function to wrap
142+
- `t`: Time value
143+
- `p`: Parameters
144+
145+
# Type Parameters
146+
- `iip`: Boolean indicating if the function is in-place (`true`) or out-of-place (`false`)
147+
- `F`: Type of the wrapped function
148+
- `tType`: Type of the time variable
149+
- `P`: Type of the parameters
150+
151+
This wrapper enables efficient state derivative computations for use in automatic differentiation
152+
and numerical analysis algorithms.
153+
"""
63154
mutable struct UDerivativeWrapper{iip, F, tType, P} <: AbstractWrappedFunction{iip}
64155
f::F
65156
t::tType
@@ -75,6 +166,26 @@ UDerivativeWrapper(f::F, t, p) where {F} = UDerivativeWrapper{isinplace(f, 4)}(f
75166
(ff::UDerivativeWrapper{true})(du1, u) = ff.f(du1, u, ff.p, ff.t)
76167
(ff::UDerivativeWrapper{true})(u) = (du1 = similar(u); ff.f(du1, u, ff.p, ff.t); du1)
77168

169+
"""
170+
ParamJacobianWrapper{iip, fType, tType, uType} <: AbstractWrappedFunction{iip}
171+
172+
Wraps functions to compute Jacobians with respect to parameters `p`. This wrapper is essential for
173+
parameter estimation, inverse problems, and sensitivity analysis with respect to model parameters.
174+
175+
# Fields
176+
- `f`: The function to wrap
177+
- `t`: Time value
178+
- `u`: State variables
179+
180+
# Type Parameters
181+
- `iip`: Boolean indicating if the function is in-place (`true`) or out-of-place (`false`)
182+
- `fType`: Type of the wrapped function
183+
- `tType`: Type of the time variable
184+
- `uType`: Type of the state variables
185+
186+
This wrapper enables efficient computation of `∂f/∂p` for parameter sensitivity analysis and
187+
optimization algorithms.
188+
"""
78189
mutable struct ParamJacobianWrapper{iip, fType, tType, uType} <: AbstractWrappedFunction{iip}
79190
f::fType
80191
t::tType
@@ -97,6 +208,24 @@ function (ff::ParamJacobianWrapper{false})(du1, p)
97208
du1 .= ff.f(ff.u, p, ff.t)
98209
end
99210

211+
"""
212+
JacobianWrapper{iip, fType, pType} <: AbstractWrappedFunction{iip}
213+
214+
A general-purpose Jacobian wrapper that can be configured for different types of Jacobian computations.
215+
This wrapper provides a unified interface for various Jacobian calculations across the SciML ecosystem.
216+
217+
# Fields
218+
- `f`: The function to wrap
219+
- `p`: Parameters
220+
221+
# Type Parameters
222+
- `iip`: Boolean indicating if the function is in-place (`true`) or out-of-place (`false`)
223+
- `fType`: Type of the wrapped function
224+
- `pType`: Type of the parameters
225+
226+
This wrapper provides a flexible interface for Jacobian computations that can adapt to different
227+
automatic differentiation backends and numerical methods.
228+
"""
100229
mutable struct JacobianWrapper{iip, fType, pType} <: AbstractWrappedFunction{iip}
101230
f::fType
102231
p::pType

src/integrator_interface.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,50 @@ The length of the tuple is dependent on the method.
5050
function get_tmp_cache(i::DEIntegrator)
5151
error("get_tmp_cache!: method has not been implemented for the integrator")
5252
end
53+
"""
54+
user_cache(integrator::DEIntegrator)
55+
56+
Returns user-accessible cache components from the integrator. These are cache arrays that users
57+
can safely access and modify without breaking the internal integrator state.
58+
"""
5359
function user_cache(i::DEIntegrator)
5460
error("user_cache: method has not been implemented for the integrator")
5561
end
62+
63+
"""
64+
u_cache(integrator::DEIntegrator)
65+
66+
Returns the state variable cache arrays used by the integrator. These contain intermediate
67+
state values during the integration process.
68+
"""
5669
function u_cache(i::DEIntegrator)
5770
error("u_cache: method has not been implemented for the integrator")
5871
end
72+
73+
"""
74+
du_cache(integrator::DEIntegrator)
75+
76+
Returns the derivative cache arrays used by the integrator. These contain intermediate
77+
derivative values during the integration process.
78+
"""
5979
function du_cache(i::DEIntegrator)
6080
error("du_cache: method has not been implemented for the integrator")
6181
end
82+
83+
"""
84+
ratenoise_cache(integrator::DEIntegrator)
85+
86+
Returns cache arrays for rate noise in stochastic differential equations.
87+
Returns an empty tuple by default for deterministic problems.
88+
"""
6289
ratenoise_cache(i::DEIntegrator) = ()
90+
91+
"""
92+
rand_cache(integrator::DEIntegrator)
93+
94+
Returns cache arrays for random number generation in stochastic differential equations.
95+
Returns an empty tuple by default for deterministic problems.
96+
"""
6397
rand_cache(i::DEIntegrator) = ()
6498

6599
"""

0 commit comments

Comments
 (0)