DiffEqDocs.jl Documentation

repository·master·Indexed 43 days ago

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

User interface documentation for the DifferentialEquations.jl ecosystem within the SciML (Scientific Machine Learning) framework. It provides API references for various solver packages including BoundaryValueDiffEq.jl, DelayDiffEq.jl, SteadyStateDiffEq.jl, SimpleDiffEq.jl, and wrapper packages such as Sundials.jl, LSODA.jl, DASSL.jl, and ODEInterfaceDiffEq.jl.

Tokens
106.4K
Snippets
278
Records
410
Agent score
55%

What's inside DiffEqDocs.jl

  1. Overview of DifferentialEquations.jl capabilities

    master

    DifferentialEquations.jl is a high-performance suite for numerically solving a wide variety of differential equations in Julia, with interfaces available for Python and R. It provides efficient implementations of classic algorithms and cutting-edge research methods, often outperforming standard C/Fortran implementations.

    Supported Equation Types:

    • Discrete equations (function maps, Gillespie/Markov simulations)
    • Ordinary differential equations (ODEs)
    • Split and Partitioned ODEs (Symplectic integrators, IMEX Methods)
    • Stochastic ODEs (SODEs/SDEs) and SDAEs
    • Random differential equations (RODEs/RDEs)
    • Differential algebraic equations (DAEs)
    • Delay differential equations (DDEs, NDDEs, RDDEs, DDAEs)
    • Stochastic delay differential equations (SDDEs, SNDDEs, SRDDEs, SDDAEs)
    • Mixed discrete and continuous equations (Hybrid Equations, Jump Diffusions)
    • (Stochastic) partial differential equations ((S)PDEs) via finite difference and finite element methods

    Key Integrations:

    • Acceleration: GPU acceleration via CUDA.jl and DiffEqGPU.jl.
    • Sparsity & Linear Algebra: Automatic sparsity detection with Symbolics.jl, Jacobian coloring with SparseDiffTools.jl, and custom linear solvers via LinearSolve.jl.
    • Analysis: Forward/Adjoint Sensitivity Analysis, Parameter Estimation, Bayesian Analysis, and Neural Differential Equations via DiffEqFlux.jl.
    • Parallelism: Automatic distributed, multithreaded, and GPU parallel ensemble simulations.
  2. Overview of the Beeler-Reuter ventricular ionic model

    master

    The Beeler-Reuter model is a classic cardiac electrophysiology model used to describe the time-evolution of transmembrane potential and gating variables. It is characterized as a stiff system due to the varying time scales of its state variables.

    Key Components:

    • State Variables (8 total): Transmembrane potential ($V$), sodium-channel gates ($m, h, j$), calcium-channel gates ($d, f$), potassium gate ($x_1$), and intracellular calcium concentration ($c$).
    • Currents: Sodium ($i_{Na}$), calcium ($i_{Ca}$), time-dependent potassium ($i_{x_1}$), and background potassium ($i_{K_1}$).
    • Mathematical Form: It is modeled as a reaction-diffusion equation: $$\frac{\partial V}{\partial t} = D \nabla^2 V - \frac {I_{\text{ion}}} {C_m}$$ where $V$ is potential, $D$ is the diffusion scalar, $I_{\text{ion}}$ is the sum of transmembrane currents, and $C_m$ is membrane capacitance.
  3. Use DiffEqCallbacks.jl callback APIs

    master

    DiffEqCallbacks.jl provides a variety of pre-built callbacks for SciML differential equation solvers. The available callback types include:

    • Manifold Projection Callbacks: For projecting solutions back onto a manifold.
    • Saving Callbacks: For saving state or specific values during integration (e.g., SavingCallback, SavedValues).
    • Domain Callbacks: For enforcing constraints on the solution domain (e.g., PositiveDomain, GeneralDomain).
    • Stepping Callbacks: For controlling step size or executing functions at specific steps (e.g., StepsizeLimiter, FunctionCallingCallback).
    • Termination Callbacks: For stopping the solver when specific conditions are met (e.g., TerminateSteadyState).
    • Iterative Callbacks: For logic that repeats or occurs periodically (e.g., IterativeCallback, PeriodicCallback).
    • Preset Time Callbacks: For triggering events at specific time points (e.g., PresetTimeCallback).
    • AutoAbstol: For automatic absolute tolerance adjustment.
  4. Understand the purpose of DiffEqDocs.jl

    master

    DiffEqDocs.jl is a component package within the DifferentialEquations ecosystem. It does not contain the solvers or the mathematical logic itself; instead, it serves as the repository for the documentation of the common user interface used across the SciML ecosystem.

    If you are looking to perform differential equation solving, parameter estimation, or sensitivity analysis, you should use DifferentialEquations.jl rather than this package directly.

  5. Use the DiffEqCallbacks.jl library with DifferentialEquations.jl

    master
    DiffEqCallbacks.jl provides a collection of callback functions designed to be used with any component solver that implements the standard callback interface. These callbacks are specifically intended for use with DifferentialEquations.jl to monitor, record, or modify the state of a simulation during integration (e.g., for logging, event handling, or adaptive stepping).
  6. The DifferentialEquations.jl workflow

    master

    The standard workflow for using the package follows three main stages:

    1. Define a problem: Specify the differential equation, initial conditions, and time interval using a problem type (e.g., ODEProblem).
    2. Solve the problem: Use the solve function to compute the solution using a specific algorithm.
    3. Analyze the output: Use the resulting solution object for interpolation, plotting, or further analysis.
  7. Use Mass Matrix solvers from OrdinaryDiffEq.jl

    master

    These methods require the DAE to be specified as an ODEProblem in mass matrix form.

    Important Note on Interpolation: Standard Hermite interpolation used by ODE methods falls back to linear interpolation for differential variables. However, if the mass matrix is non-diagonal, Hermite interpolation has no fallback and will result in an error.

    Sublibrary Mapping (v8): To use specific solvers, you may need to import them from their respective sublibraries:

    • Rosenbrock / Rosenbrock-W: OrdinaryDiffEqRosenbrock
    • FIRK (RadauIIA5): OrdinaryDiffEqFIRK
    • SDIRK (ImplicitEuler, ImplicitMidpoint, Trapezoid): OrdinaryDiffEqSDIRK
    • Multistep (QNDF, FBDF, etc.): OrdinaryDiffEqBDF
  8. Configure DAE initialization schemes

    master

    For all OrdinaryDiffEq.jl methods, you can control how initial conditions are handled using the initializealg keyword argument. This is particularly important for Differential-Algebraic Equations (DAEs) to ensure consistency between differential and algebraic variables.

    Available schemes:

    • SciMLBase.CheckInit: Validates that initial conditions satisfy the equation. If they do not, it throws an error. This avoids nonlinear solving and prevents the solver from modifying your provided initial conditions.
    • OrdinaryDiffEqNonlinearSolve.BrownFullBasicInit: Suitable for Index-1 DAEs (implicit or semi-explicit in mass matrix form). It keeps differential variables constant. Note: Requires providing du0 when used on a DAEProblem.
    • OrdinaryDiffEqNonlinearSolve.ShampineCollocationInit: Suitable for Index-1 DAEs (implicit or semi-explicit in mass matrix form). Unlike Brown, this method allows both differential and algebraic variables to change during initialization.
    • SciMLBase.NoInit: Explicitly disables DAE initialization.
    # Example usage pattern
    prob = DAEProblem(f, du0, u0, tspan)
    solve(prob, method, initializealg=SciMLBase.CheckInit)
  9. Choose between DynamicSS and SSRootfind for steady state problems

    master

    When solving steady state problems, you can choose between two primary approaches provided by SteadyStateDiffEq.jl:

    1. DynamicSS: Uses an ODE solver to integrate the system until it reaches equilibrium. This is recommended if you suspect there are multiple steady states or if you have a poor initial guess. It automatically terminates when the derivative is close to zero.
    2. SSRootfind: Uses a rootfinding algorithm to find the steady state algebraically. This is typically faster but requires a good initial guess. Note: This method is deprecated; it is recommended to use NonlinearSolve.jl instead.

    For DynamicSS, using an adaptive stiff solver like Rodas5 or QNDF is often effective as it allows for large time steps as the system approaches equilibrium.

  10. Use ArrayPartition for heterogeneous arrays in DiffEq

    master

    In DifferentialEquations.jl, native Julia solvers allow you to solve problems using AbstractArray types. ArrayPartition (from RecursiveArrayTools.jl) is used to treat multiple heterogeneous arrays (e.g., arrays with different units, different precision, or different shapes) as a single, unified array. This is useful for modeling systems where different state variables have different physical meanings or properties.

    Key Behaviors

    • Linear Indexing: A[i] indexes through the constituent arrays linearly (first array, then second, etc.).
    • Storage Access: The underlying arrays are stored in the .x field. You can access individual components via A.x[i].
    • Efficiency: Broadcasting operations like f.(A) are type-stable and efficient, making them suitable for use inside high-performance solvers.
    import RecursiveArrayTools: ArrayPartition
    A = ArrayPartition(x::AbstractArray...)
  11. Performance considerations for CUDA-accelerated IMEX solvers

    master

    When using an Implicit/Explicit (IMEX) solver with CUDA acceleration for models like the 2D Beeler-Reuter model, performance is heavily influenced by the communication overhead between the CPU and GPU.

    In current implementations where the explicit portion runs on the GPU but the implicit equations (e.g., those solved by GMRES) are performed on the CPU, the major bottleneck is the data transfer required during every function (f) call.

    To achieve maximum speedup, the entire ODE solver should ideally be compiled to the GPU to minimize CPU-GPU data transfer. Note that current solutions for alleviating these issues are primarily compatible with native Julia solvers rather than Sundials.