Skip to content

Commit fffc983

Browse files
fix: properly handle values given to parameter dependencies in late_binding_update_u0_p
1 parent 5bfb2a9 commit fffc983

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

src/systems/nonlinear/initializesystem.jl

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,25 @@ function SciMLBase.late_binding_update_u0_p(
719719
newu0, newp = promote_u0_p(newu0, newp, t0)
720720

721721
# non-symbolic u0 updates initials...
722-
if !(eltype(u0) <: Pair)
722+
if eltype(u0) <: Pair
723+
syms = []
724+
vals = []
725+
allsyms = all_symbols(sys)
726+
for (k, v) in u0
727+
v === nothing && continue
728+
(symbolic_type(v) == NotSymbolic() && !is_array_of_symbolics(v)) || continue
729+
if k isa Symbol
730+
k2 = symbol_to_symbolic(sys, k; allsyms)
731+
# if it is returned as-is, there is no match so skip it
732+
k2 === k && continue
733+
k = k2
734+
end
735+
is_parameter(sys, Initial(k)) || continue
736+
push!(syms, Initial(k))
737+
push!(vals, v)
738+
end
739+
newp = setp_oop(sys, syms)(newp, vals)
740+
else
723741
# if `p` is not provided or is symbolic
724742
p === missing || eltype(p) <: Pair || return newu0, newp
725743
(newu0 === nothing || isempty(newu0)) && return newu0, newp
@@ -732,27 +750,27 @@ function SciMLBase.late_binding_update_u0_p(
732750
throw(ArgumentError("Expected `newu0` to be of same length as unknowns ($(length(prob.u0))). Got $(typeof(newu0)) of length $(length(newu0))"))
733751
end
734752
newp = meta.set_initial_unknowns!(newp, newu0)
735-
return newu0, newp
736-
end
737-
738-
syms = []
739-
vals = []
740-
allsyms = all_symbols(sys)
741-
for (k, v) in u0
742-
v === nothing && continue
743-
(symbolic_type(v) == NotSymbolic() && !is_array_of_symbolics(v)) || continue
744-
if k isa Symbol
745-
k2 = symbol_to_symbolic(sys, k; allsyms)
746-
# if it is returned as-is, there is no match so skip it
747-
k2 === k && continue
748-
k = k2
753+
end
754+
755+
if eltype(p) <: Pair
756+
syms = []
757+
vals = []
758+
for (k, v) in p
759+
v === nothing && continue
760+
(symbolic_type(v) == NotSymbolic() && !is_array_of_symbolics(v)) || continue
761+
if k isa Symbol
762+
k2 = symbol_to_symbolic(sys, k; allsyms)
763+
# if it is returned as-is, there is no match so skip it
764+
k2 === k && continue
765+
k = k2
766+
end
767+
is_parameter(sys, Initial(k)) || continue
768+
push!(syms, Initial(k))
769+
push!(vals, v)
749770
end
750-
is_parameter(sys, Initial(k)) || continue
751-
push!(syms, Initial(k))
752-
push!(vals, v)
771+
newp = setp_oop(sys, syms)(newp, vals)
753772
end
754773

755-
newp = setp_oop(sys, syms)(newp, vals)
756774
return newu0, newp
757775
end
758776

test/initializationsystem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,9 +1252,9 @@ end
12521252
@test init(prob3)[x] 1.0
12531253
prob4 = remake(prob; p = [p => 1.0])
12541254
test_dummy_initialization_equation(prob4, x)
1255-
prob5 = remake(prob; p = [p => missing, q => 2.0])
1255+
prob5 = remake(prob; p = [p => missing, q => 4.0])
12561256
@test prob5.f.initialization_data !== nothing
1257-
@test init(prob5).ps[p] 1.0
1257+
@test init(prob5).ps[p] 2.0
12581258
end
12591259

12601260
@testset "Variables provided as symbols" begin

0 commit comments

Comments
 (0)