Skip to content

Commit dc9bd04

Browse files
fix: retain caches in ReconstructInitializeprob
1 parent 8ee3024 commit dc9bd04

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/systems/problem_utils.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,9 @@ $(TYPEDFIELDS)
632632
"""
633633
struct ReconstructInitializeprob{G}
634634
"""
635-
A function which when called on the original problem returns the parameter object of
636-
the initialization problem.
635+
A function which when given the original problem and initialization problem, returns
636+
the parameter object of the initialization problem with values copied from the
637+
original.
637638
"""
638639
getter::G
639640
end
@@ -693,14 +694,18 @@ function ReconstructInitializeprob(
693694
end
694695
getters = (tunable_getter, Returns(SizedVector{0, Float64}()), rest_getters...)
695696
getter = let getters = getters
696-
function _getter(valp)
697+
function _getter(valp, initprob)
697698
MTKParameters(getters[1](valp), getters[2](valp), getters[3](valp),
698-
getters[4](valp), getters[5](valp), ())
699+
getters[4](valp), getters[5](valp), copy.(parameter_values(initprob).caches))
699700
end
700701
end
701702
else
702703
syms = parameters(dstsys)
703-
getter = concrete_getu(srcsys, syms)
704+
getter = let inner = concrete_getu(srcsys, syms)
705+
function _getter2(valp, initprob)
706+
inner(valp)
707+
end
708+
end
704709
end
705710
return ReconstructInitializeprob(getter)
706711
end
@@ -712,7 +717,7 @@ Copy values from `srcvalp` to `dstvalp`. Returns the new `u0` and `p`.
712717
"""
713718
function (rip::ReconstructInitializeprob)(srcvalp, dstvalp)
714719
# copy parameters
715-
newp = rip.getter(srcvalp)
720+
newp = rip.getter(srcvalp, dstvalp)
716721
# no `u0`, so no type-promotion
717722
if state_values(dstvalp) === nothing
718723
return nothing, newp

0 commit comments

Comments
 (0)