Skip to content

Commit 9cc526d

Browse files
Merge pull request #811 from AayushSabharwal/as/remake-nothing
feat: variables with value `nothing` passed to `remake` are ignored
2 parents ffef2f9 + c34a8f4 commit 9cc526d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/remake.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ function fill_u0(prob, u0; defs = nothing, use_defaults = false)
570570
idx_to_sym = anydict()
571571
idx_to_val = anydict()
572572
for (k, v) in u0
573+
v === nothing && continue
573574
idx = variable_index(prob, k)
574575
idx === nothing && continue
575576
if !(idx isa AbstractArray) || symbolic_type(k) != ArraySymbolic()
@@ -614,6 +615,7 @@ function fill_p(prob, p; defs = nothing, use_defaults = false)
614615
idx_to_sym = anydict()
615616
idx_to_val = anydict()
616617
for (k, v) in p
618+
v === nothing && continue
617619
idx = parameter_index(prob, k)
618620
idx === nothing && continue
619621
if !(idx isa AbstractArray) || symbolic_type(k) != ArraySymbolic()

test/remake_tests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,13 @@ a = Remake_Test1(p = 1)
314314
@test get(newp, :a2, 0) == 3
315315
@test get(newp, :b, 0) == 4.5
316316
end
317+
318+
@testset "value of `nothing` is ignored" begin
319+
sys = SymbolCache(Dict(:x => 1, :x2 => 1, :y => 2), Dict(:a => 1, :a2 => 1, :b => 2),
320+
:t; defaults = Dict(:x => 1, :y => 2, :a => 3, :b => 4))
321+
function foo(du, u, p, t)
322+
du .= u .* p
323+
end
324+
prob = ODEProblem(ODEFunction(foo; sys), [1.5, 2.5], (0.0, 1.0), [3.5, 4.5])
325+
@test_nowarn remake(prob; u0 = [:x => nothing], p = [:a => nothing])
326+
end

0 commit comments

Comments
 (0)