ModelingToolkit.jl icon indicating copy to clipboard operation
ModelingToolkit.jl copied to clipboard

Give a warning for underconstrained variables forced to 0

Open Keno opened this issue 2 years ago • 4 comments

@oxinabox noticed that the following MSL test https://github.com/SciML/ModelingToolkitStandardLibrary.jl/blob/0f0fae138fe202140a4862eccaaac734051dc44f/test/Mechanical/translational.jl

has a test that depends on an underconstrained variable (either free.f or acc.f may be set to an arbitrary value without affecting the dynamics of the system). Our structural singularity removal logic detects these situations and chooses one variable arbitrarily to set to 0. However, it does so silently, so users are unaware that they likely have a modeling bug. This PR adds a warning when this happens. For example, the above mentioned test now gives:

┌ Warning: The model is under-constrained. Variable acc₊flange₊f(t) was arbitrarily chosen to be set to 0. This may indicate a model bug!
└ @ ModelingToolkit ~/.julia/dev/ModelingToolkit/src/systems/alias_elimination.jl:54

This is styled as an overridable callback, so higher level modeling frameworks that use MTK as a library can hook into this to give more domain-specific errors if desired.

Keno avatar Oct 25 '23 06:10 Keno

I'm not sure this makes sense here? I would think the check should be done on the complete call

ChrisRackauckas avatar Oct 25 '23 08:10 ChrisRackauckas

How would that call know? This information is discovered during bareiss.

Keno avatar Oct 25 '23 08:10 Keno

Bump on this? Came up again.

Keno avatar Mar 26 '24 22:03 Keno

Looks like we need to update the tests as well https://github.com/SciML/ModelingToolkit.jl/actions/runs/8443829319/job/23128226047?pr=2328#step:6:1037

YingboMa avatar Mar 27 '24 19:03 YingboMa