From 039a45d3922f71f8dd777769142ed00f36384e46 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Mon, 29 Jan 2024 16:08:35 +0530 Subject: [PATCH] refactor!: require systems to be `complete`d before creating an `XProblemExpr` --- src/systems/diffeqs/abstractodesystem.jl | 9 +++++++++ src/systems/diffeqs/sdesystem.jl | 3 +++ src/systems/discrete_system/discrete_system.jl | 3 +++ src/systems/jumps/jumpsystem.jl | 3 +++ src/systems/nonlinear/nonlinearsystem.jl | 3 +++ src/systems/optimization/optimizationsystem.jl | 3 +++ 6 files changed, 24 insertions(+) diff --git a/src/systems/diffeqs/abstractodesystem.jl b/src/systems/diffeqs/abstractodesystem.jl index 3bb45142ce..dcc6e87705 100644 --- a/src/systems/diffeqs/abstractodesystem.jl +++ b/src/systems/diffeqs/abstractodesystem.jl @@ -1200,6 +1200,9 @@ struct ODEProblemExpr{iip} end function ODEProblemExpr{iip}(sys::AbstractODESystem, u0map, tspan, parammap = DiffEqBase.NullParameters(); check_length = true, kwargs...) where {iip} + if !iscomplete(sys) + error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `ODEProblemExpr`") + end f, u0, p = process_DEProblem(ODEFunctionExpr{iip}, sys, u0map, parammap; check_length, kwargs...) linenumbers = get(kwargs, :linenumbers, true) @@ -1242,6 +1245,9 @@ struct DAEProblemExpr{iip} end function DAEProblemExpr{iip}(sys::AbstractODESystem, du0map, u0map, tspan, parammap = DiffEqBase.NullParameters(); check_length = true, kwargs...) where {iip} + if !iscomplete(sys) + error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `DAEProblemExpr`") + end f, du0, u0, p = process_DEProblem(DAEFunctionExpr{iip}, sys, u0map, parammap; implicit_dae = true, du0map = du0map, check_length, kwargs...) @@ -1322,6 +1328,9 @@ function SteadyStateProblemExpr{iip}(sys::AbstractODESystem, u0map, parammap = SciMLBase.NullParameters(); check_length = true, kwargs...) where {iip} + if !iscomplete(sys) + error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `SteadyStateProblemExpr`") + end f, u0, p = process_DEProblem(ODEFunctionExpr{iip}, sys, u0map, parammap; steady_state = true, check_length, kwargs...) diff --git a/src/systems/diffeqs/sdesystem.jl b/src/systems/diffeqs/sdesystem.jl index c09e712171..f984ac0718 100644 --- a/src/systems/diffeqs/sdesystem.jl +++ b/src/systems/diffeqs/sdesystem.jl @@ -635,6 +635,9 @@ function SDEProblemExpr{iip}(sys::SDESystem, u0map, tspan, parammap = DiffEqBase.NullParameters(); sparsenoise = nothing, check_length = true, kwargs...) where {iip} + if !iscomplete(sys) + error("A completed `SDESystem` is required. Call `complete` or `structural_simplify` on the system before creating an `SDEProblemExpr`") + end f, u0, p = process_DEProblem(SDEFunctionExpr{iip}, sys, u0map, parammap; check_length, kwargs...) linenumbers = get(kwargs, :linenumbers, true) diff --git a/src/systems/discrete_system/discrete_system.jl b/src/systems/discrete_system/discrete_system.jl index dcb1a12dbe..1c2d1d5822 100644 --- a/src/systems/discrete_system/discrete_system.jl +++ b/src/systems/discrete_system/discrete_system.jl @@ -452,6 +452,9 @@ function DiscreteProblemExpr{iip}(sys::DiscreteSystem, u0map, tspan, parammap = DiffEqBase.NullParameters(); check_length = true, kwargs...) where {iip} + if !iscomplete(sys) + error("A completed `DiscreteSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `DiscreteProblemExpr`") + end f, u0, p = process_DiscreteProblem(DiscreteFunctionExpr{iip}, sys, u0map, parammap; check_length, kwargs...) linenumbers = get(kwargs, :linenumbers, true) diff --git a/src/systems/jumps/jumpsystem.jl b/src/systems/jumps/jumpsystem.jl index f2d4d94aad..4b4defa63c 100644 --- a/src/systems/jumps/jumpsystem.jl +++ b/src/systems/jumps/jumpsystem.jl @@ -356,6 +356,9 @@ function DiscreteProblemExpr{iip}(sys::JumpSystem, u0map, tspan::Union{Tuple, No parammap = DiffEqBase.NullParameters(); use_union = false, kwargs...) where {iip} + if !iscomplete(sys) + error("A completed `JumpSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `DiscreteProblemExpr`") + end dvs = states(sys) ps = parameters(sys) defs = defaults(sys) diff --git a/src/systems/nonlinear/nonlinearsystem.jl b/src/systems/nonlinear/nonlinearsystem.jl index ac5393debc..02822e6e4d 100644 --- a/src/systems/nonlinear/nonlinearsystem.jl +++ b/src/systems/nonlinear/nonlinearsystem.jl @@ -399,6 +399,9 @@ function NonlinearProblemExpr{iip}(sys::NonlinearSystem, u0map, parammap = DiffEqBase.NullParameters(); check_length = true, kwargs...) where {iip} + if !iscomplete(sys) + error("A completed `NonlinearSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `NonlinearProblemExpr`") + end f, u0, p = process_NonlinearProblem(NonlinearFunctionExpr{iip}, sys, u0map, parammap; check_length, kwargs...) linenumbers = get(kwargs, :linenumbers, true) diff --git a/src/systems/optimization/optimizationsystem.jl b/src/systems/optimization/optimizationsystem.jl index a5c1a47ee9..ef7695f597 100644 --- a/src/systems/optimization/optimizationsystem.jl +++ b/src/systems/optimization/optimizationsystem.jl @@ -422,6 +422,9 @@ function OptimizationProblemExpr{iip}(sys::OptimizationSystem, u0map, linenumbers = false, parallel = SerialForm(), use_union = false, kwargs...) where {iip} + if !iscomplete(sys) + error("A completed `OptimizationSystem` is required. Call `complete` or `structural_simplify` on the system before creating a `OptimizationProblemExpr`") + end if haskey(kwargs, :lcons) || haskey(kwargs, :ucons) Base.depwarn("`lcons` and `ucons` are deprecated. Specify constraints directly instead.", :OptimizationProblem, force = true)