Skip to content
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

Merged
merged 5 commits into from
Mar 18, 2025

Conversation

vyudu
Copy link
Member

@vyudu vyudu commented Mar 12, 2025

Fix #3449

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).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one what?

Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, will change

Copy link
Member

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?

@vyudu
Copy link
Member Author

vyudu commented Mar 17, 2025

Assuming test pass I think this is good

please provide additional numeric guesses so they can resolve to numbers:
""")
for (sym, val) in zip(err.syms, err.vals)
println(sym, " => ", val)
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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

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:
"""

@ChrisRackauckas
Copy link
Member

    @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 λ, what does this print?

@vyudu
Copy link
Member Author

vyudu commented Mar 17, 2025

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)
λ(t) => 2551 + y(t)

@ChrisRackauckas
Copy link
Member

y(t) => 50 + λ(t)
λ(t) => 2551 + y(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])

?

@vyudu
Copy link
Member Author

vyudu commented Mar 17, 2025

ERROR: Initial condition underdefined. Some are missing from the variable map.
Please provide a default (u0), initialization equation, or guess
for the following variables:

λ(t), y(t)

@vyudu
Copy link
Member Author

vyudu commented Mar 17, 2025

Sorry, the first case you posted actually prints this, my output was from the test I wrote

  Initial condition underdefined. Some are missing from the variable map.
  Please provide a default (`u0`), initialization equation, or guess
  for the following variables:

  λ(t)

@ChrisRackauckas
Copy link
Member

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.

@ChrisRackauckas ChrisRackauckas merged commit 9c415dc into SciML:master Mar 18, 2025
35 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better error message for missing guesses
3 participants