-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from avik-pal/ap/cleanup
Port over improvements from NonlinearSolve
- Loading branch information
Showing
43 changed files
with
2,114 additions
and
2,709 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
style = "sciml" | ||
style = "sciml" | ||
format_markdown = true | ||
annotate_untyped_fields_with_any = false | ||
format_docstrings = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,30 @@ | ||
name = "SimpleNonlinearSolve" | ||
uuid = "727e6d20-b764-4bd8-a329-72de5adea6c7" | ||
authors = ["SciML"] | ||
version = "0.1.25" | ||
version = "0.2.0" | ||
|
||
[deps] | ||
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" | ||
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" | ||
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471" | ||
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" | ||
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41" | ||
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
MaybeInplace = "bb5d69b7-63fc-4a16-80bd-7e42200c7bdb" | ||
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" | ||
Reexport = "189a3867-3050-52da-a836-e630ba90ab69" | ||
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" | ||
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" | ||
|
||
[weakdeps] | ||
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" | ||
|
||
[extensions] | ||
SimpleNonlinearSolveNNlibExt = "NNlib" | ||
|
||
[compat] | ||
ArrayInterface = "7" | ||
DiffEqBase = "6.126" | ||
FiniteDiff = "2" | ||
ForwardDiff = "0.10.3" | ||
LinearAlgebra = "1.9" | ||
NNlib = "0.8, 0.9" | ||
PrecompileTools = "1" | ||
Reexport = "1" | ||
SciMLBase = "2.7" | ||
StaticArraysCore = "1.4" | ||
julia = "1.9" | ||
|
||
[extras] | ||
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 0 additions & 81 deletions
81
lib/SimpleNonlinearSolve/ext/SimpleNonlinearSolveNNlibExt.jl
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,101 @@ | ||
module SimpleNonlinearSolve | ||
|
||
using Reexport | ||
using FiniteDiff, ForwardDiff | ||
using ForwardDiff: Dual | ||
using StaticArraysCore | ||
using LinearAlgebra | ||
import ArrayInterface | ||
using DiffEqBase | ||
|
||
@reexport using SciMLBase | ||
import PrecompileTools: @compile_workload, @setup_workload, @recompile_invalidations | ||
|
||
@recompile_invalidations begin | ||
using ADTypes, | ||
ArrayInterface, ConcreteStructs, DiffEqBase, Reexport, LinearAlgebra, SciMLBase | ||
|
||
import DiffEqBase: AbstractNonlinearTerminationMode, | ||
AbstractSafeNonlinearTerminationMode, AbstractSafeBestNonlinearTerminationMode, | ||
NonlinearSafeTerminationReturnCode, get_termination_mode, | ||
NONLINEARSOLVE_DEFAULT_NORM | ||
using FiniteDiff, ForwardDiff | ||
import ForwardDiff: Dual | ||
import MaybeInplace: @bb, setindex_trait, CanSetindex, CannotSetindex | ||
import SciMLBase: AbstractNonlinearAlgorithm, build_solution, isinplace | ||
import StaticArraysCore: StaticArray, SVector, SMatrix, SArray, MArray, MMatrix, Size | ||
end | ||
|
||
const NNlibExtLoaded = Ref{Bool}(false) | ||
@reexport using ADTypes, SciMLBase | ||
|
||
abstract type AbstractSimpleNonlinearSolveAlgorithm <: SciMLBase.AbstractNonlinearAlgorithm end | ||
abstract type AbstractSimpleNonlinearSolveAlgorithm <: AbstractNonlinearAlgorithm end | ||
abstract type AbstractBracketingAlgorithm <: AbstractSimpleNonlinearSolveAlgorithm end | ||
abstract type AbstractNewtonAlgorithm{CS, AD, FDT} <: AbstractSimpleNonlinearSolveAlgorithm end | ||
abstract type AbstractImmutableNonlinearSolver <: AbstractSimpleNonlinearSolveAlgorithm end | ||
abstract type AbstractBatchedNonlinearSolveAlgorithm <: | ||
AbstractSimpleNonlinearSolveAlgorithm end | ||
abstract type AbstractNewtonAlgorithm <: AbstractSimpleNonlinearSolveAlgorithm end | ||
|
||
include("utils.jl") | ||
include("bisection.jl") | ||
include("falsi.jl") | ||
include("raphson.jl") | ||
include("broyden.jl") | ||
include("lbroyden.jl") | ||
include("klement.jl") | ||
include("trustRegion.jl") | ||
include("ridder.jl") | ||
include("brent.jl") | ||
include("dfsane.jl") | ||
include("ad.jl") | ||
include("halley.jl") | ||
include("alefeld.jl") | ||
include("itp.jl") | ||
|
||
# Batched Solver Support | ||
include("batched/utils.jl") | ||
include("batched/raphson.jl") | ||
include("batched/dfsane.jl") | ||
include("batched/broyden.jl") | ||
## Nonlinear Solvers | ||
include("nlsolve/raphson.jl") | ||
include("nlsolve/broyden.jl") | ||
include("nlsolve/lbroyden.jl") | ||
include("nlsolve/klement.jl") | ||
include("nlsolve/trustRegion.jl") | ||
include("nlsolve/halley.jl") | ||
include("nlsolve/dfsane.jl") | ||
|
||
## Interval Nonlinear Solvers | ||
include("bracketing/bisection.jl") | ||
include("bracketing/falsi.jl") | ||
include("bracketing/ridder.jl") | ||
include("bracketing/brent.jl") | ||
include("bracketing/alefeld.jl") | ||
include("bracketing/itp.jl") | ||
|
||
# AD | ||
include("ad.jl") | ||
|
||
## Default algorithm | ||
|
||
# Set the default bracketing method to ITP | ||
|
||
function SciMLBase.solve(prob::IntervalNonlinearProblem; kwargs...) | ||
SciMLBase.solve(prob, ITP(); kwargs...) | ||
return solve(prob, ITP(); kwargs...) | ||
end | ||
|
||
function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Nothing, | ||
args...; kwargs...) | ||
SciMLBase.solve(prob, ITP(), args...; kwargs...) | ||
return solve(prob, ITP(), args...; kwargs...) | ||
end | ||
|
||
import PrecompileTools | ||
|
||
PrecompileTools.@compile_workload begin | ||
@setup_workload begin | ||
for T in (Float32, Float64) | ||
prob_no_brack = NonlinearProblem{false}((u, p) -> u .* u .- p, T(0.1), T(2)) | ||
for alg in (SimpleNewtonRaphson, SimpleHalley, Broyden, Klement, SimpleTrustRegion, | ||
SimpleDFSane) | ||
solve(prob_no_brack, alg(), abstol = T(1e-2)) | ||
end | ||
prob_no_brack_scalar = NonlinearProblem{false}((u, p) -> u .* u .- p, T(0.1), T(2)) | ||
prob_no_brack_iip = NonlinearProblem{true}((du, u, p) -> du .= u .* u .- p, | ||
T.([1.0, 1.0, 1.0]), T(2)) | ||
prob_no_brack_oop = NonlinearProblem{false}((u, p) -> u .* u .- p, | ||
T.([1.0, 1.0, 1.0]), T(2)) | ||
|
||
algs = [SimpleNewtonRaphson(), SimpleBroyden(), SimpleKlement(), SimpleDFSane(), | ||
SimpleTrustRegion(), SimpleLimitedMemoryBroyden(; threshold = 2)] | ||
|
||
algs_no_iip = [SimpleHalley()] | ||
|
||
@compile_workload begin | ||
for alg in algs | ||
solve(prob_no_brack_scalar, alg, abstol = T(1e-2)) | ||
solve(prob_no_brack_iip, alg, abstol = T(1e-2)) | ||
solve(prob_no_brack_oop, alg, abstol = T(1e-2)) | ||
end | ||
|
||
#= | ||
for alg in (SimpleNewtonRaphson,) | ||
for u0 in ([1., 1.], StaticArraysCore.SA[1.0, 1.0]) | ||
u0 = T.(.1) | ||
probN = NonlinearProblem{false}((u,p) -> u .* u .- p, u0, T(2)) | ||
solve(probN, alg(), tol = T(1e-2)) | ||
for alg in algs_no_iip | ||
solve(prob_no_brack_scalar, alg, abstol = T(1e-2)) | ||
solve(prob_no_brack_oop, alg, abstol = T(1e-2)) | ||
end | ||
end | ||
=# | ||
|
||
prob_brack = IntervalNonlinearProblem{false}((u, p) -> u * u - p, | ||
T.((0.0, 2.0)), | ||
T(2)) | ||
for alg in (Bisection, Falsi, Ridder, Brent, Alefeld, ITP) | ||
solve(prob_brack, alg(), abstol = T(1e-2)) | ||
T.((0.0, 2.0)), T(2)) | ||
algs = [Bisection(), Falsi(), Ridder(), Brent(), Alefeld(), ITP()] | ||
@compile_workload begin | ||
for alg in algs | ||
solve(prob_brack, alg, abstol = T(1e-2)) | ||
end | ||
end | ||
end | ||
end | ||
|
||
export Bisection, Brent, Broyden, LBroyden, SimpleDFSane, Falsi, SimpleHalley, Klement, | ||
Ridder, SimpleNewtonRaphson, SimpleTrustRegion, Alefeld, ITP, SimpleGaussNewton | ||
export BatchedBroyden, BatchedSimpleNewtonRaphson, BatchedSimpleDFSane | ||
export SimpleBroyden, SimpleDFSane, SimpleGaussNewton, SimpleHalley, SimpleKlement, | ||
SimpleLimitedMemoryBroyden, SimpleNewtonRaphson, SimpleTrustRegion | ||
export Alefeld, Bisection, Brent, Falsi, ITP, Ridder | ||
|
||
end # module |
Oops, something went wrong.