Skip to content

Commit c5266f4

Browse files
Merge pull request #1165 from SebastianM-C/smc/dynopt
add AbstractDynamicOptProblem with remake
2 parents b59a86d + c1834c7 commit c5266f4

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/SciMLBase.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ abstract type AbstractODEProblem{uType, tType, isinplace} <: AbstractDEProblem e
135135
"""
136136
$(TYPEDEF)
137137
138+
Base for types which define dynamical optimization problems.
139+
"""
140+
abstract type AbstractDynamicOptProblem{uType, tType, isinplace} <:
141+
AbstractODEProblem{uType, tType, isinplace} end
142+
143+
"""
144+
$(TYPEDEF)
145+
138146
Base for types which define discrete problems.
139147
"""
140148
abstract type AbstractDiscreteProblem{uType, tType, isinplace} <:

src/remake.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,43 @@ function remake(prob::ODEProblem; f = missing,
270270
return prob
271271
end
272272

273+
function SciMLBase.remake(prob::AbstractDynamicOptProblem; f = missing,
274+
u0 = missing,
275+
tspan = missing,
276+
p = missing,
277+
wrapped_model = missing,
278+
kwargs = missing,
279+
interpret_symbolicmap = true,
280+
use_defaults = false,
281+
lazy_initialization = nothing,
282+
_kwargs...
283+
)
284+
285+
if tspan === missing
286+
tspan = prob.tspan
287+
end
288+
289+
newu0, newp = updated_u0_p(prob, u0, p, tspan[1]; interpret_symbolicmap, use_defaults)
290+
291+
f = coalesce(f, prob.f)
292+
wrapped_model = coalesce(wrapped_model, prob.wrapped_model)
293+
294+
T = parameterless_type(typeof(prob))
295+
296+
prob = if kwargs === missing
297+
T(f, newu0, tspan, newp, wrapped_model; prob.kwargs..., _kwargs...)
298+
else
299+
T(f, newu0, tspan, newp, wrapped_model; kwargs...)
300+
end
301+
302+
u0, p = maybe_eager_initialize_problem(prob, nothing, lazy_initialization)
303+
304+
@reset prob.u0 = u0
305+
@reset prob.p = p
306+
307+
return prob
308+
end
309+
273310
"""
274311
remake_initializeprob(sys, scimlfn, u0, t0, p)
275312

0 commit comments

Comments
 (0)