Skip to content

Commit 97a79f7

Browse files
Merge pull request #830 from jClugstor/aliasing_system
Add aliasing API types
2 parents 227cc3d + a698ec1 commit 97a79f7

17 files changed

+565
-2
lines changed

docs/src/interfaces/Common_Keywords.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ Note that if a method does not have adaptivity, the following rules apply:
101101

102102
## Memory Optimizations
103103

104-
- `alias_u0`: allows the solver to alias the initial condition array that is contained
105-
in the problem struct. Defaults to false.
104+
- `alias`: an `AbstractAliasSpecifier` object that holds fields specifying which variables to alias
105+
when solving. For example, to tell an ODE solver to alias the `u0` array, you can use an `ODEAliases` object,
106+
and the `alias_u0` keyword argument, e.g. `solve(prob,alias = ODEAliases(alias_u0 = true))`.
107+
For more information on what can be aliased for each problem type, see the documentation for the `AbstractAliasSpecifier`
108+
associated with that problem type. Set to `true` to alias every variable possible, or to `false` to disable aliasing.
109+
Defaults to an `AbstractAliasSpecifier` instance with `nothing` for all fields, which tells the solver to use the default behavior.
106110
- `cache`: pass a solver cache to decrease the construction time. This is not implemented
107111
for any of the problem interfaces at this moment.
108112

src/SciMLBase.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,14 @@ abstract type ADOriginator end
642642
"""
643643
$(TYPEDEF)
644644
645+
Used to specify which variables can be aliased in a solve.
646+
Every concrete AbstractAliasSpecifier should have at least the fields `alias_p` and `alias_f`.
647+
"""
648+
abstract type AbstractAliasSpecifier end
649+
650+
"""
651+
$(TYPEDEF)
652+
645653
Internal. Used for signifying the AD context comes from a ChainRules.jl definition.
646654
"""
647655
struct ChainRulesOriginator <: ADOriginator end
@@ -863,4 +871,6 @@ export ContinuousCallback, DiscreteCallback, CallbackSet, VectorContinuousCallba
863871

864872
export Clocks, TimeDomain, is_discrete_time_domain, isclock, issolverstepclock, iscontinuous
865873

874+
export ODEAliasSpecifier, LinearAliasSpecifier
875+
866876
end

src/problems/analytical_problems.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,43 @@ function AnalyticalProblem(f, u0, tspan, p = NullParameters(); kwargs...)
2828
end
2929

