Skip to content

Commit 006f638

Browse files
Merge pull request #603 from AayushSabharwal/as/mtk-v9
fix: remove implicit MTK dependency, other bug fixes, MTKv9 compatibility
2 parents e46e491 + 3eb2f15 commit 006f638

File tree

9 files changed

+161
-242
lines changed

9 files changed

+161
-242
lines changed

src/remake.jl

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function remake(prob::ODEProblem; f = missing,
5454
tspan = missing,
5555
p = missing,
5656
kwargs = missing,
57+
interpret_symbolicmap = true,
5758
_kwargs...)
5859
if tspan === missing
5960
tspan = prob.tspan
@@ -68,14 +69,26 @@ function remake(prob::ODEProblem; f = missing,
6869
if u0 === missing
6970
u0 = prob.u0
7071
end
71-
if (eltype(p) <: Pair && !isempty(p)) || (eltype(u0) <: Pair && !isempty(u0)) # one is a non-empty symbolic map
72-
hasproperty(prob.f, :sys) && hasfield(typeof(prob.f.sys), :ps) ||
73-
throw(ArgumentError("This problem does not support symbolic maps with `remake`, i.e. it does not have a symbolic origin." *
74-
" Please use `remake` with the `p` keyword argument as a vector of values, paying attention to parameter order."))
75-
hasproperty(prob.f, :sys) && hasfield(typeof(prob.f.sys), :states) ||
76-
throw(ArgumentError("This problem does not support symbolic maps with `remake`, i.e. it does not have a symbolic origin." *
77-
" Please use `remake` with the `u0` keyword argument as a vector of values, paying attention to state order."))
72+
isu0symbolic = eltype(u0) <: Pair && !isempty(u0)
73+
ispsymbolic = eltype(p) <: Pair && !isempty(p) && interpret_symbolicmap
74+
if isu0symbolic && !has_sys(prob.f)
75+
throw(ArgumentError("This problem does not support symbolic maps with" *
76+
" remake, i.e. it does not have a symbolic origin. Please use `remake`" *
77+
"with the `u0` keyword argument as a vector of values, paying attention to" *
78+
"parameter order."))
79+
end
80+
if ispsymbolic && !has_sys(prob.f)
81+
throw(ArgumentError("This problem does not support symbolic maps with " *
82+
"`remake`, i.e. it does not have a symbolic origin. Please use `remake`" *
83+
"with the `p` keyword argument as a vector of values (paying attention to" *
84+
"parameter order) or pass `interpret_symbolicmap = false` as a keyword argument"))
85+
end
86+
if isu0symbolic && ispsymbolic
7887
p, u0 = process_p_u0_symbolic(prob, p, u0)
88+
elseif isu0symbolic
89+
_, u0 = process_p_u0_symbolic(prob, prob.p, u0)
90+
elseif ispsymbolic
91+
p, _ = process_p_u0_symbolic(prob, p, prob.u0)
7992
end
8093
end
8194

@@ -262,6 +275,7 @@ function remake(prob::OptimizationProblem;
262275
ucons = missing,
263276
sense = missing,
264277
kwargs = missing,
278+
interpret_symbolicmap = true,
265279
_kwargs...)
266280
if p === missing && u0 === missing
267281
p, u0 = prob.p, prob.u0
@@ -272,14 +286,26 @@ function remake(prob::OptimizationProblem;
272286
if u0 === missing
273287
u0 = prob.u0
274288
end
275-
if (eltype(p) <: Pair && !isempty(p)) || (eltype(u0) <: Pair && !isempty(u0)) # one is a non-empty symbolic map
276-
hasproperty(prob.f, :sys) && hasfield(typeof(prob.f.sys), :ps) ||
277-
throw(ArgumentError("This problem does not support symbolic maps with `remake`, i.e. it does not have a symbolic origin." *
278-
" Please use `remake` with the `p` keyword argument as a vector of values, paying attention to parameter order."))
279-
hasproperty(prob.f, :sys) && hasfield(typeof(prob.f.sys), :states) ||
280-
throw(ArgumentError("This problem does not support symbolic maps with `remake`, i.e. it does not have a symbolic origin." *
281-
" Please use `remake` with the `u0` keyword argument as a vector of values, paying attention to state order."))
289+
isu0symbolic = eltype(u0) <: Pair && !isempty(u0)
290+
ispsymbolic = eltype(p) <: Pair && !isempty(p) && interpret_symbolicmap
291+
if isu0symbolic && !has_sys(prob.f)
292+
throw(ArgumentError("This problem does not support symbolic maps with" *
293+
" remake, i.e. it does not have a symbolic origin. Please use `remake`" *
294+
"with the `u0` keyword argument as a vector of values, paying attention to" *
295+
"parameter order."))
296+
end
297+
if ispsymbolic && !has_sys(prob.f)
298+
throw(ArgumentError("This problem does not support symbolic maps with " *
299+
"`remake`, i.e. it does not have a symbolic origin. Please use `remake`" *
300+
"with the `p` keyword argument as a vector of values (paying attention to" *
301+
"parameter order) or pass `interpret_symbolicmap = false` as a keyword argument"))
302+
end
303+
if isu0symbolic && ispsymbolic
282304
p, u0 = process_p_u0_symbolic(prob, p, u0)
305+
elseif isu0symbolic
306+
_, u0 = process_p_u0_symbolic(prob, prob.p, u0)
307+
elseif ispsymbolic
308+
p, _ = process_p_u0_symbolic(prob, p, prob.u0)
283309
end
284310
end
285311

@@ -331,6 +357,7 @@ function remake(prob::NonlinearProblem;
331357
p = missing,
332358
problem_type = missing,
333359
kwargs = missing,
360+
interpret_symbolicmap = true,
334361
_kwargs...)
335362
if p === missing && u0 === missing
336363
p, u0 = prob.p, prob.u0
@@ -341,14 +368,26 @@ function remake(prob::NonlinearProblem;
341368
if u0 === missing
342369
u0 = prob.u0
343370
end
344-
if (eltype(p) <: Pair && !isempty(p)) || (eltype(u0) <: Pair && !isempty(u0)) # one is a non-empty symbolic map
345-
hasproperty(prob.f, :sys) && hasfield(typeof(prob.f.sys), :ps) ||
346-
throw(ArgumentError("This problem does not support symbolic maps with `remake`, i.e. it does not have a symbolic origin." *
347-
" Please use `remake` with the `p` keyword argument as a vector of values, paying attention to parameter order."))
348-
hasproperty(prob.f, :sys) && hasfield(typeof(prob.f.sys), :states) ||
349-
throw(ArgumentError("This problem does not support symbolic maps with `remake`, i.e. it does not have a symbolic origin." *
350-
" Please use `remake` with the `u0` keyword argument as a vector of values, paying attention to state order."))
371+
isu0symbolic = eltype(u0) <: Pair && !isempty(u0)
372+
ispsymbolic = eltype(p) <: Pair && !isempty(p) && interpret_symbolicmap
373+
if isu0symbolic && !has_sys(prob.f)
374+
throw(ArgumentError("This problem does not support symbolic maps with" *
375+
" remake, i.e. it does not have a symbolic origin. Please use `remke`" *
376+
"with the `u0` keyword argument as a vector of values, paying attention to" *
377+
"parameter order."))
378+
end
379+
if ispsymbolic && !has_sys(prob.f)
380+
throw(ArgumentError("This problem does not support symbolic maps with " *
381+
"`remake`, i.e. it does not have a symbolic origin. Please use `remake`" *
382+
"with the `p` keyword argument as a vector of values (paying attention to" *
383+
"parameter order) or pass `interpret_symbolicmap = false` as a keyword argument"))
384+
end
385+
if isu0symbolic && ispsymbolic
351386
p, u0 = process_p_u0_symbolic(prob, p, u0)
387+
elseif isu0symbolic
388+
_, u0 = process_p_u0_symbolic(prob, prob.p, u0)
389+
elseif ispsymbolic
390+
p, _ = process_p_u0_symbolic(prob, p, prob.u0)
352391
end
353392
end
354393

0 commit comments

Comments
 (0)