Skip to content

Commit 7cd2a35

Browse files
authored
Merge pull request #909 from SciML/myb/defaults
Allow incomplete initialization
2 parents 57a1325 + cf0e31d commit 7cd2a35

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ function process_DEProblem(constructor, sys::AbstractODESystem,u0map,parammap;
291291
u0 = varmap_to_vars(u0map,dvs; defaults=defs)
292292
p = varmap_to_vars(parammap,ps; defaults=defs)
293293

294-
length(dvs) == length(u0) || throw(ArgumentError("States ($(length(dvs))) and initial conditions ($(length(u0))) are of different lengths."))
294+
if u0 !== nothing
295+
length(dvs) == length(u0) || throw(ArgumentError("States ($(length(dvs))) and initial conditions ($(length(u0))) are of different lengths."))
296+
end
295297

296298
f = constructor(sys,dvs,ps,u0;tgrad=tgrad,jac=jac,checkbounds=checkbounds,
297299
linenumbers=linenumbers,parallel=parallel,simplify=simplify,

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ function process_NonlinearProblem(constructor, sys::NonlinearSystem,u0map,paramm
211211
u0 = varmap_to_vars(u0map,dvs; defaults=defs)
212212
p = varmap_to_vars(parammap,ps; defaults=defs)
213213

214-
length(dvs) == length(u0) || throw(ArgumentError("States ($(length(dvs))) and initial conditions ($(length(u0))) are of different lengths."))
214+
if u0 !== nothing
215+
length(dvs) == length(u0) || throw(ArgumentError("States ($(length(dvs))) and initial conditions ($(length(u0))) are of different lengths."))
216+
end
215217

216218
f = constructor(sys,dvs,ps,u0;jac=jac,checkbounds=checkbounds,
217219
linenumbers=linenumbers,parallel=parallel,simplify=simplify,

src/variables.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ applicable.
1212
"""
1313
function varmap_to_vars(varmap, varlist; defaults=Dict(), check=true)
1414
# Edge cases where one of the arguments is effectively empty.
15-
if varmap isa DiffEqBase.NullParameters || varmap === nothing || isempty(varmap)
15+
is_incomplete_initialization = varmap isa DiffEqBase.NullParameters || varmap === nothing
16+
if is_incomplete_initialization || isempty(varmap)
1617
if isempty(defaults)
17-
check && (isempty(varlist) || throw_missingvars(varlist))
18+
if !is_incomplete_initialization && check
19+
isempty(varlist) || throw_missingvars(varlist)
20+
end
1821
return nothing
1922
else
2023
varmap = Dict()

test/sdesystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ solexpr = solve(eval(probexpr),SRIW1(),seed=1)
2929
@test all(x->x==0,Array(sol-solexpr))
3030

3131
# Test no error
32-
@test_nowarn SDEProblem(de,zeros(3),(0, 10.0),zeros(3))
32+
@test_nowarn SDEProblem(de,nothing,(0, 10.0))
3333

3434
noiseeqs_nd = [0.01*x 0.01*x*y 0.02*x*z
3535
σ 0.01*y 0.02*x*z

test/structural_transformation/tearing.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ daesys = ODESystem(eqs, t)
149149
newdaesys = tearing(daesys)
150150
@test equations(newdaesys) == [D(x) ~ z; 0 ~ x + sin(z) - p*t]
151151
@test isequal(states(newdaesys), [x, z])
152-
@test_throws ArgumentError ODAEProblem(newdaesys, [x=>1.0], (0, 1.0))
153152
prob = ODAEProblem(newdaesys, [x=>1.0], (0, 1.0), [p=>0.2])
154153
du = [0.0]; u = [1.0]; pr = 0.2; tt = 0.1
155154
@test (@ballocated $(prob.f)($du, $u, $pr, $tt)) == 0

0 commit comments

Comments
 (0)