-
-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fails to initialize with units #3086
Comments
please see #2342 (comment) It will takes time to improve the Unit system. Unit is just for displaying to user, not for modeling and equation solving. I think the most important thing currently is not that, but other features and bug correction. |
Thanks for this response, but I'm not sure I completely understand it. This is something that used to work, but stopped working sometime during the last month or so. It doesn't involve unit literals. I guess I should have labeled it as a regression, but I'm not exactly sure which version it most recently worked with. I can look into that. |
This worked fine in MTK 9.38 but was broken in 9.39. Maybe #3032 caused the problem? |
For some reason in the initialization system unit check it's only using the value and uniting the values right. Before that PR, it wasn't doing an initialization system at all, which is incorrect since you have an overconstrained system. The easiest "fix" for now is to just make sure that if you have an ODE that you initialize it like an ODE, for example: using ModelingToolkit
using ModelingToolkit: t, D
using DimensionalQuantities
@variables a(t) = 1.0 [unit=u"kg"]
@variables b(t) [unit=u"kg"]
@constants c = 3.0 [unit=u"s"]
eqs = [D(a) ~ a/c, b ~ a]
sys = structural_simplify(ODESystem(eqs, t; name=:sys))
sys_nl = generate_initializesystem(sys) Your model was incorrect anyways since the initial conditions you gave are impossible to satisfy, so this is a much more sane formulation. |
Would it make sense to add a kwarg to turn off unit checking (e.g. Also, presumably, fixing the above case to make unit validation pass would probably require creating a new Adding an option to turn off unit checking would also fix SciML/MethodOfLines.jl#287 , which is another case where unit checking has already passed during initial system construction but an automatic transformation causes it to fail, presumably for the same reason involving the use of literals rather than Finally, an option to turn off unit checking would make debugging easier, for cases where one just wants to try something to see what happens and doesn't want to worry about making all the units work out. |
There already is a keyword argument to turn off the unit checking. |
Well then! |
Describe the bug 🐞
Systems don't seem to initialize properly if there are units.
Expected behavior
I would like to be able to run the system but it fails during initialization.
Minimal Reproducible Example 👇
Error & Stacktrace⚠️
Environment (please complete the following information):
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
The text was updated successfully, but these errors were encountered: