Skip to content

Commit 33caa99

Browse files
fix: handle null state problem in ReconstructInitializeprob
1 parent baefe85 commit 33caa99

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/systems/nonlinear/initializesystem.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ function (rip::ReconstructInitializeprob)(srcvalp, dstvalp)
322322
if state_values(dstvalp) === nothing
323323
return nothing, newp
324324
end
325-
T = eltype(state_values(srcvalp))
325+
srcu0 = state_values(srcvalp)
326+
T = srcu0 === nothing || isempty(srcu0) ? Union{} : eltype(srcu0)
326327
if parameter_values(dstvalp) isa MTKParameters
327328
if !isempty(newp.tunable)
328329
T = promote_type(eltype(newp.tunable), T)
@@ -332,7 +333,7 @@ function (rip::ReconstructInitializeprob)(srcvalp, dstvalp)
332333
end
333334
if T == eltype(state_values(dstvalp))
334335
u0 = state_values(dstvalp)
335-
else
336+
elseif T != Union{}
336337
u0 = T.(state_values(dstvalp))
337338
end
338339
buf, repack, alias = SciMLStructures.canonicalize(SciMLStructures.Tunable(), newp)

test/initializationsystem.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,3 +1361,12 @@ end
13611361
prob = ODEProblem(sys, [], (0.0, 1.0))
13621362
@test prob.f.initialization_data !== nothing
13631363
end
1364+
1365+
@testset "`ReconstructInitializeprob` with `nothing` state" begin
1366+
@parameters p
1367+
@variables x(t)
1368+
@mtkbuild sys = ODESystem(x ~ p * t, t)
1369+
prob = @test_nowarn ODEProblem(sys, [], (0.0, 1.0), [p => 1.0])
1370+
@test_nowarn remake(prob, p = [p => 1.0])
1371+
@test_nowarn remake(prob, p = [p => ForwardDiff.Dual(1.0)])
1372+
end

0 commit comments

Comments
 (0)