Skip to content

Commit 367ebd4

Browse files
refactor!: require systems to be completed before creating an XProblem
1 parent 74cada4 commit 367ebd4

File tree

7 files changed

+39
-0
lines changed

7 files changed

+39
-0
lines changed

ext/MTKBifurcationKitExt.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ function BifurcationKit.BifurcationProblem(nsys::NonlinearSystem,
8888
record_from_solution = BifurcationKit.record_sol_default,
8989
jac = true,
9090
kwargs...)
91+
if !ModelingToolkit.iscomplete(nsys)
92+
error("A completed `NonlinearSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `BifurcationProblem`")
93+
end
9194
# Creates F and J functions.
9295
ofun = NonlinearFunction(nsys; jac = jac)
9396
F = ofun.f
@@ -133,6 +136,9 @@ end
133136

134137
# When input is a ODESystem.
135138
function BifurcationKit.BifurcationProblem(osys::ODESystem, args...; kwargs...)
139+
if !ModelingToolkit.iscomplete(osys)
140+
error("A completed `ODESystem` is required. Call `complete` or `structural_simplify` on the system before creating a `BifurcationProblem`")
141+
end
136142
nsys = NonlinearSystem([0 ~ eq.rhs for eq in equations(osys)],
137143
unknowns(osys),
138144
parameters(osys);

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,9 @@ function DiffEqBase.ODEProblem{iip, specialize}(sys::AbstractODESystem, u0map =
939939
callback = nothing,
940940
check_length = true,
941941
kwargs...) where {iip, specialize}
942+
if !iscomplete(sys)
943+
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating an `ODEProblem`")
944+
end
942945
has_difference = any(isdifferenceeq, equations(sys))
943946
f, u0, p = process_DEProblem(ODEFunction{iip, specialize}, sys, u0map, parammap;
944947
t = tspan !== nothing ? tspan[1] : tspan,
@@ -1009,6 +1012,9 @@ end
10091012
function DiffEqBase.DAEProblem{iip}(sys::AbstractODESystem, du0map, u0map, tspan,
10101013
parammap = DiffEqBase.NullParameters();
10111014
check_length = true, kwargs...) where {iip}
1015+
if !iscomplete(sys)
1016+
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `DAEProblem`")
1017+
end
10121018
has_difference = any(isdifferenceeq, equations(sys))
10131019
f, du0, u0, p = process_DEProblem(DAEFunction{iip}, sys, u0map, parammap;
10141020
implicit_dae = true, du0map = du0map,
@@ -1042,6 +1048,9 @@ function DiffEqBase.DDEProblem{iip}(sys::AbstractODESystem, u0map = [],
10421048
callback = nothing,
10431049
check_length = true,
10441050
kwargs...) where {iip}
1051+
if !iscomplete(sys)
1052+
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `DDEProblem`")
1053+
end
10451054
has_difference = any(isdifferenceeq, equations(sys))
10461055
f, u0, p = process_DEProblem(DDEFunction{iip}, sys, u0map, parammap;
10471056
t = tspan !== nothing ? tspan[1] : tspan,
@@ -1102,6 +1111,9 @@ function DiffEqBase.SDDEProblem{iip}(sys::AbstractODESystem, u0map = [],
11021111
check_length = true,
11031112
sparsenoise = nothing,
11041113
kwargs...) where {iip}
1114+
if !iscomplete(sys)
1115+
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `SDDEProblem`")
1116+
end
11051117
has_difference = any(isdifferenceeq, equations(sys))
11061118
f, u0, p = process_DEProblem(SDDEFunction{iip}, sys, u0map, parammap;
11071119
t = tspan !== nothing ? tspan[1] : tspan,
@@ -1278,6 +1290,9 @@ end
12781290
function DiffEqBase.SteadyStateProblem{iip}(sys::AbstractODESystem, u0map,
12791291
parammap = SciMLBase.NullParameters();
12801292
check_length = true, kwargs...) where {iip}
1293+
if !iscomplete(sys)
1294+
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `SteadyStateProblem`")
1295+
end
12811296
f, u0, p = process_DEProblem(ODEFunction{iip}, sys, u0map, parammap;
12821297
steady_state = true,
12831298
check_length, kwargs...)

src/systems/diffeqs/sdesystem.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ function DiffEqBase.SDEProblem{iip}(sys::SDESystem, u0map = [], tspan = get_tspa
573573
parammap = DiffEqBase.NullParameters();
574574
sparsenoise = nothing, check_length = true,
575575
callback = nothing, kwargs...) where {iip}
576+
if !iscomplete(sys)
577+
error("A completed `SDESystem` is required. Call `complete` or `structural_simplify` on the system before creating an `SDEProblem`")
578+
end
576579
f, u0, p = process_DEProblem(SDEFunction{iip}, sys, u0map, parammap; check_length,
577580
kwargs...)
578581
cbs = process_events(sys; callback)

src/systems/discrete_system/discrete_system.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ function SciMLBase.DiscreteProblem(sys::DiscreteSystem, u0map = [], tspan = get_
214214
eval_expression = true,
215215
use_union = false,
216216
kwargs...)
217+
if !iscomplete(sys)
218+
error("A completed `DiscreteSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `DiscreteProblem`")
219+
end
217220
dvs = unknowns(sys)
218221
ps = parameters(sys)
219222
eqs = equations(sys)

src/systems/jumps/jumpsystem.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ function DiffEqBase.DiscreteProblem(sys::JumpSystem, u0map, tspan::Union{Tuple,
297297
checkbounds = false,
298298
use_union = true,
299299
kwargs...)
300+
if !iscomplete(sys)
301+
error("A completed `JumpSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `DiscreteProblem`")
302+
end
300303
dvs = unknowns(sys)
301304
ps = parameters(sys)
302305

@@ -388,6 +391,9 @@ sol = solve(jprob, SSAStepper())
388391
"""
389392
function JumpProcesses.JumpProblem(js::JumpSystem, prob, aggregator; callback = nothing,
390393
kwargs...)
394+
if !iscomplete(js)
395+
error("A completed `JumpSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `JumpProblem`")
396+
end
391397
unknowntoid = Dict(value(unknown) => i for (i, unknown) in enumerate(unknowns(js)))
392398
eqs = equations(js)
393399
invttype = prob.tspan[1] === nothing ? Float64 : typeof(1 / prob.tspan[2])

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ end
366366
function DiffEqBase.NonlinearProblem{iip}(sys::NonlinearSystem, u0map,
367367
parammap = DiffEqBase.NullParameters();
368368
check_length = true, kwargs...) where {iip}
369+
if !iscomplete(sys)
370+
error("A completed `NonlinearSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `NonlinearProblem`")
371+
end
369372
f, u0, p = process_NonlinearProblem(NonlinearFunction{iip}, sys, u0map, parammap;
370373
check_length, kwargs...)
371374
pt = something(get_metadata(sys), StandardNonlinearProblem())

src/systems/optimization/optimizationsystem.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map,
227227
linenumbers = true, parallel = SerialForm(),
228228
use_union = false,
229229
kwargs...) where {iip}
230+
if !iscomplete(sys)
231+
error("A completed `OptimizationSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `OptimizationProblem`")
232+
end
230233
if haskey(kwargs, :lcons) || haskey(kwargs, :ucons)
231234
Base.depwarn("`lcons` and `ucons` are deprecated. Specify constraints directly instead.",
232235
:OptimizationProblem, force = true)

0 commit comments

Comments
 (0)