Skip to content

Commit 2fbb878

Browse files
fix: retain caches in ReconstructInitializeprob
1 parent 4911e86 commit 2fbb878

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
@@ -648,8 +648,9 @@ $(TYPEDFIELDS)
648648
"""
649649
struct ReconstructInitializeprob{G}
650650
"""
651-
A function which when called on the original problem returns the parameter object of
652-
the initialization problem.
651+
A function which when given the original problem and initialization problem, returns
652+
the parameter object of the initialization problem with values copied from the
653+
original.
653654
"""
654655
getter::G
655656
end
@@ -709,14 +710,18 @@ function ReconstructInitializeprob(
709710
end
710711
getters = (tunable_getter, Returns(SizedVector{0, Float64}()), rest_getters...)
711712
getter = let getters = getters
712-
function _getter(valp)
713+
function _getter(valp, initprob)
713714
MTKParameters(getters[1](valp), getters[2](valp), getters[3](valp),
714-
getters[4](valp), getters[5](valp), ())
715+
getters[4](valp), getters[5](valp), copy.(parameter_values(initprob).caches))
715716
end
716717
end
717718
else
718719
syms = parameters(dstsys)
719-
getter = concrete_getu(srcsys, syms)
720+
getter = let inner = concrete_getu(srcsys, syms)
721+
function _getter2(valp, initprob)
722+
inner(valp)
723+
end
724+
end
720725
end
721726
return ReconstructInitializeprob(getter)
722727
end
@@ -728,7 +733,7 @@ Copy values from `srcvalp` to `dstvalp`. Returns the new `u0` and `p`.
728733
"""
729734
function (rip::ReconstructInitializeprob)(srcvalp, dstvalp)
730735
# copy parameters
731-
newp = rip.getter(srcvalp)
736+
newp = rip.getter(srcvalp, dstvalp)
732737
# no `u0`, so no type-promotion
733738
if state_values(dstvalp) === nothing
734739
return nothing, newp

0 commit comments

Comments
 (0)