The SciML init and solve Functions

solve function has the default definition

solve(args...; kwargs...) = solve!(init(args...; kwargs...))

The interface for the three functions is as follows:

init(::ProblemType, args...; kwargs...)::IteratorType
solve!(::IteratorType)::SolutionType

where ProblemType, IteratorType, and SolutionType are the types defined in your package.

To avoid method ambiguity, the first argument of solve, solve!, and initmust be dispatched on the type defined in your package. For example, do not define a method such as

init(::AbstractVector, ::AlgorithmType)

init and the Iterator Interface

init's return gives an IteratorType which is designed to allow the user to have more direct handling over the internal solving process. Because of this internal nature, the IteratorType has a less unified interface across problem types than other portions like ProblemType and SolutionType. For example, for differential equations this is the Integrator Interface designed for mutating solutions in a manner for callback implementation, which is distinctly different from the LinearSolve init interface which is designed for caching efficiency with reusing factorizations.

__solve and High-Level Handling

While init and solve are the common entry point for users, solver packages will mostly define dispatches on SciMLBase.__init and SciMLBase.__solve. The reason is because this allows for SciMLBase.init and SciMLBase.solve to have common implementations across all solvers for doing things such as checking for common errors and throwing high level messages. Solvers can opt-out of the high level error handling by directly defining SciMLBase.init and SciMLBase.solve instead, though this is not recommended in order to allow for uniformity of the error messages.

Low-Level Integrator Interface

SciMLBase.check_error!Function
check_error!(integrator)

Same as check_error but also set solution's return code (integrator.sol.retcode) and run postamble!.

source
SciMLBase.initialize_dae!Function
initialize_dae!(integrator::DEIntegrator,initializealg = integrator.initializealg)

Runs the DAE initialization to find a consistent state vector. The optional argument initializealg can be used to specify a different initialization algorithm to use.

source

Initialization Interface

SciMLBase.get_initial_valuesFunction
get_initial_values(prob, valp, f, alg, isinplace; kwargs...)

Return the initial u0 and p for the given SciMLProblem and initialization algorithm, and a boolean indicating whether the initialization process was successful. Keyword arguments to this function are dependent on the initialization algorithm. prob is only required for dispatching. valp refers the appropriate data structure from which the current state and parameter values should be obtained. valp is a non-timeseries value provider as defined by SymbolicIndexingInterface.jl. f is the SciMLFunction for the problem. alg is the initialization algorithm to use. isinplace is either Val{true} if valp and the SciMLFunction are inplace, and Val{false} otherwise.

source

Argument Validation

SciMLBase.TooFewArgumentsErrorType
TooFewArgumentsError

Exception thrown when a model function defines methods with fewer arguments than the SciML problem interface requires.

source