Skip to content

Commit fdca4e9

Browse files
refactor!: require systems to be completed before creating an XProblem
1 parent ce450b2 commit fdca4e9

File tree

6 files changed

+36
-0
lines changed

6 files changed

+36
-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
@@ -891,6 +891,9 @@ function DiffEqBase.ODEProblem{iip, specialize}(sys::AbstractODESystem, u0map =
891891
callback = nothing,
892892
check_length = true,
893893
kwargs...) where {iip, specialize}
894+
if !iscomplete(sys)
895+
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating an `ODEProblem`")
896+
end
894897
f, u0, p = process_DEProblem(ODEFunction{iip, specialize}, sys, u0map, parammap;
895898
t = tspan !== nothing ? tspan[1] : tspan,
896899
check_length, kwargs...)
@@ -959,6 +962,9 @@ end
959962
function DiffEqBase.DAEProblem{iip}(sys::AbstractODESystem, du0map, u0map, tspan,
960963
parammap = DiffEqBase.NullParameters();
961964
check_length = true, kwargs...) where {iip}
965+
if !iscomplete(sys)
966+
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `DAEProblem`")
967+
end
962968
f, du0, u0, p = process_DEProblem(DAEFunction{iip}, sys, u0map, parammap;
963969
implicit_dae = true, du0map = du0map, check_length,
964970
kwargs...)
@@ -984,6 +990,9 @@ function DiffEqBase.DDEProblem{iip}(sys::AbstractODESystem, u0map = [],
984990
callback = nothing,
985991
check_length = true,
986992
kwargs...) where {iip}
993+
if !iscomplete(sys)
994+
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `DDEProblem`")
995+
end
987996
f, u0, p = process_DEProblem(DDEFunction{iip}, sys, u0map, parammap;
988997
t = tspan !== nothing ? tspan[1] : tspan,
989998
symbolic_u0 = true,
@@ -1042,6 +1051,9 @@ function DiffEqBase.SDDEProblem{iip}(sys::AbstractODESystem, u0map = [],
10421051
check_length = true,
10431052
sparsenoise = nothing,
10441053
kwargs...) where {iip}
1054+
if !iscomplete(sys)
1055+
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `SDDEProblem`")
1056+
end
10451057
f, u0, p = process_DEProblem(SDDEFunction{iip}, sys, u0map, parammap;
10461058
t = tspan !== nothing ? tspan[1] : tspan,
10471059
symbolic_u0 = true,
@@ -1216,6 +1228,9 @@ end
12161228
function DiffEqBase.SteadyStateProblem{iip}(sys::AbstractODESystem, u0map,
12171229
parammap = SciMLBase.NullParameters();
12181230
check_length = true, kwargs...) where {iip}
1231+
if !iscomplete(sys)
1232+
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `SteadyStateProblem`")
1233+
end
12191234
f, u0, p = process_DEProblem(ODEFunction{iip}, sys, u0map, parammap;
12201235
steady_state = true,
12211236
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/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)