NonlinearSolve.jl

repository·master·Indexed 43 days ago

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

Fast, high-performance implementations of root-finding algorithms in Julia. Designed to satisfy the SciML common interface, it provides a comprehensive suite of solvers including first-order (Newton-Raphson, Gauss-Newton, Levenberg-Marquardt), quasi-Newton (Broyden, Klement), spectral residual methods (DF-SANE), and homotopy continuation for polynomial systems. The ecosystem includes specialized components like BracketingNonlinearSolve.jl for interval root finding, SimpleNonlinearSolve.jl for small problems, and NonlinearSolveSciPy.jl for accessing SciPy routines.

Tokens
36.3K
Snippets
107
Records
172
Agent score
52%

What's inside NonlinearSolve.jl

  1. Overview of NonlinearSolveHomotopyContinuation.jl

    master

    NonlinearSolveHomotopyContinuation.jl is a specialized component of the NonlinearSolve.jl ecosystem. It provides a wrapper around HomotopyContinuation.jl to integrate homotopy continuation methods into the SciML common interface.

    This package is specifically designed for finding all roots (or a single root) of fully determined polynomial systems. While it can be used independently, it is intended to be used as part of the broader NonlinearSolve.jl suite for users requiring a comprehensive nonlinear solver toolkit.

  2. Overview of NonlinearSolveQuasiNewton.jl

    master

    NonlinearSolveQuasiNewton.jl is a specialized component of the NonlinearSolve.jl ecosystem. It provides quasi-Newton solvers, including Broyden and Klement methods. These solvers are designed to avoid the computational cost of recomputing the full Jacobian at every iteration by maintaining an approximation of the Jacobian or its inverse.

    While this package can be used independently, it is intended to be used as part of the broader NonlinearSolve.jl suite for a complete nonlinear solving experience.

  3. Overview of NonlinearSolveSpectralMethods.jl

    master

    NonlinearSolveSpectralMethods.jl is a specialized component of the NonlinearSolve.jl ecosystem. It provides Jacobian-free spectral residual methods, such as DF-SANE, designed specifically for solving large-scale nonlinear systems where computing or storing the Jacobian is impractical.

    While this package can be used independently, it is intended to be used as part of the broader NonlinearSolve.jl suite for a complete nonlinear solver experience.

  4. Overview of SCCNonlinearSolve.jl

    master

    SCCNonlinearSolve.jl is a specialized solver designed to solve Strongly Connected Component (SCC) problems. It works by decomposing a system into its nonlinear and linear subproblems and solving them according to their dependency order.

    While it can be used as a standalone package, it is a component of the NonlinearSolve.jl monorepo. For a complete suite of nonlinear solvers, it is recommended to use the main NonlinearSolve.jl package.

  5. Overview of NonlinearSolve.jl

    master

    NonlinearSolve.jl provides a unified interface for nonlinear solving in the Julia ecosystem. It is designed for high performance across various problem scales:

    • Small/Scalar Problems: Optimized for high performance on scalar and statically sized small problems.
    • Large-Scale Systems: Provides options for large-scale systems, including the ability to swap in fast direct or iterative linear solvers.
    • Automatic Differentiation: Supports sparse automatic differentiation for Jacobian construction and Jacobian-vector products.
    • Ecosystem Integration: Interfaces with ModelingToolkit.jl for symbolic modeling and automatic high-performance code generation. It also allows users to easily swap between different solver packages via a unified interface.
  6. Overview of SimpleNonlinearSolve.jl

    master

    SimpleNonlinearSolve.jl provides fast, low-dependency implementations of root-finding algorithms in Julia. It is designed specifically for very small and simple problems where speed is a priority. It is part of the larger SciML ecosystem and implements the common SciML interface, making it compatible with other solvers in the NonlinearSolve.jl ecosystem.

    For more advanced or comprehensive solver sets, use NonlinearSolve.jl instead.

  7. Overview of NonlinearSolveFirstOrder.jl

    master

    NonlinearSolveFirstOrder.jl is a specialized component of the NonlinearSolve.jl monorepo. It focuses on first-order (Jacobian-based) solvers designed for solving nonlinear systems and nonlinear least squares problems.

    Key solver types provided include:

    • Newton-Raphson
    • Gauss-Newton
    • Levenberg-Marquardt
    • Trust-region methods

    While this package can be used independently, it is intended to be used as part of the broader NonlinearSolve.jl suite for a complete nonlinear solver experience.

  8. Compute JVP and VJP with SciMLJacobianOperators.jl

    master

    SciMLJacobianOperators.jl provides a high-level interface to compute Jacobian-Vector Products (JVP) and Vector-Jacobian Products (VJP). It leverages SciMLOperators.jl and DifferentiationInterface.jl to support various autodiff backends.

    It currently supports the following problem types:

    • NonlinearProblem
    • NonlinearLeastSquaresProblem

    To use it, you can construct a JacobianOperator and wrap it in a StatefulJacobianOperator to handle stateful problems (where parameters p or initial values u0 are involved).

    using SciMLJacobianOperators, NonlinearSolve, Enzyme, ForwardDiff
    
    # Define the problem
    f(u, p) = u .* u .- p
    u0 = ones(4)
    p = 2.0
    prob = NonlinearProblem(f, u0, p)
    fu0 = f(u0, p)
    v = ones(4) .* 2
    
    # Construct the operator
    jac_op = JacobianOperator(
        prob, fu0, u0;
        jvp_autodiff = AutoForwardDiff(),
        vjp_autodiff = AutoEnzyme(; mode = Enzyme.Reverse)
    )
    sjac_op = StatefulJacobianOperator(jac_op, u0, p)
    
    # Compute JVP
    sjac_op * v
    
    # Compute VJP
    sjac_op' * v
    
    # Compute JᵀJ * v
    snormal_form = sjac_op' * sjac_op
    snormal_form * v
  9. Use NonlinearSolveSciPy.jl to access SciPy root-finding routines

    master

    NonlinearSolveSciPy.jl provides a Julia interface to SciPy's scipy.optimize root-finding and least-squares routines. It uses PythonCall.jl to bridge the two languages and implements the standard SciML common interface. This allows users to leverage mature Python optimization algorithms within the SciML ecosystem.

    Note that while this package is a standalone component, it is part of the NonlinearSolve.jl monorepo. For the full suite of nonlinear solvers, consider using the main NonlinearSolve.jl package.

    # This package wraps scipy.optimize via PythonCall.jl
    # It follows the SciML common interface
  10. Use nonlinear preconditioning with `precondition`

    master

    Nonlinear preconditioning transforms the residual so that Newton-type methods encounter a 'tamer' function. This is useful for systems with extreme nonlinearities, such as exponential I-V curves in semiconductors.

    Use the precondition keyword to provide a function G(fu, u, p) that acts as a left preconditioner. The solver replaces the residual $f(u, p)$ with the root-equivalent composition $u \to G(f(u, p), u, p)$ for all internal operations, including function evaluations, automatic-differentiation Jacobians, line-search merit functions, and termination criteria.

    Requirements for G:

    • It must be root-preserving: $G(r, u, p) = 0$ if and only if $r = 0$.
    • If you provide manual derivatives (jac, jvp, vjp, etc.) in the NonlinearFunction, they must describe the derivatives of the composed map $G \circ f$, not the raw $f$.

    Note for Least Squares: For NonlinearLeastSquaresProblems, precondition re-weights the objective to $||G(f(u))||^2$. For overdetermined systems, this can be used for residual weighting, but it may change the minimizer.

    using NonlinearSolve
    
    p = (; Is = 1.0e-14, Vt = 0.025, It = 1.0e-2)
    f_diode(v, p) = p.Is * expm1(v / p.Vt) - p.It
    prob = NonlinearProblem(f_diode, 2.0, p)
    
    # Apply asinh compression to tame the exponential residual
    G(fu, u, p) = asinh(fu)
    sol_G = solve(prob, NewtonRaphson(); precondition = G)
  11. Configure nonlinear preconditioning

    master
    The precondition and postcondition options allow you to apply transformations to the problem. For algorithms that transform bounds (lb/ub), you can specify whether a corrector is applied in the original bounded variable coordinates or the transformed variable coordinates using PostconditionSpecifier and PostconditionSpace.