SciMLBase.jl
repository·master·Indexed 41 days ago
https://github.com/sciml/scimlbase.jlThe foundational interface layer for the SciML ecosystem, providing standardized mathematical problem definitions and interfaces for interoperability between solvers. It defines core types such as AbstractSciMLProblem and AbstractSciMLAlgorithm, covering domains including ODEs, PDEs, linear and nonlinear systems, integrals, and optimization. Version 3.0 introduces breaking changes to solution indexing (now requiring .u for timesteps), a redesigned EnsembleContext API for simulations, and the successful_retcode function for solution validation.
What's inside SciMLBase
- SciMLBase.jl serves as the core interface definition for the SciML ecosystem. It is designed as a low-dependency library that downstream SciML libraries depend on to provide a common interface, enabling the interexchange of mathematical problems across different solvers and tools.
Note on ForwardDiff compatibility
masterForwardDiffdoes not useChainRules.jl. Consequently, it ignores the standardChainRules-basedsolvehandling used by most other sensitivity algorithms in SciMLBase. If you are usingForwardDifffor direct AD through solver internals, ensure you have a pure Julia solver path and that all local operations are AD-compatible.Solve Steady-State and Analytical Problems
masterSciMLBase includes specialized types for finding equilibrium points and working with analytically evaluated trajectories.
Available problem types:
SteadyStateProblem: For finding the steady-state (equilibrium) solutions of a system.AnalyticalProblem: For problems involving trajectories that are evaluated analytically.
Use Boundary-Value Function wrappers
masterBoundary-value problems (BVPs) are handled using specific wrappers that encapsulate boundary-condition callbacks and optional derivatives. These are structured to work with various BVP solver interfaces.
Available types:
SciMLBase.BVPFunctionSciMLBase.TwoPointBVPFunctionSciMLBase.TwoPointDynamicalBVPFunctionSciMLBase.DynamicalBVPFunction
Use Noise Problem types
masterNoise problems are used to request the generation or replay of a noise-process trajectory within a simulation context.Understand the distinction between Developer API and User API
masterThe SciML ecosystem distinguishes between the User API (intended for application developers) and the Developer API (intended for package authors building solvers, symbolic systems, or numeric wrappers).
Do not use the Developer API for application code. Instead, use the standard high-level interfaces:
solvefor solving problems.remakefor updating problem parameters.- Solution interpolation interfaces.
- Return-code interfaces for error handling.
The hooks described in this documentation are internal contracts designed for package interoperability and should only be extended or called by solver and system implementers.
Use GPU backends for ensemble simulations
masterGPU acceleration for ensembles is provided by the
DiffEqGPU.jlpackage rather thanSciMLBasedirectly.EnsembleGPUArray(): Adapts trajectories to GPU arrays.EnsembleGPUKernel(backend): Compiles compatible solves into a device kernel.
Compatibility depends on the specific problem features and the selected GPU backend. Refer to the
DiffEqGPUdocumentation for detailed compatibility rules.Implement Callback condition and affect! functions
masterWhen defining a callback, you must implement two primary functions with different side-effect rules:
condition: This function inspects the proposed state, time, and integrator. It must not mutate the integrator.affect!: This function is allowed to mutate the integrator. If the state changes introduced byaffect!create discontinuities, you should normally usesave_positions = (true, true)to ensure the solver handles the discontinuity correctly.
DAE Note: For Differential-Algebraic Equations (DAEs), callback effects might require consistent reinitialization. You can control this using the
initializealgkeyword on a per-callback basis if it is not being inherited from thesolvecall.Use Boundary-Value Problem (BVP) types
masterBoundary-value problems extend the evolution contract by adding residual callbacks that are evaluated over the candidate solution or at specific boundary points. Use these when constraints are defined at the boundaries of the domain rather than just at an initial time.
Available problem types include:
BVProblemStandardBVProblemTwoPointBVProblemSecondOrderBVProblemStandardSecondOrderBVProblemTwoPointSecondOrderBVProblem
Use Nonlinear Function wrappers
masterSciMLBase provides specialized wrappers for nonlinear problems. These wrappers encapsulate residual callbacks, optional derivatives, and structural metadata. They are designed to follow the solver-facing interface, including support for in-place conventions.
Available types:
SciMLBase.NonlinearFunctionSciMLBase.HomotopyNonlinearFunctionSciMLBase.IntervalNonlinearFunction
Understand re-exported APIs in SciMLBase
masterWhen you run
using SciMLBase, several names are brought into your scope that are actually owned and documented by other packages. This is done to provide a unified interface, but for detailed reference documentation, you should look at the upstream packages.Key re-exported groups include:
- SciMLOperators: The operator interface used for operator-valued arguments (like
jac_prototypeor the linear half of aSplitFunction). - CommonSolve: The core solve verbs (
solve,solve!,init,step!) which define the SciML solve interface.
- SciMLOperators: The operator interface used for operator-valued arguments (like
Query problem properties using Problem Traits
masterProblem traits are used by solver dispatch to expose properties stored on concrete problem types. Instead of reconstructing information from fields or callback method tables, solvers should query these traits to understand the problem's convention and metadata.
Key traits include:
isinplace(prob): Reports the mutating convention selected by the problem constructor. This value is part of the problem type and must be preserved byremake, problem conversion, and wrapper problems.problem_type(prob): Returns public construction-layout metadata when multiple convenience constructors share a single concrete problem representation. Returnsnothingif no separate marker is required.is_diagonal_noise(prob): Reports whether an SDE-like problem should be treated as diagonal noise. This is typicallytrueif anoise_rate_prototypeis absent, andfalsefor non-stochastic problem types.