-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
fix: Throw better warning when a guess is missing #3456
Conversation
src/systems/problem_utils.jl
Outdated
Please provide one or more additional numeric guesses to `guesses` in \ | ||
the problem constructor. | ||
|
||
This error was thrown because symbolic value $(err.val) was found for variable $(err.sym). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only one what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the message is a bit confusing since one could interpret it as asking for more than one guess for a single variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, will change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this have a list of variables that need guesses? Not just one?
Assuming test pass I think this is good |
src/systems/problem_utils.jl
Outdated
please provide additional numeric guesses so they can resolve to numbers: | ||
""") | ||
for (sym, val) in zip(err.syms, err.vals) | ||
println(sym, " => ", val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's just missing, what's the val?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The symbolic value that it tries to assign to the variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's if it's cyclic. But this also is for if a guess is just missing, right? In which case, what does the error look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a guess it just missing it throws a different error (IncompleteInitializationError)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ModelingToolkit.jl/src/systems/diffeqs/abstractodesystem.jl
Lines 1345 to 1353 in 0ad773d
const INCOMPLETE_INITIALIZATION_MESSAGE = """ | |
Initialization incomplete. Not all of the state variables of the | |
DAE system can be determined by the initialization. Missing | |
variables: | |
""" | |
struct IncompleteInitializationError <: Exception | |
uninit::Any | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That error doesn't make much sense to the user though? Why wouldn't the case I mentioned be a missing guess error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably should be, this was just already in the code. I can make it throw a MissingGuessError instead of this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is also this error but I need to dig a bit to figure out when it throws IncompleteInitializationError vs this one, maybe @AayushSabharwal knows better
ModelingToolkit.jl/src/variables.jl
Lines 210 to 214 in 0ad773d
const MISSING_VARIABLES_MESSAGE = """ | |
Initial condition underdefined. Some are missing from the variable map. | |
Please provide a default (`u0`), initialization equation, or guess | |
for the following variables: | |
""" |
@parameters g
@variables x(t) y(t) [state_priority = 10] λ(t)
eqs = [D(D(x)) ~ λ * x
D(D(y)) ~ λ * y - g
x^2 + y^2 ~ 1]
@mtkbuild pend = ODESystem(eqs, t)
@test_throws ModelingToolkit.MissingGuessError ODEProblem(pend, [x => 1], (0, 1), [g => 1], guesses = [y => λ]) where it's missing a guess for |
ERROR: Unable to resolve numeric guesses for all of the variables in the system. This may be because your guesses are cyclic. In order for the problem to be initialized, all of the variables must have a numeric value to serve as a starting point for the nonlinear solve. Symbolic values were found for the following variables/parameters in the map; please provide additional numeric guesses so they can resolve to numbers: y(t) => 50 + λ(t) |
how does it get that? That doesn't look right. What does it print for: @parameters g
@variables x(t) y(t) [state_priority = 10] λ(t)
eqs = [D(D(x)) ~ λ * x
D(D(y)) ~ λ * y - g
x^2 + y^2 ~ 1]
@mtkbuild pend = ODESystem(eqs, t)
ODEProblem(pend, [x => 1], (0, 1), [g => 1]) ? |
ERROR: Initial condition underdefined. Some are missing from the variable map. λ(t), y(t) |
Sorry, the first case you posted actually prints this, my output was from the test I wrote
|
Okay so if any are missing you get that message, and if it's cyclic you get this other method. Given that, can we refine the error message? We know it's not a missing guess and instead a cyclic case, so we should make this more explicit. |
Fix #3449