SciMLBase.jl

repository·master·Indexed 41 days ago

https://github.com/sciml/scimlbase.jl

The 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.

Tokens
24.9K
Snippets
60
Records
115
Agent score
51%

What's inside SciMLBase

  1. Overview of SciMLBase.jl

    master
    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.
  2. Note on ForwardDiff compatibility

    master
    ForwardDiff does not use ChainRules.jl. Consequently, it ignores the standard ChainRules-based solve handling used by most other sensitivity algorithms in SciMLBase. If you are using ForwardDiff for direct AD through solver internals, ensure you have a pure Julia solver path and that all local operations are AD-compatible.
  3. Use Boundary-Value Function wrappers

    master

    Boundary-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.BVPFunction
    • SciMLBase.TwoPointBVPFunction
    • SciMLBase.TwoPointDynamicalBVPFunction
    • SciMLBase.DynamicalBVPFunction
  4. Understand the distinction between Developer API and User API

    master

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

    • solve for solving problems.
    • remake for 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.

  5. Use GPU backends for ensemble simulations

    master

    GPU acceleration for ensembles is provided by the DiffEqGPU.jl package rather than SciMLBase directly.

    • 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 DiffEqGPU documentation for detailed compatibility rules.

  6. Implement Callback condition and affect! functions

    master

    When 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 by affect! create discontinuities, you should normally use save_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 initializealg keyword on a per-callback basis if it is not being inherited from the solve call.

  7. Use Boundary-Value Problem (BVP) types

    master

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

    • BVProblem
    • StandardBVProblem
    • TwoPointBVProblem
    • SecondOrderBVProblem
    • StandardSecondOrderBVProblem
    • TwoPointSecondOrderBVProblem
  8. Use Nonlinear Function wrappers

    master

    SciMLBase 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.NonlinearFunction
    • SciMLBase.HomotopyNonlinearFunction
    • SciMLBase.IntervalNonlinearFunction
  9. Understand re-exported APIs in SciMLBase

    master

    When 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_prototype or the linear half of a SplitFunction).
    • CommonSolve: The core solve verbs (solve, solve!, init, step!) which define the SciML solve interface.
  10. Query problem properties using Problem Traits

    master

    Problem 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 by remake, problem conversion, and wrapper problems.
    • problem_type(prob): Returns public construction-layout metadata when multiple convenience constructors share a single concrete problem representation. Returns nothing if no separate marker is required.
    • is_diagonal_noise(prob): Reports whether an SDE-like problem should be treated as diagonal noise. This is typically true if a noise_rate_prototype is absent, and false for non-stochastic problem types.