Skip to content

Commit 08b3e86

Browse files
fix: handle nothing passed as u0 to ODEProblem
fix: handle non-vector non-symbolic array u0 for ODEProblem
1 parent 9aadc71 commit 08b3e86

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,14 @@ function process_DEProblem(constructor, sys::AbstractODESystem, u0map, parammap;
816816
(((implicit_dae || !isempty(missingvars) || !isempty(setobserved)) &&
817817
ModelingToolkit.get_tearing_state(sys) !== nothing) ||
818818
!isempty(initialization_equations(sys))) && t !== nothing
819+
819820
if eltype(u0map) <: Number
820-
u0map = unknowns(sys) .=> u0map
821+
u0map = unknowns(sys) .=> vec(u0map)
821822
end
822-
if isempty(u0map)
823+
if u0map === nothing || isempty(u0map)
823824
u0map = Dict()
824825
end
826+
825827
initializeprob = ModelingToolkit.InitializationProblem(
826828
sys, t, u0map, parammap; guesses, warn_initialize_determined,
827829
initialization_eqs, eval_expression, eval_module, fully_determined, check_units)

test/odesystem.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,3 +1387,10 @@ end
13871387

13881388
@test obsfn(ones(2), 2ones(2), 3ones(4), 4.0) == 6ones(2)
13891389
end
1390+
1391+
@testset "Passing `nothing` to `u0`" begin
1392+
@variables x(t) = 1
1393+
@mtkbuild sys = ODEProblem(D(x) ~ t, t)
1394+
prob = @test_nowarn ODEProblem(sys, nothing, (0.0, 1.0))
1395+
@test_nowarn solve(prob)
1396+
end

0 commit comments

Comments
 (0)