3030
export AnalyticalProblem, AbstractAnalyticalProblem
31+
32+
33+
@doc doc"""
34+
35+
Holds information on what variables to alias
36+
when solving an AnalyticalProblem. Conforms to the AbstractAliasSpecifier interface.
37+
`AnalyticalAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias_du0 = nothing, alias_tstops = nothing, alias = nothing)`
38+
39+
When a keyword argument is `nothing`, the default behaviour of the solver is used.
40+
41+
### Keywords
42+
* `alias_p::Union{Bool, Nothing}`
43+
* `alias_f::Union{Bool, Nothing}`
44+
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array.
45+
* `alias_du0::Union{Bool, Nothing}`: alias the du0 array for DAEs. Defaults to false.
46+
* `alias_tstops::Union{Bool, Nothing}`: alias the tstops array
47+
* `alias::Union{Bool, Nothing}`: sets all fields of the `AnalyticalAliasSpecifier` to `alias`
48+
49+
"""
50+
struct AnalyticalAliasSpecifier <: AbstractAliasSpecifier
51+
alias_p::Union{Bool, Nothing}
52+
alias_f::Union{Bool, Nothing}
53+
alias_u0::Union{Bool, Nothing}
54+
alias_du0::Union{Bool, Nothing}
55+
alias_tstops::Union{Bool, Nothing}
56+
57+
function AnalyticalAliasSpecifier(;
58+
alias_p = nothing, alias_f = nothing, alias_u0 = nothing,
59+
alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
60+
if alias == true
61+
new(true, true, true, true, true)
62+
elseif alias == false
63+
new(false, false, false, false, false)
64+
elseif isnothing(alias)
65+
new(alias_p, alias_f, alias_u0, alias_du0, alias_tstops)
66+
end
67+
end
68+
end
69+
70+

src/problems/bvp_problems.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,3 +438,42 @@ function TwoPointSecondOrderBVProblem(
438438
u0 = [initialGuess(i) for i in tspan]
439439
return TwoPointSecondOrderBVProblem(f, bc, u0, (tspan[1], tspan[end]), p; kwargs...)
440440
end
441+
442+
@doc doc"""
443+
444+
Holds information on what variables to alias
445+
when solving an BVP. Conforms to the AbstractAliasSpecifier interface.
446+
`BVPAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias_du0 = nothing, alias_tstops = nothing, alias = nothing)`
447+
448+
When a keyword argument is `nothing`, the default behaviour of the solver is used.
449+
450+
### Keywords
451+
* `alias_p::Union{Bool, Nothing}`
452+
* `alias_f::Union{Bool, Nothing}`
453+
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false .
454+
* `alias_du0::Union{Bool, Nothing}`: alias the du0 array for DAEs. Defaults to false.
455+
* `alias_tstops::Union{Bool, Nothing}`: alias the tstops array
456+
* `alias::Union{Bool, Nothing}`: sets all fields of the `BVPAliasSpecifier` to `alias`
457+
458+
"""
459+
struct BVPAliasSpecifier <: AbstractAliasSpecifier
460+
alias_p::Union{Bool, Nothing}
461+
alias_f::Union{Bool, Nothing}
462+
alias_u0::Union{Bool, Nothing}
463+
alias_du0::Union{Bool, Nothing}
464+
alias_tstops::Union{Bool, Nothing}
465+
466+
function BVPAliasSpecifier(; alias_p = nothing, alias_f = nothing, alias_u0 = nothing,
467+
alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
468+
if alias == true
469+
new(true, true, true, true, true)
470+
elseif alias == false
471+
new(false, false, false, false, false)
472+
elseif isnothing(alias)
473+
new(alias_p, alias_f, alias_u0, alias_du0, alias_tstops)
474+
end
475+
end
476+
end
477+
478+
479+

src/problems/dae_problems.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,42 @@ function ConstructionBase.constructorof(::Type{P}) where {P <: DAEProblem}
119119
return DAEProblem{iip}(f, du0, u0, tspan, p; differential_vars = dv, kw...)
120120
end
121121
end
122+
123+
@doc doc"""
124+
125+
Holds information on what variables to alias
126+
when solving a DAE. Conforms to the AbstractAliasSpecifier interface.
127+
`DAEAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias_du0 = nothing, alias_tstops = nothing, alias = nothing)`
128+
129+
When a keyword argument is `nothing`, the default behaviour of the solver is used.
130+
131+
### Keywords
132+
* `alias_p::Union{Bool, Nothing}`
133+
* `alias_f::Union{Bool, Nothing}`
134+
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false.
135+
* `alias_du0::Union{Bool, Nothing}`: alias the du0 array for DAEs. Defaults to false.
136+
* `alias_tstops::Union{Bool, Nothing}`: alias the tstops array
137+
* `alias::Union{Bool, Nothing}`: sets all fields of the `DAEAliasSpecifier` to `alias`
138+
139+
"""
140+
struct DAEAliasSpecifier
141+
alias_p::Union{Bool, Nothing}
142+
alias_f::Union{Bool, Nothing}
143+
alias_u0::Union{Bool, Nothing}
144+
alias_du0::Union{Bool, Nothing}
145+
alias_tstops::Union{Bool, Nothing}
146+
147+
function DAEAliasSpecifier(; alias_p = nothing, alias_f = nothing, alias_u0 = nothing,
148+
alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
149+
if alias == true
150+
new(true, true, true, true, true)
151+
elseif alias == false
152+
new(false, false, false, false, false)
153+
elseif isnothing(alias)
154+
new(alias_p, alias_f, alias_u0, alias_du0, alias_tstops)
155+
end
156+
end
157+
end
158+
159+
160+

src/problems/dde_problems.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,41 @@ function SecondOrderDDEProblem(f::DynamicalDDEFunction, args...; kwargs...)
396396
kwargs...)
397397
end
398398
end
399+
400+
401+
@doc doc"""
402+
403+
Holds information on what variables to alias
404+
when solving a DDE. Conforms to the AbstractAliasSpecifier interface.
405+
`DDEAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias_du0 = nothing, alias_tstops = nothing, alias = nothing)`
406+
407+
When a keyword argument is `nothing`, the default behaviour of the solver is used.
408+
409+
### Keywords
410+
* `alias_p::Union{Bool, Nothing}`
411+
* `alias_f::Union{Bool, Nothing}`
412+
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false .
413+
* `alias_du0::Union{Bool, Nothing}`: alias the du0 array for DAEs. Defaults to false.
414+
* `alias_tstops::Union{Bool, Nothing}`: alias the tstops array
415+
* `alias::Union{Bool, Nothing}`: sets all fields of the `DDEAliasSpecifier` to `alias`
416+
417+
"""
418+
struct DDEAliasSpecifier
419+
alias_p::Union{Bool, Nothing}
420+
alias_f::Union{Bool, Nothing}
421+
alias_u0::Union{Bool, Nothing}
422+
alias_tstops::Union{Bool, Nothing}
423+
424+
function DDEAliasSpecifier(; alias_p = nothing, alias_f = nothing, alias_u0 = nothing,
425+
alias_du0 = nothing, alias_tstops = nothing, alias = nothing)
426+
if alias == true
427+
new(true, true, true, true, true)
428+
elseif alias == false
429+
new(false, false, false, false, false)
430+
elseif isnothing(alias)
431+
new(alias_p, alias_f, alias_u0, alias_du0, alias_tstops)
432+
end
433+
end
434+
end
435+
436+

src/problems/discrete_problems.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,39 @@ function DiscreteProblem(u0::Union{AbstractArray, Number}, tspan::Tuple,
153153
end
154154
DiscreteProblem(f, u0, tspan, p; kwargs...)
155155
end
156+
157+
@doc doc"""
158+
159+
Holds information on what variables to alias
160+
when solving a DiscreteProblem. Conforms to the AbstractAliasSpecifier interface.
161+
`DiscreteAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias = nothing)`
162+
163+
When a keyword argument is `nothing`, the default behaviour of the solver is used.
164+
165+
### Keywords
166+
* `alias_p::Union{Bool, Nothing}`
167+
* `alias_f::Union{Bool, Nothing}`
168+
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false .
169+
* `alias::Union{Bool, Nothing}`: sets all fields of the `DiscreteAliasSpecifier` to `alias`
170+
171+
"""
172+
struct DiscreteAliasSpecifier
173+
alias_p::Union{Bool, Nothing}
174+
alias_f::Union{Bool, Nothing}
175+
alias_u0::Union{Bool, Nothing}
176+
177+
function DiscreteAliasSpecifier(;
178+
alias_p = nothing, alias_f = nothing, alias_u0 = nothing,
179+
alias_du0 = nothing, alias = nothing)
180+
if alias == true
181+
new(true, true, true, true, true)
182+
elseif alias == false
183+
new(false, false, false, false, false)
184+
elseif isnothing(alias)
185+
new(alias_p, alias_f, alias_u0)
186+
end
187+
end
188+
end
189+
190+
191+

src/problems/implicit_discrete_problems.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,38 @@ function ImplicitDiscreteProblem(f, u0, tspan, p = NullParameters();
119119
iip = isinplace(f, 6)
120120
ImplicitDiscreteProblem(ImplicitDiscreteFunction{iip}(f), u0, tspan, p; kwargs...)
121121
end
122+
123+
@doc doc"""
124+
125+
Holds information on what variables to alias
126+
when solving an ODE. Conforms to the AbstractAliasSpecifier interface.
127+
`DiscreteAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias = nothing)`
128+
129+
When a keyword argument is `nothing`, the default behaviour of the solver is used.
130+
131+
### Keywords
132+
* `alias_p::Union{Bool, Nothing}`
133+
* `alias_f::Union{Bool, Nothing}`
134+
* `alias_u0::Union{Bool, Nothing}`: alias the u0 array. Defaults to false .
135+
* `alias::Union{Bool, Nothing}`: sets all fields of the `ImplicitDiscreteAliasSpecifier` to `alias`
136+
137+
"""
138+
struct ImplicitDiscreteAliasSpecifier
139+
alias_p::Union{Bool,Nothing}
140+
alias_f::Union{Bool, Nothing}
141+
alias_u0::Union{Bool, Nothing}
142+
143+
function ImplicitDiscreteAliasSpecifier(;
144+
alias_p = nothing, alias_f = nothing, alias_u0 = nothing,
145+
alias_du0 = nothing, alias = nothing)
146+
if alias == true
147+
new(true, true, true, true, true)
148+
elseif alias == false
149+
new(false, false, false, false, false)
150+
elseif isnothing(alias)
151+
new(alias_p, alias_f, alias_u0)
152+
end
153+
end
154+
end
155+
156+

src/problems/integral_problems.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,34 @@ struct SampledIntegralProblem{Y, X, K} <: AbstractIntegralProblem{false}
167167
new{typeof(y), typeof(x), typeof(kwargs)}(y, x, dim, kwargs)
168168
end
169169
end
170+
171+
@doc doc"""
172+
173+
Holds information on what variables to alias
174+
when solving an IntegralProblem. Conforms to the AbstractAliasSpecifier interface.
175+
`IntegralAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_u0 = nothing, alias = nothing)``
176+
177+
When a keyword argument is `nothing`, the default behaviour of the solver is used.
178+
179+
### Keywords
180+
* `alias_p::Union{Bool, Nothing}`
181+
* `alias_f::Union{Bool, Nothing}`
182+
* `alias::Union{Bool, Nothing}`: sets all fields of the `IntegralAliasSpecifier` to `alias`
183+
184+
"""
185+
struct IntegralAliasSpecifier <: AbstractAliasSpecifier
186+
alias_p::Union{Bool, Nothing}
187+
alias_f::Union{Bool, Nothing}
188+
189+
function IntegralAliasSpecifier(alias_p = nothing, alias_f = nothing, alias = nothing)
190+
if alias == true
191+
new(true, true)
192+
elseif alias == false
193+
new(false, false)
194+
elseif isnothing(alias)
195+
new(alias_p, alias_f)
196+
end
197+
end
198+
end
199+
200+

src/problems/linear_problems.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,39 @@ function LinearProblem(A, b, args...; kwargs...)
7676
LinearProblem{isinplace(A, 4)}(A, b, args...; kwargs...)
7777
end
7878
end
79+
80+
@doc doc"""
81+
Holds information on what variables to alias
82+
when solving a LinearProblem. Conforms to the AbstractAliasSpecifier interface.
83+
`LinearAliasSpecifier(;alias_p = nothing, alias_f = nothing, alias_A = nothing, alias_b = nothing, alias = nothing)`
84+
85+
When a keyword argument is `nothing`, the default behaviour of the solver is used.
86+
87+
### Keywords
88+
89+
* `alias_p::Union{Bool, Nothing}`
90+
* `alias_f::Union{Bool, Nothing}`
91+
* `alias_A::Union{Bool, Nothing}`: alias the `A` array.
92+
* `alias_b::Union{Bool, Nothing}`: alias the `b` array.
93+
* `alias::Union{Bool, Nothing}`: sets all fields of the `LinearAliasSpecifier` to `alias`.
94+
95+
Creates a `LinearAliasSpecifier` where `alias_A` and `alias_b` default to `nothing`.
96+
When `alias_A` or `alias_b` is nothing, the default value of the solver is used.
97+
"""
98+
struct LinearAliasSpecifier <: AbstractAliasSpecifier
99+
alias_A::Union{Bool,Nothing}
100+
alias_b::Union{Bool,Nothing}
101+
102+
function LinearAliasSpecifier(; alias_A = nothing, alias_b = nothing,
103+
alias_p = nothing, alias_f = nothing, alias = nothing)
104+
if alias == true
105+
new(true, true, true, true)
106+
elseif alias == false
107+
new(false, false, false, false)
108+
elseif isnothing(alias)
109+
new(alias_p, alias_f, alias_A, alias_b)
110+
end
111+
end
112+
end
113+
114+

0 commit comments

Comments
 (0)