Skip to content

structural_simplify broken for some underdetermined NonlinearSystems #2786

Open
@AayushSabharwal

Description

@AayushSabharwal

Describe the bug 🐞

Some underdetermined nonlinear systems when simplified have a variable that only occurs on the RHS of observed equations, but is also not an unknown. Thus, it has no value assigned to it and errors.

Expected behavior

The variable should be on the LHS of an observed equation or be an unknown.

Minimal Reproducible Example 👇

Using the model in https://github.com/SciML/ModelingToolkit.jl/blob/master/test/downstream/inversemodel.jl,

@named model = InverseControlledTank()
get_sensitivity(model, :y)

Error & Stacktrace ⚠️

ERROR: UndefVarError: `filter₊x(t)[1]ˍtt` not defined
Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/SymbolicUtils/0opve/src/code.jl:375 [inlined]
  [2] macro expansion
    @ ~/.julia/packages/RuntimeGeneratedFunctions/M9ZX8/src/RuntimeGeneratedFunctions.jl:163 [inlined]
  [3] macro expansion
    @ ./none:0 [inlined]
  [4] generated_callfunc
    @ ./none:0 [inlined]
  [5] (::RuntimeGeneratedFunctions.RuntimeGeneratedFunction{…})(::Vector{…}, ::Vector{…}, ::Vector{…})
    @ RuntimeGeneratedFunctions ~/.julia/packages/RuntimeGeneratedFunctions/M9ZX8/src/RuntimeGeneratedFunctions.jl:150
  [6] f
    @ ~/.julia/packages/ModelingToolkit/3Suzf/src/systems/nonlinear/nonlinearsystem.jl:292 [inlined]
  [7] NonlinearFunction
    @ ~/.julia/packages/SciMLBase/roUH9/src/scimlfunctions.jl:2297 [inlined]
  [8] evaluate_f(prob::NonlinearLeastSquaresProblem{…}, u::Vector{…})
    @ NonlinearSolve ~/.julia/packages/NonlinearSolve/m8oNC/src/internal/helpers.jl:7
  [9] __init(::NonlinearLeastSquaresProblem{…}, ::NonlinearSolve.GeneralizedFirstOrderAlgorithm{…}; stats::SciMLBase.NLStats, alias_u0::Bool, maxiters::Int64, abstol::Nothing, reltol::Nothing, maxtime::Nothing, termination_condition::Nothing, internalnorm::Function, linsolve_kwargs::@NamedTuple{}, kwargs::@Kwargs{})
    @ NonlinearSolve ~/.julia/packages/NonlinearSolve/m8oNC/src/core/generalized_first_order.jl:164
 [10] __init
    @ ~/.julia/packages/NonlinearSolve/m8oNC/src/core/generalized_first_order.jl:154 [inlined]
 [11] __solve(::NonlinearLeastSquaresProblem{…}, ::NonlinearSolve.GeneralizedFirstOrderAlgorithm{…}; stats::SciMLBase.NLStats, kwargs::@Kwargs{})
    @ NonlinearSolve ~/.julia/packages/NonlinearSolve/m8oNC/src/core/generic.jl:3
 [12] __solve
    @ ~/.julia/packages/NonlinearSolve/m8oNC/src/core/generic.jl:1 [inlined]

Environment (please complete the following information):

MTK downstream environment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions