From 0dc27aee042c8d73e42311594ff2c1ce958ff60d Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Tue, 5 Dec 2023 13:35:49 -0500 Subject: [PATCH] Drop deprecated things --- Project.toml | 4 +- docs/Project.toml | 2 +- docs/pages.jl | 1 + docs/src/api/nonlinearsolve.md | 4 +- docs/src/api/simplenonlinearsolve.md | 2 +- docs/src/api/steadystatediffeq.md | 1 + docs/src/basics/TerminationCondition.md | 11 -- docs/src/basics/solve.md | 28 +++++ docs/src/index.md | 24 ++-- docs/src/release_notes.md | 9 ++ docs/src/solvers/BracketingSolvers.md | 16 +-- .../solvers/NonlinearLeastSquaresSolvers.md | 20 ++-- docs/src/solvers/NonlinearSystemSolvers.md | 111 +++++++++--------- docs/src/solvers/SteadyStateSolvers.md | 17 ++- src/NonlinearSolve.jl | 4 +- src/broyden.jl | 24 ++-- src/default.jl | 8 +- src/gaussnewton.jl | 5 +- src/klement.jl | 24 ++-- src/lbroyden.jl | 2 +- src/levenberg.jl | 5 +- src/pseudotransient.jl | 6 +- src/raphson.jl | 5 +- src/trustRegion.jl | 10 +- src/utils.jl | 39 ------ test/23_test_problems.jl | 15 +-- test/basictests.jl | 50 ++++---- test/gpu.jl | 4 +- test/matrix_resizing.jl | 4 +- test/polyalgs.jl | 2 +- 30 files changed, 217 insertions(+), 240 deletions(-) create mode 100644 docs/src/release_notes.md diff --git a/Project.toml b/Project.toml index cec099ef5..7b70858dc 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NonlinearSolve" uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" authors = ["SciML"] -version = "2.10.0" +version = "3.0.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -72,7 +72,7 @@ Reexport = "0.2, 1" SafeTestsets = "0.1" SciMLBase = "2.9" SciMLOperators = "0.3" -SimpleNonlinearSolve = "0.1.23" +SimpleNonlinearSolve = "1" SparseArrays = "<0.0.1, 1" SparseDiffTools = "2.14" StaticArrays = "1" diff --git a/docs/Project.toml b/docs/Project.toml index d4050deb6..f81157cd7 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -30,7 +30,7 @@ NonlinearSolve = "1, 2" NonlinearSolveMINPACK = "0.1" SciMLBase = "2.4" SciMLNLSolve = "0.1" -SimpleNonlinearSolve = "0.1.5" +SimpleNonlinearSolve = "1" StaticArrays = "1" SteadyStateDiffEq = "1.10, 2" Sundials = "4.11" diff --git a/docs/pages.jl b/docs/pages.jl index bea06e3fa..21105d9eb 100644 --- a/docs/pages.jl +++ b/docs/pages.jl @@ -25,4 +25,5 @@ pages = ["index.md", "api/nlsolve.md", "api/sundials.md", "api/steadystatediffeq.md"], + "Release Notes" => "release_notes.md", ] diff --git a/docs/src/api/nonlinearsolve.md b/docs/src/api/nonlinearsolve.md index 3e6009017..0eebda2b4 100644 --- a/docs/src/api/nonlinearsolve.md +++ b/docs/src/api/nonlinearsolve.md @@ -9,8 +9,8 @@ NewtonRaphson TrustRegion PseudoTransient DFSane -GeneralBroyden -GeneralKlement +Broyden +Klement ``` ## Polyalgorithms diff --git a/docs/src/api/simplenonlinearsolve.md b/docs/src/api/simplenonlinearsolve.md index e71aacc1a..7b5a6ca6f 100644 --- a/docs/src/api/simplenonlinearsolve.md +++ b/docs/src/api/simplenonlinearsolve.md @@ -18,7 +18,7 @@ Brent ### General Methods -These methods are suited for any general nonlinear root-finding problem , i.e. `NonlinearProblem`. +These methods are suited for any general nonlinear root-finding problem, i.e. `NonlinearProblem`. ```@docs SimpleNewtonRaphson diff --git a/docs/src/api/steadystatediffeq.md b/docs/src/api/steadystatediffeq.md index 79499aec0..3681ce9dd 100644 --- a/docs/src/api/steadystatediffeq.md +++ b/docs/src/api/steadystatediffeq.md @@ -17,4 +17,5 @@ These methods can be used independently of the rest of NonlinearSolve.jl ```@docs DynamicSS +SSRootfind ``` diff --git a/docs/src/basics/TerminationCondition.md b/docs/src/basics/TerminationCondition.md index a4ff5272b..5351198ca 100644 --- a/docs/src/basics/TerminationCondition.md +++ b/docs/src/basics/TerminationCondition.md @@ -63,14 +63,3 @@ DiffEqBase.NonlinearSafeTerminationReturnCode.Failure DiffEqBase.NonlinearSafeTerminationReturnCode.PatienceTermination DiffEqBase.NonlinearSafeTerminationReturnCode.ProtectiveTermination ``` - -## [Deprecated] Termination Condition API - -!!! warning - - This is deprecated. Currently only parts of `SimpleNonlinearSolve` uses this API. That - will also be phased out soon! - -```@docs -NLSolveTerminationCondition -``` diff --git a/docs/src/basics/solve.md b/docs/src/basics/solve.md index 8e33ed933..afa091223 100644 --- a/docs/src/basics/solve.md +++ b/docs/src/basics/solve.md @@ -3,3 +3,31 @@ ```@docs solve(prob::SciMLBase.NonlinearProblem, args...; kwargs...) ``` + +## General Controls + +- `alias_u0::Bool`: Whether to alias the initial condition or use a copy. + Defaults to `false`. +- `internal_norm::Function`: The norm used by the solver. Default depends on algorithm + choice. + +## Iteration Controls + +- `maxiters::Int`: The maximum number of iterations to perform. Defaults to `1000`. +- `abstol::Number`: The absolute tolerance. +- `reltol::Number`: The relative tolerance. +- `termination_condition`: Termination Condition from DiffEqBase. Defaults to + `AbsSafeBestTerminationMode()` for `NonlinearSolve.jl` and `AbsTerminateMode()` for + `SimpleNonlinearSolve.jl`. + +## Tracing Controls + +These are exclusively available for native `NonlinearSolve.jl` solvers. + +- `show_trace`: Must be `Val(true)` or `Val(false)`. This controls whether the trace is + displayed to the console. (Defaults to `Val(false)`) +- `trace_level`: Needs to be one of Trace Objects: [`TraceMinimal`](@ref), + [`TraceWithJacobianConditionNumber`](@ref), or [`TraceAll`](@ref). This controls the + level of detail of the trace. (Defaults to `TraceMinimal()`) +- `store_trace`: Must be `Val(true)` or `Val(false)`. This controls whether the trace is + stored in the solution object. (Defaults to `Val(false)`) diff --git a/docs/src/index.md b/docs/src/index.md index 3d7e97890..134328ddc 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -27,19 +27,17 @@ Pkg.add("NonlinearSolve") ## Contributing - - Please refer to the - [SciML ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://github.com/SciML/ColPrac/blob/master/README.md) - for guidance on PRs, issues, and other matters relating to contributing to SciML. - - - See the [SciML Style Guide](https://github.com/SciML/SciMLStyle) for common coding practices and other style decisions. - - There are a few community forums: - - + The #diffeq-bridged and #sciml-bridged channels in the - [Julia Slack](https://julialang.org/slack/) - + The #diffeq-bridged and #sciml-bridged channels in the - [Julia Zulip](https://julialang.zulipchat.com/#narrow/stream/279055-sciml-bridged) - + On the [Julia Discourse forums](https://discourse.julialang.org) - + See also [SciML Community page](https://sciml.ai/community/) +- Please refer to the + [SciML ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://github.com/SciML/ColPrac/blob/master/README.md) + for guidance on PRs, issues, and other matters relating to contributing to SciML. + +- See the [SciML Style Guide](https://github.com/SciML/SciMLStyle) for common coding practices and other style decisions. +- There are a few community forums: + + - The #diffeq-bridged and #sciml-bridged channels in the [Julia Slack](https://julialang.org/slack/) + - The #diffeq-bridged and #sciml-bridged channels in the [Julia Zulip](https://julialang.zulipchat.com/#narrow/stream/279055-sciml-bridged) + - On the [Julia Discourse forums](https://discourse.julialang.org) + - See also [SciML Community page](https://sciml.ai/community/) ## Reproducibility diff --git a/docs/src/release_notes.md b/docs/src/release_notes.md new file mode 100644 index 000000000..829576a7f --- /dev/null +++ b/docs/src/release_notes.md @@ -0,0 +1,9 @@ +# Release Notes + +## Breaking Changes in NonlinearSolve.jl v3 + +1. `GeneralBroyden` and `GeneralKlement` have been renamed to `Broyden` and `Klement` + respectively. +2. Compat for `SimpleNonlinearSolve` has been bumped to `v1`. +3. The old API to specify autodiff via `Val` and chunksize (that was deprecated in v2) has + been removed. diff --git a/docs/src/solvers/BracketingSolvers.md b/docs/src/solvers/BracketingSolvers.md index 37184fbfe..cc3bd031a 100644 --- a/docs/src/solvers/BracketingSolvers.md +++ b/docs/src/solvers/BracketingSolvers.md @@ -2,13 +2,15 @@ `solve(prob::IntervalNonlinearProblem,alg;kwargs)` -Solves for ``f(t)=0`` in the problem defined by `prob` using the algorithm -`alg`. If no algorithm is given, a default algorithm will be chosen. +Solves for ``f(t) = 0`` in the problem defined by `prob` using the algorithm `alg`. If no +algorithm is given, a default algorithm will be chosen. ## Recommended Methods `ITP()` is the recommended method for the scalar interval root-finding problems. It is particularly well-suited for cases where the function is smooth and well-behaved; and achieved superlinear convergence while retaining the optimal worst-case performance of the Bisection method. For more details, consult the detailed solver API docs. + `Ridder` is a hybrid method that uses the value of function at the midpoint of the interval to perform an exponential interpolation to the root. This gives a fast convergence with a guaranteed convergence of at most twice the number of iterations as the bisection method. + `Brent` is a combination of the bisection method, the secant method and inverse quadratic interpolation. At every iteration, Brent's method decides which method out of these three is likely to do best, and proceeds by doing a step according to that method. This gives a robust and fast method, which therefore enjoys considerable popularity. ## Full List of Methods @@ -18,8 +20,8 @@ Solves for ``f(t)=0`` in the problem defined by `prob` using the algorithm These methods are automatically included as part of NonlinearSolve.jl. Though, one can use SimpleNonlinearSolve.jl directly to decrease the dependencies and improve load time. - - `ITP`: A non-allocating ITP (Interpolate, Truncate & Project) method - - `Falsi`: A non-allocating regula falsi method - - `Bisection`: A common bisection method - - `Ridder`: A non-allocating Ridder method - - `Brent`: A non-allocating Brent method +- `ITP`: A non-allocating ITP (Interpolate, Truncate & Project) method +- `Falsi`: A non-allocating regula falsi method +- `Bisection`: A common bisection method +- `Ridder`: A non-allocating Ridder method +- `Brent`: A non-allocating Brent method diff --git a/docs/src/solvers/NonlinearLeastSquaresSolvers.md b/docs/src/solvers/NonlinearLeastSquaresSolvers.md index 1690671d9..588e21a84 100644 --- a/docs/src/solvers/NonlinearLeastSquaresSolvers.md +++ b/docs/src/solvers/NonlinearLeastSquaresSolvers.md @@ -14,13 +14,13 @@ algorithm (`LevenbergMarquardt`). ## Full List of Methods - - `LevenbergMarquardt()`: An advanced Levenberg-Marquardt implementation with the - improvements suggested in the [paper](https://arxiv.org/abs/1201.5885) "Improvements to - the Levenberg-Marquardt algorithm for nonlinear least-squares minimization". Designed for - large-scale and numerically-difficult nonlinear systems. - - `GaussNewton()`: An advanced GaussNewton implementation with support for efficient - handling of sparse matrices via colored automatic differentiation and preconditioned - linear solvers. Designed for large-scale and numerically-difficult nonlinear least squares - problems. - - `SimpleNewtonRaphson()`: Simple Gauss Newton Implementation with `QRFactorization` to - solve a linear least squares problem at each step! +- `LevenbergMarquardt()`: An advanced Levenberg-Marquardt implementation with the + improvements suggested in the [paper](https://arxiv.org/abs/1201.5885) "Improvements to + the Levenberg-Marquardt algorithm for nonlinear least-squares minimization". Designed for + large-scale and numerically-difficult nonlinear systems. +- `GaussNewton()`: An advanced GaussNewton implementation with support for efficient + handling of sparse matrices via colored automatic differentiation and preconditioned + linear solvers. Designed for large-scale and numerically-difficult nonlinear least squares + problems. +- `SimpleGaussNewton()`: Simple Gauss Newton Implementation with `QRFactorization` to + solve a linear least squares problem at each step! diff --git a/docs/src/solvers/NonlinearSystemSolvers.md b/docs/src/solvers/NonlinearSystemSolvers.md index 31e820083..15a7d8d5e 100644 --- a/docs/src/solvers/NonlinearSystemSolvers.md +++ b/docs/src/solvers/NonlinearSystemSolvers.md @@ -47,34 +47,34 @@ linear solver, automatic differentiation, abstract array types, GPU, sparse/structured matrix support, etc. These methods support the largest set of types and features, but have a bit of overhead on very small problems. - - `NewtonRaphson()`:A Newton-Raphson method with swappable nonlinear solvers and autodiff - methods for high performance on large and sparse systems. - - `TrustRegion()`: A Newton Trust Region dogleg method with swappable nonlinear solvers and - autodiff methods for high performance on large and sparse systems. - - `LevenbergMarquardt()`: An advanced Levenberg-Marquardt implementation with the - improvements suggested in the [paper](https://arxiv.org/abs/1201.5885) "Improvements to - the Levenberg-Marquardt algorithm for nonlinear least-squares minimization". Designed for - large-scale and numerically-difficult nonlinear systems. - - `PseudoTransient()`: A pseudo-transient method which mixes the stability of Euler-type - stepping with the convergence speed of a Newton method. Good for highly unstable - systems. - - `RobustMultiNewton()`: A polyalgorithm that mixes highly robust methods (line searches and - trust regions) in order to be as robust as possible for difficult problems. If this method - fails to converge, then one can be pretty certain that most (all?) other choices would - likely fail. - - `FastShortcutNonlinearPolyalg()`: The default method. A polyalgorithm that mixes fast methods - with fallbacks to robust methods to allow for solving easy problems quickly without sacrificing - robustness on the hard problems. - - `GeneralBroyden()`: Generalization of Broyden's Quasi-Newton Method with Line Search and - Automatic Jacobian Resetting. This is a fast method but unstable when the condition number of - the Jacobian matrix is sufficiently large. - - `GeneralKlement()`: Generalization of Klement's Quasi-Newton Method with Line Search and - Automatic Jacobian Resetting. This is a fast method but unstable when the condition number of - the Jacobian matrix is sufficiently large. - - `LimitedMemoryBroyden()`: An advanced version of `LBroyden` which uses a limited memory - Broyden method. This is a fast method but unstable when the condition number of - the Jacobian matrix is sufficiently large. It is recommended to use `GeneralBroyden` or - `GeneralKlement` instead unless the memory usage is a concern. +- `NewtonRaphson()`:A Newton-Raphson method with swappable nonlinear solvers and autodiff + methods for high performance on large and sparse systems. +- `TrustRegion()`: A Newton Trust Region dogleg method with swappable nonlinear solvers and + autodiff methods for high performance on large and sparse systems. +- `LevenbergMarquardt()`: An advanced Levenberg-Marquardt implementation with the + improvements suggested in the [paper](https://arxiv.org/abs/1201.5885) "Improvements to + the Levenberg-Marquardt algorithm for nonlinear least-squares minimization". Designed for + large-scale and numerically-difficult nonlinear systems. +- `PseudoTransient()`: A pseudo-transient method which mixes the stability of Euler-type + stepping with the convergence speed of a Newton method. Good for highly unstable + systems. +- `RobustMultiNewton()`: A polyalgorithm that mixes highly robust methods (line searches and + trust regions) in order to be as robust as possible for difficult problems. If this method + fails to converge, then one can be pretty certain that most (all?) other choices would + likely fail. +- `FastShortcutNonlinearPolyalg()`: The default method. A polyalgorithm that mixes fast methods + with fallbacks to robust methods to allow for solving easy problems quickly without sacrificing + robustness on the hard problems. +- `Broyden()`: Generalization of Broyden's Quasi-Newton Method with Line Search and + Automatic Jacobian Resetting. This is a fast method but unstable when the condition number of + the Jacobian matrix is sufficiently large. +- `Klement()`: Generalization of Klement's Quasi-Newton Method with Line Search and + Automatic Jacobian Resetting. This is a fast method but unstable when the condition number of + the Jacobian matrix is sufficiently large. +- `LimitedMemoryBroyden()`: An advanced version of `LBroyden` which uses a limited memory + Broyden method. This is a fast method but unstable when the condition number of + the Jacobian matrix is sufficiently large. It is recommended to use `Broyden` or + `Klement` instead unless the memory usage is a concern. ### SimpleNonlinearSolve.jl @@ -82,21 +82,21 @@ These methods are included with NonlinearSolve.jl by default, though SimpleNonli can be used directly to reduce dependencies and improve load times. SimpleNonlinearSolve.jl's methods excel at small problems and problems defined with static arrays. - - `SimpleNewtonRaphson()`: A simplified implementation of the Newton-Raphson method. - - `Broyden()`: The classic Broyden's quasi-Newton method. - - `LBroyden()`: A low-memory Broyden implementation, similar to L-BFGS. This method is - common in machine learning contexts but is known to be unstable in comparison to many - other choices. - - `Klement()`: A quasi-Newton method due to Klement. It's supposed to be more efficient - than Broyden's method, and it seems to be in the cases that have been tried, but more - benchmarking is required. - - `SimpleTrustRegion()`: A dogleg trust-region Newton method. Improved globalizing stability - for more robust fitting over basic Newton methods, though potentially with a cost. - - `SimpleDFSane()`: A low-overhead implementation of the df-sane method for solving - large-scale nonlinear systems of equations. - - `SimpleHalley()`: A low-overhead implementation of the Halley method. This is a higher order - method and thus can converge faster to low tolerances than a Newton method. Requires higher - order derivatives, so best used when automatic differentiation is available. +- `SimpleNewtonRaphson()`: A simplified implementation of the Newton-Raphson method. +- `SimpleBroyden()`: The classic Broyden's quasi-Newton method. +- `SimpleLimitedMemoryBroyden()`: A low-memory Broyden implementation, similar to L-BFGS. This method is + common in machine learning contexts but is known to be unstable in comparison to many + other choices. +- `SimpleKlement()`: A quasi-Newton method due to Klement. It's supposed to be more efficient + than Broyden's method, and it seems to be in the cases that have been tried, but more + benchmarking is required. +- `SimpleTrustRegion()`: A dogleg trust-region Newton method. Improved globalizing stability + for more robust fitting over basic Newton methods, though potentially with a cost. +- `SimpleDFSane()`: A low-overhead implementation of the df-sane method for solving + large-scale nonlinear systems of equations. +- `SimpleHalley()`: A low-overhead implementation of the Halley method. This is a higher order + method and thus can converge faster to low tolerances than a Newton method. Requires higher + order derivatives, so best used when automatic differentiation is available. !!! note @@ -110,34 +110,35 @@ SteadyStateDiffEq.jl uses ODE solvers to iteratively approach the steady state. very stable method for solving nonlinear systems, though often more computationally expensive than direct methods. - - `DynamicSS()` : Uses an ODE solver to find the steady state. Automatically - terminates when close to the steady state. +- `DynamicSS()`: Uses an ODE solver to find the steady state. Automatically terminates when + close to the steady state. +- `SSRootfind()`: Uses a NonlinearSolve compatible solver to find the steady state. ### SciMLNLSolve.jl This is a wrapper package for importing solvers from NLsolve.jl into the SciML interface. - - `NLSolveJL()`: A wrapper for [NLsolve.jl](https://github.com/JuliaNLSolvers/NLsolve.jl) +- `NLSolveJL()`: A wrapper for [NLsolve.jl](https://github.com/JuliaNLSolvers/NLsolve.jl) Submethod choices for this algorithm include: - - `:anderson`: Anderson-accelerated fixed-point iteration - - `:newton`: Classical Newton method with an optional line search - - `:trust_region`: Trust region Newton method (the default choice) +- `:anderson`: Anderson-accelerated fixed-point iteration +- `:newton`: Classical Newton method with an optional line search +- `:trust_region`: Trust region Newton method (the default choice) ### MINPACK.jl MINPACK.jl methods are good for medium-sized nonlinear solves. It does not scale due to the lack of sparse Jacobian support, though the methods are very robust and stable. - - `CMINPACK()`: A wrapper for using the classic MINPACK method through [MINPACK.jl](https://github.com/sglyon/MINPACK.jl) +- `CMINPACK()`: A wrapper for using the classic MINPACK method through [MINPACK.jl](https://github.com/sglyon/MINPACK.jl) Submethod choices for this algorithm include: - - `:hybr`: Modified version of Powell's algorithm. - - `:lm`: Levenberg-Marquardt. - - `:lmdif`: Advanced Levenberg-Marquardt - - `:hybrd`: Advanced modified version of Powell's algorithm +- `:hybr`: Modified version of Powell's algorithm. +- `:lm`: Levenberg-Marquardt. +- `:lmdif`: Advanced Levenberg-Marquardt +- `:hybrd`: Advanced modified version of Powell's algorithm ### Sundials.jl @@ -145,4 +146,4 @@ Sundials.jl are a classic set of C/Fortran methods which are known for good scal Newton-Krylov form. However, KINSOL is known to be less stable than some other implementations, as it has no line search or globalizer (trust region). - - `KINSOL()`: The KINSOL method of the SUNDIALS C library +- `KINSOL()`: The KINSOL method of the SUNDIALS C library diff --git a/docs/src/solvers/SteadyStateSolvers.md b/docs/src/solvers/SteadyStateSolvers.md index af7b2bc06..a3818a6d8 100644 --- a/docs/src/solvers/SteadyStateSolvers.md +++ b/docs/src/solvers/SteadyStateSolvers.md @@ -36,16 +36,13 @@ SteadyStateDiffEq.jl uses ODE solvers to iteratively approach the steady state. very stable method for solving nonlinear systems, though often computationally more expensive than direct methods. - - `DynamicSS` : Uses an ODE solver to find the steady state. Automatically - terminates when close to the steady state. - `DynamicSS(alg;abstol=1e-8,reltol=1e-6,tspan=Inf)` requires that an - ODE algorithm is given as the first argument. The absolute and - relative tolerances specify the termination conditions on the - derivative's closeness to zero. This internally uses the - `TerminateSteadyState` callback from the Callback Library. The - simulated time, for which the ODE is solved, can be limited by - `tspan`. If `tspan` is a number, it is equivalent to passing - `(zero(tspan), tspan)`. +- `DynamicSS` : Uses an ODE solver to find the steady state. Automatically terminates when + close to the steady state. `DynamicSS(alg; abstol=1e-8, reltol=1e-6, tspan=Inf)` requires + that an ODE algorithm is given as the first argument. The absolute and relative tolerances + specify the termination conditions on the derivative's closeness to zero. This internally + uses the `TerminateSteadyState` callback from the Callback Library. The simulated time, + for which the ODE is solved, can be limited by `tspan`. If `tspan` is a number, it is + equivalent to passing `(zero(tspan), tspan)`. Example usage: diff --git a/src/NonlinearSolve.jl b/src/NonlinearSolve.jl index 3cdfa6c43..8bdfcedf5 100644 --- a/src/NonlinearSolve.jl +++ b/src/NonlinearSolve.jl @@ -195,7 +195,7 @@ include("default.jl") end nls_algs = (NewtonRaphson(), TrustRegion(), LevenbergMarquardt(), PseudoTransient(), - GeneralBroyden(), GeneralKlement(), DFSane(), nothing) + Broyden(), Klement(), DFSane(), nothing) probs_nlls = NonlinearLeastSquaresProblem[] nlfuncs = ((NonlinearFunction{false}((u, p) -> (u .^ 2 .- p)[1:1]), [0.1, 0.0]), @@ -235,7 +235,7 @@ end export RadiusUpdateSchemes export NewtonRaphson, TrustRegion, LevenbergMarquardt, DFSane, GaussNewton, PseudoTransient, - GeneralBroyden, GeneralKlement, LimitedMemoryBroyden + Broyden, Klement, LimitedMemoryBroyden export LeastSquaresOptimJL, FastLevenbergMarquardtJL export NonlinearSolvePolyAlgorithm, RobustMultiNewton, FastShortcutNonlinearPolyalg, FastShortcutNLLSPolyalg diff --git a/src/broyden.jl b/src/broyden.jl index ffacfcb9a..f2f1fa1b0 100644 --- a/src/broyden.jl +++ b/src/broyden.jl @@ -1,6 +1,6 @@ # Sadly `Broyden` is taken up by SimpleNonlinearSolve.jl """ - GeneralBroyden(; max_resets = 100, linesearch = nothing, reset_tolerance = nothing, + Broyden(; max_resets = 100, linesearch = nothing, reset_tolerance = nothing, init_jacobian::Val = Val(:identity), autodiff = nothing, alpha = nothing) An implementation of `Broyden` with resetting and line search. @@ -40,7 +40,7 @@ An implementation of `Broyden` with resetting and line search. SciPy's implementation of Broyden's method. This algorithm may be useful for specific problems, but whether it will work may depend strongly on the problem. """ -@concrete struct GeneralBroyden{IJ, UR, CJ, AD} <: AbstractNewtonAlgorithm{CJ, AD} +@concrete struct Broyden{IJ, UR, CJ, AD} <: AbstractNewtonAlgorithm{CJ, AD} ad::AD max_resets::Int reset_tolerance @@ -48,7 +48,7 @@ An implementation of `Broyden` with resetting and line search. alpha end -function __alg_print_modifiers(alg::GeneralBroyden{IJ, UR}) where {IJ, UR} +function __alg_print_modifiers(alg::Broyden{IJ, UR}) where {IJ, UR} modifiers = String[] IJ !== :identity && push!(modifiers, "init_jacobian = :$(IJ)") UR !== :good_broyden && push!(modifiers, "update_rule = :$(UR)") @@ -56,12 +56,12 @@ function __alg_print_modifiers(alg::GeneralBroyden{IJ, UR}) where {IJ, UR} return modifiers end -function set_ad(alg::GeneralBroyden{IJ, UR, CJ}, ad) where {IJ, UR, CJ} - return GeneralBroyden{IJ, UR, CJ}(ad, alg.max_resets, alg.reset_tolerance, +function set_ad(alg::Broyden{IJ, UR, CJ}, ad) where {IJ, UR, CJ} + return Broyden{IJ, UR, CJ}(ad, alg.max_resets, alg.reset_tolerance, alg.linesearch, alg.alpha) end -function GeneralBroyden(; max_resets = 100, linesearch = nothing, reset_tolerance = nothing, +function Broyden(; max_resets = 100, linesearch = nothing, reset_tolerance = nothing, init_jacobian::Val = Val(:identity), autodiff = nothing, alpha = nothing, update_rule = Val(:good_broyden)) UR = _unwrap_val(update_rule) @@ -70,11 +70,11 @@ function GeneralBroyden(; max_resets = 100, linesearch = nothing, reset_toleranc @assert IJ ∈ (:identity, :true_jacobian) linesearch = linesearch isa LineSearch ? linesearch : LineSearch(; method = linesearch) CJ = IJ === :true_jacobian - return GeneralBroyden{IJ, UR, CJ}(autodiff, max_resets, reset_tolerance, linesearch, + return Broyden{IJ, UR, CJ}(autodiff, max_resets, reset_tolerance, linesearch, alpha) end -@concrete mutable struct GeneralBroydenCache{iip, IJ, UR} <: +@concrete mutable struct BroydenCache{iip, IJ, UR} <: AbstractNonlinearSolveCache{iip} f alg @@ -108,7 +108,7 @@ end trace end -function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg_::GeneralBroyden{IJ, UR}, +function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg_::Broyden{IJ, UR}, args...; alias_u0 = false, maxiters = 1000, abstol = nothing, reltol = nothing, termination_condition = nothing, internalnorm::F = DEFAULT_NORM, kwargs...) where {uType, iip, F, IJ, UR} @@ -144,14 +144,14 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg_::GeneralBroyd trace = init_nonlinearsolve_trace(alg, u, fu, J⁻¹, du; uses_jac_inverse = Val(true), kwargs...) - return GeneralBroydenCache{iip, IJ, UR}(f, alg, u, u_cache, du, fu, fu_cache, dfu, p, + return BroydenCache{iip, IJ, UR}(f, alg, u, u_cache, du, fu, fu_cache, dfu, p, uf, J⁻¹, J⁻¹dfu, inv_alpha, alg.alpha, false, 0, alg.max_resets, maxiters, internalnorm, ReturnCode.Default, abstol, reltol, reset_tolerance, reset_check, jac_cache, prob, NLStats(1, 0, 0, 0, 0), init_linesearch_cache(alg.linesearch, f, u, p, fu, Val(iip)), tc_cache, trace) end -function perform_step!(cache::GeneralBroydenCache{iip, IJ, UR}) where {iip, IJ, UR} +function perform_step!(cache::BroydenCache{iip, IJ, UR}) where {iip, IJ, UR} T = eltype(cache.u) if IJ === :true_jacobian && cache.stats.nsteps == 0 @@ -209,7 +209,7 @@ function perform_step!(cache::GeneralBroydenCache{iip, IJ, UR}) where {iip, IJ, return nothing end -function __reinit_internal!(cache::GeneralBroydenCache; kwargs...) +function __reinit_internal!(cache::BroydenCache; kwargs...) cache.inv_alpha = __initial_inv_alpha(cache.inv_alpha, cache.alpha_initial, cache.u, cache.fu, cache.internalnorm) cache.J⁻¹ = __reinit_identity_jacobian!!(cache.J⁻¹, cache.inv_alpha) diff --git a/src/default.jl b/src/default.jl index 459cf4083..b3f5d99ed 100644 --- a/src/default.jl +++ b/src/default.jl @@ -19,7 +19,7 @@ residual is returned. ```julia using NonlinearSolve -alg = NonlinearSolvePolyAlgorithm((NewtonRaphson(), GeneralBroyden())) +alg = NonlinearSolvePolyAlgorithm((NewtonRaphson(), Broyden())) ``` """ struct NonlinearSolvePolyAlgorithm{pType, N, A} <: AbstractNonlinearSolveAlgorithm @@ -248,9 +248,9 @@ function FastShortcutNonlinearPolyalg(; concrete_jac = nothing, linsolve = nothi TrustRegion(; concrete_jac, linsolve, precs, radius_update_scheme = RadiusUpdateSchemes.Bastin, adkwargs...)) else - algs = (GeneralBroyden(), - GeneralBroyden(; init_jacobian = Val(:true_jacobian)), - GeneralKlement(; linsolve, precs), + algs = (Broyden(), + Broyden(; init_jacobian = Val(:true_jacobian)), + Klement(; linsolve, precs), NewtonRaphson(; concrete_jac, linsolve, precs, adkwargs...), NewtonRaphson(; concrete_jac, linsolve, precs, linesearch = BackTracking(), adkwargs...), diff --git a/src/gaussnewton.jl b/src/gaussnewton.jl index 822b0ffc3..c7e99c912 100644 --- a/src/gaussnewton.jl +++ b/src/gaussnewton.jl @@ -47,10 +47,9 @@ function set_ad(alg::GaussNewton{CJ}, ad) where {CJ} end function GaussNewton(; concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS, - linesearch = nothing, vjp_autodiff = nothing, adkwargs...) - ad = default_adargs_to_adtype(; adkwargs...) + linesearch = nothing, vjp_autodiff = nothing, autodiff = nothing) linesearch = linesearch isa LineSearch ? linesearch : LineSearch(; method = linesearch) - return GaussNewton{_unwrap_val(concrete_jac)}(ad, linsolve, precs, linesearch, + return GaussNewton{_unwrap_val(concrete_jac)}(autodiff, linsolve, precs, linesearch, vjp_autodiff) end diff --git a/src/klement.jl b/src/klement.jl index e98e01f7d..ab88460a1 100644 --- a/src/klement.jl +++ b/src/klement.jl @@ -1,5 +1,5 @@ """ - GeneralKlement(; max_resets = 100, linsolve = nothing, linesearch = nothing, + Klement(; max_resets = 100, linsolve = nothing, linesearch = nothing, precs = DEFAULT_PRECS, alpha = true, init_jacobian::Val = Val(:identity), autodiff = nothing) @@ -38,7 +38,7 @@ solves. It is recommended to use `Broyden` for most problems over this. `nothing` which means that a default is selected according to the problem specification! Valid choices are types from ADTypes.jl. (Used if `init_jacobian = Val(:true_jacobian)`) """ -@concrete struct GeneralKlement{IJ, CJ, AD} <: AbstractNewtonAlgorithm{CJ, AD} +@concrete struct Klement{IJ, CJ, AD} <: AbstractNewtonAlgorithm{CJ, AD} ad::AD max_resets::Int linsolve @@ -47,30 +47,30 @@ solves. It is recommended to use `Broyden` for most problems over this. alpha end -function __alg_print_modifiers(alg::GeneralKlement{IJ}) where {IJ} +function __alg_print_modifiers(alg::Klement{IJ}) where {IJ} modifiers = String[] IJ !== :identity && push!(modifiers, "init_jacobian = :$(IJ)") alg.alpha !== nothing && push!(modifiers, "alpha = $(alg.alpha)") return modifiers end -function set_ad(alg::GeneralKlement{IJ, CJ}, ad) where {IJ, CJ} - return GeneralKlement{IJ, CJ}(ad, alg.max_resets, alg.linsolve, alg.precs, +function set_ad(alg::Klement{IJ, CJ}, ad) where {IJ, CJ} + return Klement{IJ, CJ}(ad, alg.max_resets, alg.linsolve, alg.precs, alg.linesearch, alg.alpha) end -function GeneralKlement(; max_resets::Int = 100, linsolve = nothing, alpha = true, +function Klement(; max_resets::Int = 100, linsolve = nothing, alpha = true, linesearch = nothing, precs = DEFAULT_PRECS, init_jacobian::Val = Val(:identity), autodiff = nothing) IJ = _unwrap_val(init_jacobian) @assert IJ ∈ (:identity, :true_jacobian, :true_jacobian_diagonal) linesearch = linesearch isa LineSearch ? linesearch : LineSearch(; method = linesearch) CJ = IJ !== :identity - return GeneralKlement{IJ, CJ}(autodiff, max_resets, linsolve, precs, linesearch, + return Klement{IJ, CJ}(autodiff, max_resets, linsolve, precs, linesearch, alpha) end -@concrete mutable struct GeneralKlementCache{iip, IJ} <: AbstractNonlinearSolveCache{iip} +@concrete mutable struct KlementCache{iip, IJ} <: AbstractNonlinearSolveCache{iip} f alg u @@ -104,7 +104,7 @@ end trace end -function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg_::GeneralKlement{IJ}, +function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg_::Klement{IJ}, args...; alias_u0 = false, maxiters = 1000, abstol = nothing, reltol = nothing, termination_condition = nothing, internalnorm::F = DEFAULT_NORM, linsolve_kwargs = (;), kwargs...) where {uType, iip, F, IJ} @@ -155,14 +155,14 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg_::GeneralKleme J_cache_2, Jdu_cache = nothing, nothing end - return GeneralKlementCache{iip, IJ}(f, alg, u, u_cache, fu, fu_cache, fu_cache_2, du, p, + return KlementCache{iip, IJ}(f, alg, u, u_cache, fu, fu_cache, fu_cache_2, du, p, uf, linsolve, J, J_cache, J_cache_2, Jdu, Jdu_cache, alpha, alg.alpha, 0, false, maxiters, internalnorm, ReturnCode.Default, abstol, reltol, prob, jac_cache, NLStats(1, 0, 0, 0, 0), init_linesearch_cache(alg.linesearch, f, u, p, fu, Val(iip)), tc_cache, trace) end -function perform_step!(cache::GeneralKlementCache{iip, IJ}) where {iip, IJ} +function perform_step!(cache::KlementCache{iip, IJ}) where {iip, IJ} @unpack linsolve, alg = cache T = eltype(cache.J) @@ -248,7 +248,7 @@ function perform_step!(cache::GeneralKlementCache{iip, IJ}) where {iip, IJ} return nothing end -function __reinit_internal!(cache::GeneralKlementCache; kwargs...) +function __reinit_internal!(cache::KlementCache; kwargs...) cache.alpha = __initial_alpha(cache.alpha, cache.alpha_initial, cache.u, cache.fu, cache.internalnorm) cache.J = __reinit_identity_jacobian!!(cache.J, cache.alpha) diff --git a/src/lbroyden.jl b/src/lbroyden.jl index c4c73e11e..c245b5dc0 100644 --- a/src/lbroyden.jl +++ b/src/lbroyden.jl @@ -76,7 +76,7 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::LimitedMemory if u0 isa Number || length(u0) ≤ η # If u is a number or very small problem then we simply use Broyden return SciMLBase.__init(prob, - GeneralBroyden(; alg.max_resets, alg.reset_tolerance, alg.linesearch), args...; + Broyden(; alg.max_resets, alg.reset_tolerance, alg.linesearch), args...; alias_u0, maxiters, abstol, internalnorm, kwargs...) end u = __maybe_unaliased(u0, alias_u0) diff --git a/src/levenberg.jl b/src/levenberg.jl index 160406f66..305613df2 100644 --- a/src/levenberg.jl +++ b/src/levenberg.jl @@ -102,10 +102,9 @@ function LevenbergMarquardt(; concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS, damping_initial::Real = 1.0, α_geodesic::Real = 0.75, damping_increase_factor::Real = 2.0, damping_decrease_factor::Real = 3.0, finite_diff_step_geodesic::Real = 0.1, b_uphill::Real = 1.0, - min_damping_D::Real = 1e-8, adkwargs...) - ad = default_adargs_to_adtype(; adkwargs...) + min_damping_D::Real = 1e-8, autodiff = nothing) _concrete_jac = ifelse(concrete_jac === nothing, true, concrete_jac) - return LevenbergMarquardt{_unwrap_val(_concrete_jac)}(ad, linsolve, precs, + return LevenbergMarquardt{_unwrap_val(_concrete_jac)}(autodiff, linsolve, precs, damping_initial, damping_increase_factor, damping_decrease_factor, finite_diff_step_geodesic, α_geodesic, b_uphill, min_damping_D) end diff --git a/src/pseudotransient.jl b/src/pseudotransient.jl index 1416cc4b8..7045e38cd 100644 --- a/src/pseudotransient.jl +++ b/src/pseudotransient.jl @@ -46,9 +46,9 @@ function set_ad(alg::PseudoTransient{CJ}, ad) where {CJ} end function PseudoTransient(; concrete_jac = nothing, linsolve = nothing, - precs = DEFAULT_PRECS, alpha_initial = 1e-3, adkwargs...) - ad = default_adargs_to_adtype(; adkwargs...) - return PseudoTransient{_unwrap_val(concrete_jac)}(ad, linsolve, precs, alpha_initial) + precs = DEFAULT_PRECS, alpha_initial = 1e-3, autodiff = nothing) + return PseudoTransient{_unwrap_val(concrete_jac)}(autodiff, linsolve, precs, + alpha_initial) end @concrete mutable struct PseudoTransientCache{iip} <: AbstractNonlinearSolveCache{iip} diff --git a/src/raphson.jl b/src/raphson.jl index 9ba6319aa..0fa918232 100644 --- a/src/raphson.jl +++ b/src/raphson.jl @@ -42,10 +42,9 @@ function set_ad(alg::NewtonRaphson{CJ}, ad) where {CJ} end function NewtonRaphson(; concrete_jac = nothing, linsolve = nothing, linesearch = nothing, - precs = DEFAULT_PRECS, adkwargs...) - ad = default_adargs_to_adtype(; adkwargs...) + precs = DEFAULT_PRECS, autodiff = nothing) linesearch = linesearch isa LineSearch ? linesearch : LineSearch(; method = linesearch) - return NewtonRaphson{_unwrap_val(concrete_jac)}(ad, linsolve, precs, linesearch) + return NewtonRaphson{_unwrap_val(concrete_jac)}(autodiff, linsolve, precs, linesearch) end @concrete mutable struct NewtonRaphsonCache{iip} <: AbstractNonlinearSolveCache{iip} diff --git a/src/trustRegion.jl b/src/trustRegion.jl index cab250223..3f41733b7 100644 --- a/src/trustRegion.jl +++ b/src/trustRegion.jl @@ -175,11 +175,11 @@ function TrustRegion(; concrete_jac = nothing, linsolve = nothing, precs = DEFAU step_threshold::Real = 1 // 10000, shrink_threshold::Real = 1 // 4, expand_threshold::Real = 3 // 4, shrink_factor::Real = 1 // 4, expand_factor::Real = 2 // 1, max_shrink_times::Int = 32, vjp_autodiff = nothing, - adkwargs...) - ad = default_adargs_to_adtype(; adkwargs...) - return TrustRegion{_unwrap_val(concrete_jac)}(ad, linsolve, precs, radius_update_scheme, - max_trust_radius, initial_trust_radius, step_threshold, shrink_threshold, - expand_threshold, shrink_factor, expand_factor, max_shrink_times, vjp_autodiff) + autodiff = nothing) + return TrustRegion{_unwrap_val(concrete_jac)}(autodiff, linsolve, precs, + radius_update_scheme, max_trust_radius, initial_trust_radius, step_threshold, + shrink_threshold, expand_threshold, shrink_factor, expand_factor, max_shrink_times, + vjp_autodiff) end @concrete mutable struct TrustRegionCache{iip} <: AbstractNonlinearSolveCache{iip} diff --git a/src/utils.jl b/src/utils.jl index 1b341fd69..a7554b519 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -25,45 +25,6 @@ function ForwardDiff.checktag(::Type{<:ForwardDiff.Tag{<:NonlinearSolveTag, <:T} return true end -""" - default_adargs_to_adtype(; chunk_size = Val{0}(), autodiff = Val{true}(), - standardtag = Val{true}(), diff_type = Val{:forward}) - -Construct the AD type from the arguments. This is mostly needed for compatibility with older -code. - -!!! warning - - `chunk_size`, `standardtag`, `diff_type`, and `autodiff::Union{Val, Bool}` are - deprecated and will be removed in v3. Update your code to directly specify - `autodiff=`. -""" -function default_adargs_to_adtype(; chunk_size = missing, autodiff = nothing, - standardtag = missing, diff_type = missing) - # If using the new API short circuit - autodiff === nothing && return nothing - autodiff isa ADTypes.AbstractADType && return autodiff - - # Deprecate the old version - if chunk_size !== missing || standardtag !== missing || diff_type !== missing || - autodiff !== missing - Base.depwarn("`chunk_size`, `standardtag`, `diff_type`, \ - `autodiff::Union{Val, Bool}` kwargs have been deprecated and will be removed \ - in v3. Update your code to directly specify autodiff=", - :default_adargs_to_adtype) - end - chunk_size === missing && (chunk_size = Val{0}()) - standardtag === missing && (standardtag = Val{true}()) - diff_type === missing && (diff_type = Val{:forward}()) - autodiff === missing && (autodiff = Val{true}()) - - ad = _unwrap_val(autodiff) - # We don't really know the typeof the input yet, so we can't use the correct tag! - ad && - return AutoForwardDiff{_unwrap_val(chunk_size), NonlinearSolveTag}(NonlinearSolveTag()) - return AutoFiniteDiff(; fdtype = diff_type) -end - """ value_derivative(f, x) diff --git a/test/23_test_problems.jl b/test/23_test_problems.jl index 689b6266c..7bec60627 100644 --- a/test/23_test_problems.jl +++ b/test/23_test_problems.jl @@ -90,11 +90,9 @@ end end @testset "GeneralBroyden 23 Test Problems" begin - alg_ops = (GeneralBroyden(), - GeneralBroyden(; init_jacobian = Val(:true_jacobian)), - GeneralBroyden(; update_rule = Val(:bad_broyden)), - GeneralBroyden(; init_jacobian = Val(:true_jacobian), - update_rule = Val(:bad_broyden))) + alg_ops = (Broyden(), Broyden(; init_jacobian = Val(:true_jacobian)), + Broyden(; update_rule = Val(:bad_broyden)), + Broyden(; init_jacobian = Val(:true_jacobian), update_rule = Val(:bad_broyden))) broken_tests = Dict(alg => Int[] for alg in alg_ops) broken_tests[alg_ops[1]] = [1, 5, 6, 11] @@ -111,10 +109,9 @@ end test_on_library(problems, dicts, alg_ops, broken_tests; skip_tests) end -@testset "GeneralKlement 23 Test Problems" begin - alg_ops = (GeneralKlement(), - GeneralKlement(; init_jacobian = Val(:true_jacobian)), - GeneralKlement(; init_jacobian = Val(:true_jacobian_diagonal))) +@testset "Klement 23 Test Problems" begin + alg_ops = (Klement(), Klement(; init_jacobian = Val(:true_jacobian)), + Klement(; init_jacobian = Val(:true_jacobian_diagonal))) broken_tests = Dict(alg => Int[] for alg in alg_ops) broken_tests[alg_ops[1]] = [1, 2, 4, 5, 6, 11, 22] diff --git a/test/basictests.jl b/test/basictests.jl index 869690298..19ceff89a 100644 --- a/test/basictests.jl +++ b/test/basictests.jl @@ -124,9 +124,8 @@ const TERMINATION_CONDITIONS = [ @test nlprob_iterator_interface(quadratic_f, p, Val(false)) ≈ sqrt.(p) @test nlprob_iterator_interface(quadratic_f!, p, Val(true)) ≈ sqrt.(p) - @testset "ADType: $(autodiff) u0: $(_nameof(u0))" for autodiff in (false, true, - AutoSparseForwardDiff(), AutoSparseFiniteDiff(), AutoZygote(), - AutoSparseZygote(), AutoSparseEnzyme()), u0 in (1.0, [1.0, 1.0]) + @testset "ADType: $(autodiff) u0: $(_nameof(u0))" for autodiff in (AutoSparseForwardDiff(), + AutoSparseFiniteDiff(), AutoZygote(), AutoSparseZygote(), AutoSparseEnzyme()), u0 in (1.0, [1.0, 1.0]) probN = NonlinearProblem(quadratic_f, u0, 2.0) @test all(solve(probN, NewtonRaphson(; autodiff)).u .≈ sqrt(2.0)) end @@ -244,9 +243,8 @@ end @test nlprob_iterator_interface(quadratic_f, p, Val(false)) ≈ sqrt.(p) @test nlprob_iterator_interface(quadratic_f!, p, Val(true)) ≈ sqrt.(p) - @testset "ADType: $(autodiff) u0: $(_nameof(u0)) radius_update_scheme: $(radius_update_scheme)" for autodiff in (false, - true, AutoSparseForwardDiff(), AutoSparseFiniteDiff(), AutoZygote(), - AutoSparseZygote(), AutoSparseEnzyme()), u0 in (1.0, [1.0, 1.0]), + @testset "ADType: $(autodiff) u0: $(_nameof(u0)) radius_update_scheme: $(radius_update_scheme)" for autodiff in (AutoSparseForwardDiff(), + AutoSparseFiniteDiff(), AutoZygote(), AutoSparseZygote(), AutoSparseEnzyme()), u0 in (1.0, [1.0, 1.0]), radius_update_scheme in radius_update_schemes probN = NonlinearProblem(quadratic_f, u0, 2.0) @@ -380,9 +378,8 @@ end @test ForwardDiff.jacobian(p -> [benchmark_nlsolve_oop(quadratic_f2, 0.5, p).u], p) ≈ ForwardDiff.jacobian(t, p) - @testset "ADType: $(autodiff) u0: $(_nameof(u0))" for autodiff in (false, true, - AutoSparseForwardDiff(), AutoSparseFiniteDiff(), AutoZygote(), - AutoSparseZygote(), AutoSparseEnzyme()), u0 in (1.0, [1.0, 1.0]) + @testset "ADType: $(autodiff) u0: $(_nameof(u0))" for autodiff in (AutoSparseForwardDiff(), + AutoSparseFiniteDiff(), AutoZygote(), AutoSparseZygote(), AutoSparseEnzyme()), u0 in (1.0, [1.0, 1.0]) probN = NonlinearProblem(quadratic_f, u0, 2.0) @test all(solve(probN, LevenbergMarquardt(; autodiff); abstol = 1e-9, reltol = 1e-9).u .≈ sqrt(2.0)) @@ -664,9 +661,8 @@ end @test nlprob_iterator_interface(quadratic_f, p, Val(false)) ≈ sqrt.(p) @test nlprob_iterator_interface(quadratic_f!, p, Val(true)) ≈ sqrt.(p) - @testset "ADType: $(autodiff) u0: $(_nameof(u0))" for autodiff in (false, true, - AutoSparseForwardDiff(), AutoSparseFiniteDiff(), AutoZygote(), - AutoSparseZygote(), AutoSparseEnzyme()), u0 in (1.0, [1.0, 1.0]) + @testset "ADType: $(autodiff) u0: $(_nameof(u0))" for autodiff in (AutoSparseForwardDiff(), + AutoSparseFiniteDiff(), AutoZygote(), AutoSparseZygote(), AutoSparseEnzyme()), u0 in (1.0, [1.0, 1.0]) probN = NonlinearProblem(quadratic_f, u0, 2.0) @test all(solve(probN, PseudoTransient(; alpha_initial = 10.0, autodiff)).u .≈ sqrt(2.0)) @@ -689,17 +685,17 @@ end end end -# --- GeneralBroyden tests --- +# --- Broyden tests --- -@testset "GeneralBroyden" begin +@testset "Broyden" begin function benchmark_nlsolve_oop(f, u0, p = 2.0; linesearch = nothing) prob = NonlinearProblem{false}(f, u0, p) - return solve(prob, GeneralBroyden(; linesearch), abstol = 1e-9) + return solve(prob, Broyden(; linesearch), abstol = 1e-9) end function benchmark_nlsolve_iip(f, u0, p = 2.0; linesearch = nothing) prob = NonlinearProblem{true}(f, u0, p) - return solve(prob, GeneralBroyden(; linesearch), abstol = 1e-9) + return solve(prob, Broyden(; linesearch), abstol = 1e-9) end @testset "LineSearch: $(_nameof(lsmethod)) LineSearch AD: $(_nameof(ad))" for lsmethod in (Static(), @@ -716,7 +712,7 @@ end @test all(abs.(sol.u .* sol.u .- 2) .< 1e-9) cache = init(NonlinearProblem{false}(quadratic_f, u0, 2.0), - GeneralBroyden(; linesearch), abstol = 1e-9) + Broyden(; linesearch), abstol = 1e-9) @test (@ballocated solve!($cache)) < 200 end @@ -727,7 +723,7 @@ end @test all(abs.(sol.u .* sol.u .- 2) .< 1e-9) cache = init(NonlinearProblem{true}(quadratic_f!, u0, 2.0), - GeneralBroyden(; linesearch), abstol = 1e-9) + Broyden(; linesearch), abstol = 1e-9) @test (@ballocated solve!($cache)) ≤ 64 end end @@ -765,7 +761,7 @@ end # Iterator interface function nlprob_iterator_interface(f, p_range, ::Val{iip}) where {iip} probN = NonlinearProblem{iip}(f, iip ? [0.5] : 0.5, p_range[begin]) - cache = init(probN, GeneralBroyden(); maxiters = 100, abstol = 1e-10) + cache = init(probN, Broyden(); maxiters = 100, abstol = 1e-10) sols = zeros(length(p_range)) for (i, p) in enumerate(p_range) reinit!(cache, iip ? [cache.u[1]] : cache.u; p = p) @@ -782,23 +778,23 @@ end u0 in (1.0, [1.0, 1.0]) probN = NonlinearProblem(quadratic_f, u0, 2.0) - @test all(solve(probN, GeneralBroyden(); termination_condition).u .≈ sqrt(2.0)) + @test all(solve(probN, Broyden(); termination_condition).u .≈ sqrt(2.0)) end end -# --- GeneralKlement tests --- +# --- Klement tests --- @testset "GeneralKlement" begin function benchmark_nlsolve_oop(f, u0, p = 2.0; linesearch = nothing, init_jacobian = Val(:identity)) prob = NonlinearProblem{false}(f, u0, p) - return solve(prob, GeneralKlement(; linesearch, init_jacobian), abstol = 1e-9) + return solve(prob, Klement(; linesearch, init_jacobian), abstol = 1e-9) end function benchmark_nlsolve_iip(f, u0, p = 2.0; linesearch = nothing, init_jacobian = Val(:identity)) prob = NonlinearProblem{true}(f, u0, p) - return solve(prob, GeneralKlement(; linesearch, init_jacobian), abstol = 1e-9) + return solve(prob, Klement(; linesearch, init_jacobian), abstol = 1e-9) end @testset "LineSearch: $(_nameof(lsmethod)) LineSearch AD: $(_nameof(ad)) Init Jacobian: $(init_jacobian)" for lsmethod in (Static(), @@ -816,7 +812,7 @@ end @test all(abs.(sol.u .* sol.u .- 2) .< 3e-9) cache = init(NonlinearProblem{false}(quadratic_f, u0, 2.0), - GeneralKlement(; linesearch), abstol = 1e-9) + Klement(; linesearch), abstol = 1e-9) @test (@ballocated solve!($cache)) < 200 end @@ -827,7 +823,7 @@ end @test all(abs.(sol.u .* sol.u .- 2) .< 1e-9) cache = init(NonlinearProblem{true}(quadratic_f!, u0, 2.0), - GeneralKlement(; linesearch), abstol = 1e-9) + Klement(; linesearch), abstol = 1e-9) @test (@ballocated solve!($cache)) ≤ 64 end end @@ -865,7 +861,7 @@ end # Iterator interface function nlprob_iterator_interface(f, p_range, ::Val{iip}) where {iip} probN = NonlinearProblem{iip}(f, iip ? [0.5] : 0.5, p_range[begin]) - cache = init(probN, GeneralKlement(); maxiters = 100, abstol = 1e-10) + cache = init(probN, Klement(); maxiters = 100, abstol = 1e-10) sols = zeros(length(p_range)) for (i, p) in enumerate(p_range) reinit!(cache, iip ? [cache.u[1]] : cache.u; p = p) @@ -882,7 +878,7 @@ end u0 in (1.0, [1.0, 1.0]) probN = NonlinearProblem(quadratic_f, u0, 2.0) - @test all(solve(probN, GeneralKlement(); termination_condition).u .≈ sqrt(2.0)) + @test all(solve(probN, Klement(); termination_condition).u .≈ sqrt(2.0)) end end diff --git a/test/gpu.jl b/test/gpu.jl index c314f4d76..8459a2a2a 100644 --- a/test/gpu.jl +++ b/test/gpu.jl @@ -11,7 +11,7 @@ linear_f(du, u, p) = (du .= A * u .+ b) prob = NonlinearProblem(linear_f, u0) for alg in (NewtonRaphson(), LevenbergMarquardt(; linsolve = QRFactorization()), - PseudoTransient(; alpha_initial = 1.0f0), GeneralKlement(), GeneralBroyden(), + PseudoTransient(; alpha_initial = 1.0f0), Klement(), Broyden(), LimitedMemoryBroyden(), TrustRegion()) @test_nowarn sol = solve(prob, alg; abstol = 1.0f-8, reltol = 1.0f-8) end @@ -21,7 +21,7 @@ linear_f(u, p) = A * u .+ b prob = NonlinearProblem{false}(linear_f, u0) for alg in (NewtonRaphson(), LevenbergMarquardt(; linsolve = QRFactorization()), - PseudoTransient(; alpha_initial = 1.0f0), GeneralKlement(), GeneralBroyden(), + PseudoTransient(; alpha_initial = 1.0f0), Klement(), Broyden(), LimitedMemoryBroyden(), TrustRegion()) @test_nowarn sol = solve(prob, alg; abstol = 1.0f-8, reltol = 1.0f-8) end diff --git a/test/matrix_resizing.jl b/test/matrix_resizing.jl index 59a537ace..e2d2cb0a3 100644 --- a/test/matrix_resizing.jl +++ b/test/matrix_resizing.jl @@ -7,7 +7,7 @@ vecprob = NonlinearProblem(ff, vec(u0), p) prob = NonlinearProblem(ff, u0, p) for alg in (NewtonRaphson(), TrustRegion(), LevenbergMarquardt(), PseudoTransient(), - RobustMultiNewton(), FastShortcutNonlinearPolyalg(), GeneralBroyden(), GeneralKlement(), + RobustMultiNewton(), FastShortcutNonlinearPolyalg(), Broyden(), Klement(), LimitedMemoryBroyden(; threshold = 2)) @test vec(solve(prob, alg).u) == solve(vecprob, alg).u end @@ -19,7 +19,7 @@ vecprob = NonlinearProblem(fiip, vec(u0), p) prob = NonlinearProblem(fiip, u0, p) for alg in (NewtonRaphson(), TrustRegion(), LevenbergMarquardt(), PseudoTransient(), - RobustMultiNewton(), FastShortcutNonlinearPolyalg(), GeneralBroyden(), GeneralKlement(), + RobustMultiNewton(), FastShortcutNonlinearPolyalg(), Broyden(), Klement(), LimitedMemoryBroyden(; threshold = 2)) @test vec(solve(prob, alg).u) == solve(vecprob, alg).u end diff --git a/test/polyalgs.jl b/test/polyalgs.jl index e56bb5353..9a0409671 100644 --- a/test/polyalgs.jl +++ b/test/polyalgs.jl @@ -4,7 +4,7 @@ f(u, p) = u .* u .- 2 u0 = [1.0, 1.0] probN = NonlinearProblem{false}(f, u0) -custom_polyalg = NonlinearSolvePolyAlgorithm((GeneralBroyden(), LimitedMemoryBroyden())) +custom_polyalg = NonlinearSolvePolyAlgorithm((Broyden(), LimitedMemoryBroyden())) # Uses the `__solve` function @time solver = solve(probN; abstol = 1e-9)