Description
MTK's initialization can be useful, but a simple warning telling the user their initialization system is over/under-determined is not very useful for debugging. This issue is to discuss tools MTK should provide to aid users in debugging issues with initialization.
Better error messages for missing guesses
If the user doesn't provide required guesses, we throw a MissingVariablesError
which is identical to what we would throw had they not specified an initial condition for the variable at all. This doesn't convey the difference between a missing initial condition and a missing guess. The easiest solution here would be a try-catch block around the call to InitializationProblem
in problem_utils.jl
which would intercept specifically MissingVariablesError
or MissingParametersError
and throw a MissingGuessesError
instead. The overhead of a try-catch is negligible compared to the time we take for codegen, or structural_simplify
of the initialization system.
get_initialization_problem
, get_initialization_system
This is a simple function which would take a problem or solution and return the initialization problem/system stored inside that is used during solve
.
Logging when generating initialization system
Basically an optional @info
every time generate_initializesystem
does something interesting (mainly add an equation). This could be a verbose
keyword, but generate_initializesystem
can add a lot of equations and the user may thus want to only log e.g. equations added from initial conditions, or ones added for parameter initialization. Being able to add some sort of tags to log messages and allowing users to filter them easily would be helpful. Alternatively, we could use ScopedValues (ScopedValues.jl for 1.10 compatibility) to allow the user to toggle flags that determine which messages are logged. This is less extensible than custom filter functions for logs, but easier to setup and may be sufficient.
solve_initialization
A function which takes a problem, a nonlinear solver and tolerance (same keyword arguments as SciMLBase.get_initial_values
) and returns the result of solving the initialization problem (a NonlinearSolution
). This allows users to see which equations have a high residual and are failing initialization.
substitute_defaults
A function which takes a system and returns a new one with all defaults substituted into the equations/observed. Could also have a filter function to subset the substituted defaults.
substitute_parameters_from_problem
A function which takes a system and corresponding problem, and substitutes parameter values from the problem into the system's equations/observed. Useful to see "what's the relation between the variables I'm solving for" without having to parse parameter symbols. Could also have a filter function to subset the substituted parameters.