From a4f30c7661f36dadba604205c9fb65a537325f79 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Thu, 5 Dec 2024 01:59:37 +0530 Subject: [PATCH] fix: fix `remake_initializeprob` handling of no pre-existing initializeprob --- src/systems/nonlinear/initializesystem.jl | 31 +++-------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/src/systems/nonlinear/initializesystem.jl b/src/systems/nonlinear/initializesystem.jl index 726d171bd0..64c62bfa29 100644 --- a/src/systems/nonlinear/initializesystem.jl +++ b/src/systems/nonlinear/initializesystem.jl @@ -291,33 +291,10 @@ function SciMLBase.remake_initialization_data(sys::ODESystem, odefn, u0, t0, p, end else # there is no initializeprob, so the original problem construction - # had no solvable parameters and had the differential variables - # specified in `u0map`. - if u0 === missing - # the user didn't pass `u0` to `remake`, so they want to retain - # existing values. Fill the differential variables in `u0map`, - # initialization will either be elided or solve for the algebraic - # variables - diff_idxs = isdiffeq.(equations(sys)) - for i in eachindex(dvs) - diff_idxs[i] || continue - u0map[dvs[i]] = newu0[i] - end - end - if p === missing - # the user didn't pass `p` to `remake`, so they want to retain - # existing values. Fill all parameters in `pmap` so that none of - # them are solvable. - for p in ps - pmap[p] = getp(sys, p)(newp) - end - end - # all non-solvable parameters need values regardless - for p in ps - haskey(pmap, p) && continue - is_parameter_solvable(p, pmap, defs, guesses) && continue - pmap[p] = getp(sys, p)(newp) - end + # had all variables specified in `u0map`, all parameters specified + # and no parameter dependencies specified. + add_fallbacks!(u0map, dvs, to_varmap(Dict(dvs .=> newu0), dvs)) + add_fallbacks!(pmap, ps, to_varmap(Dict(k => getp(sys, k)(newp) for k in ps), ps)) end if t0 === nothing t0 = 0.0