Skip to content

Commit 00c4070

Browse files
Merge pull request #919 from AayushSabharwal/as/remake-array-unknown-symbol
fix: handle array unknown provided as `Symbol` to `remake`
2 parents c01ffa5 + c5e4ede commit 00c4070

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/remake.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,10 @@ function fill_vars(
910910
v === nothing && continue
911911
idx = index_function(prob, k)
912912
idx === nothing && continue
913-
if !(idx isa AbstractArray) || symbolic_type(k) != ArraySymbolic()
913+
# If `k` is an array symbolic, and `[:k => [1.0, 2.0]]` is provided
914+
if idx isa AbstractArray && symbolic_type(k) == ScalarSymbolic()
915+
k = [idx_to_vsym[i] for i in idx]
916+
elseif !(idx isa AbstractArray) || symbolic_type(k) != ArraySymbolic()
914917
idx = (idx,)
915918
k = (k,)
916919
v = (v,)

test/downstream/modelingtoolkit_remake.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,11 @@ end
424424
@test eltype(initprob.u0) <: ForwardDiff.Dual
425425
@test eltype(SciMLStructures.canonicalize(SciMLStructures.Tunable(), initprob.p)[1]) <: ForwardDiff.Dual
426426
end
427+
428+
@testset "Array unknown specified as Symbol" begin
429+
@variables x(t)[1:2]
430+
@parameters k
431+
@mtkbuild sys = ODESystem([D(x[1]) ~ k * x[1], D(x[2]) ~ - x[2]], t)
432+
prob = ODEProblem(sys, [x => ones(2)], (0.0, 1.0), [k => 2.0])
433+
prob2 = remake(prob; u0 = [:x => 2ones(2)])
434+
end

0 commit comments

Comments
 (0)