Skip to content

Commit 14b65b4

Browse files
Merge pull request #100 from avik-pal/ap/cleanup
Port over improvements from NonlinearSolve
2 parents 31b8a57 + 32c20f1 commit 14b65b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2114
-2709
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
style = "sciml"
1+
style = "sciml"
2+
format_markdown = true
3+
annotate_untyped_fields_with_any = false
4+
format_docstrings = true

lib/SimpleNonlinearSolve/Project.toml

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,30 @@
11
name = "SimpleNonlinearSolve"
22
uuid = "727e6d20-b764-4bd8-a329-72de5adea6c7"
33
authors = ["SciML"]
4-
version = "0.1.25"
4+
version = "0.2.0"
55

66
[deps]
7+
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
78
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
9+
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471"
810
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
911
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
1012
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1113
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
14+
MaybeInplace = "bb5d69b7-63fc-4a16-80bd-7e42200c7bdb"
1215
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1316
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1417
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
1518
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
1619

17-
[weakdeps]
18-
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
19-
20-
[extensions]
21-
SimpleNonlinearSolveNNlibExt = "NNlib"
22-
2320
[compat]
2421
ArrayInterface = "7"
2522
DiffEqBase = "6.126"
2623
FiniteDiff = "2"
2724
ForwardDiff = "0.10.3"
2825
LinearAlgebra = "1.9"
29-
NNlib = "0.8, 0.9"
3026
PrecompileTools = "1"
3127
Reexport = "1"
3228
SciMLBase = "2.7"
3329
StaticArraysCore = "1.4"
3430
julia = "1.9"
35-
36-
[extras]
37-
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"

lib/SimpleNonlinearSolve/README.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
[![codecov](https://codecov.io/gh/SciML/SimpleNonlinearSolve.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/SciML/SimpleNonlinearSolve.jl)
77
[![Build Status](https://github.com/SciML/SimpleNonlinearSolve.jl/workflows/CI/badge.svg)](https://github.com/SciML/SimpleNonlinearSolve.jl/actions?query=workflow%3ACI)
88

9-
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
9+
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor%27s%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
1010
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)
1111

1212
Fast implementations of root finding algorithms in Julia that satisfy the SciML common interface.
1313
SimpleNonlinearSolve.jl focuses on low-dependency implementations of very fast methods for
14-
very small and simple problems. For the full set of solvers, see
14+
very small and simple problems. For the full set of solvers, see
1515
[NonlinearSolve.jl](https://github.com/SciML/NonlinearSolve.jl), of which
1616
SimpleNonlinearSolve.jl is just one solver set.
1717

@@ -25,7 +25,7 @@ the documentation which contains the unreleased features.
2525
```julia
2626
using SimpleNonlinearSolve, StaticArrays
2727

28-
f(u,p) = u .* u .- 2
28+
f(u, p) = u .* u .- 2
2929
u0 = @SVector[1.0, 1.0]
3030
probN = NonlinearProblem{false}(f, u0)
3131
solver = solve(probN, SimpleNewtonRaphson(), abstol = 1e-9)
@@ -39,3 +39,16 @@ sol = solve(probB, ITP())
3939
```
4040

4141
For more details on the bracketing methods, refer to the [Tutorials](https://docs.sciml.ai/NonlinearSolve/stable/tutorials/nonlinear/#Using-Bracketing-Methods) and detailed [APIs](https://docs.sciml.ai/NonlinearSolve/stable/api/simplenonlinearsolve/#Solver-API)
42+
43+
## Breaking Changes in v2
44+
45+
- Batched solvers have been removed in favor of `BatchedArrays.jl`. Stay tuned for detailed
46+
tutorials on how to use `BatchedArrays.jl` with `NonlinearSolve` & `SimpleNonlinearSolve`
47+
solvers.
48+
- The old style of specifying autodiff with `chunksize`, `standardtag`, etc. has been
49+
deprecated in favor of directly specifying the autodiff type, like `AutoForwardDiff`.
50+
- `Broyden` and `Klement` have been renamed to `SimpleBroyden` and `SimpleKlement` to
51+
avoid conflicts with `NonlinearSolve.jl`'s `GeneralBroyden` and `GeneralKlement`, which
52+
will be renamed to `Broyden` and `Klement` in the future.
53+
- `LBroyden` has been renamed to `SimpleLimitedMemoryBroyden` to make it consistent with
54+
`NonlinearSolve.jl`'s `LimitedMemoryBroyden`.

lib/SimpleNonlinearSolve/ext/SimpleNonlinearSolveNNlibExt.jl

-81
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,101 @@
11
module SimpleNonlinearSolve
22

3-
using Reexport
4-
using FiniteDiff, ForwardDiff
5-
using ForwardDiff: Dual
6-
using StaticArraysCore
7-
using LinearAlgebra
8-
import ArrayInterface
9-
using DiffEqBase
10-
11-
@reexport using SciMLBase
3+
import PrecompileTools: @compile_workload, @setup_workload, @recompile_invalidations
4+
5+
@recompile_invalidations begin
6+
using ADTypes,
7+
ArrayInterface, ConcreteStructs, DiffEqBase, Reexport, LinearAlgebra, SciMLBase
8+
9+
import DiffEqBase: AbstractNonlinearTerminationMode,
10+
AbstractSafeNonlinearTerminationMode, AbstractSafeBestNonlinearTerminationMode,
11+
NonlinearSafeTerminationReturnCode, get_termination_mode,
12+
NONLINEARSOLVE_DEFAULT_NORM
13+
using FiniteDiff, ForwardDiff
14+
import ForwardDiff: Dual
15+
import MaybeInplace: @bb, setindex_trait, CanSetindex, CannotSetindex
16+
import SciMLBase: AbstractNonlinearAlgorithm, build_solution, isinplace
17+
import StaticArraysCore: StaticArray, SVector, SMatrix, SArray, MArray, MMatrix, Size
18+
end
1219

13-
const NNlibExtLoaded = Ref{Bool}(false)
20+
@reexport using ADTypes, SciMLBase
1421

15-
abstract type AbstractSimpleNonlinearSolveAlgorithm <: SciMLBase.AbstractNonlinearAlgorithm end
22+
abstract type AbstractSimpleNonlinearSolveAlgorithm <: AbstractNonlinearAlgorithm end
1623
abstract type AbstractBracketingAlgorithm <: AbstractSimpleNonlinearSolveAlgorithm end
17-
abstract type AbstractNewtonAlgorithm{CS, AD, FDT} <: AbstractSimpleNonlinearSolveAlgorithm end
18-
abstract type AbstractImmutableNonlinearSolver <: AbstractSimpleNonlinearSolveAlgorithm end
19-
abstract type AbstractBatchedNonlinearSolveAlgorithm <:
20-
AbstractSimpleNonlinearSolveAlgorithm end
24+
abstract type AbstractNewtonAlgorithm <: AbstractSimpleNonlinearSolveAlgorithm end
2125

2226
include("utils.jl")
23-
include("bisection.jl")
24-
include("falsi.jl")
25-
include("raphson.jl")
26-
include("broyden.jl")
27-
include("lbroyden.jl")
28-
include("klement.jl")
29-
include("trustRegion.jl")
30-
include("ridder.jl")
31-
include("brent.jl")
32-
include("dfsane.jl")
33-
include("ad.jl")
34-
include("halley.jl")
35-
include("alefeld.jl")
36-
include("itp.jl")
3727

38-
# Batched Solver Support
39-
include("batched/utils.jl")
40-
include("batched/raphson.jl")
41-
include("batched/dfsane.jl")
42-
include("batched/broyden.jl")
28+
## Nonlinear Solvers
29+
include("nlsolve/raphson.jl")
30+
include("nlsolve/broyden.jl")
31+
include("nlsolve/lbroyden.jl")
32+
include("nlsolve/klement.jl")
33+
include("nlsolve/trustRegion.jl")
34+
include("nlsolve/halley.jl")
35+
include("nlsolve/dfsane.jl")
36+
37+
## Interval Nonlinear Solvers
38+
include("bracketing/bisection.jl")
39+
include("bracketing/falsi.jl")
40+
include("bracketing/ridder.jl")
41+
include("bracketing/brent.jl")
42+
include("bracketing/alefeld.jl")
43+
include("bracketing/itp.jl")
44+
45+
# AD
46+
include("ad.jl")
4347

4448
## Default algorithm
4549

4650
# Set the default bracketing method to ITP
47-
4851
function SciMLBase.solve(prob::IntervalNonlinearProblem; kwargs...)
49-
SciMLBase.solve(prob, ITP(); kwargs...)
52+
return solve(prob, ITP(); kwargs...)
5053
end
5154

5255
function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Nothing,
5356
args...; kwargs...)
54-
SciMLBase.solve(prob, ITP(), args...; kwargs...)
57+
return solve(prob, ITP(), args...; kwargs...)
5558
end
5659

57-
import PrecompileTools
58-
59-
PrecompileTools.@compile_workload begin
60+
@setup_workload begin
6061
for T in (Float32, Float64)
61-
prob_no_brack = NonlinearProblem{false}((u, p) -> u .* u .- p, T(0.1), T(2))
62-
for alg in (SimpleNewtonRaphson, SimpleHalley, Broyden, Klement, SimpleTrustRegion,
63-
SimpleDFSane)
64-
solve(prob_no_brack, alg(), abstol = T(1e-2))
65-
end
62+
prob_no_brack_scalar = NonlinearProblem{false}((u, p) -> u .* u .- p, T(0.1), T(2))
63+
prob_no_brack_iip = NonlinearProblem{true}((du, u, p) -> du .= u .* u .- p,
64+
T.([1.0, 1.0, 1.0]), T(2))
65+
prob_no_brack_oop = NonlinearProblem{false}((u, p) -> u .* u .- p,
66+
T.([1.0, 1.0, 1.0]), T(2))
67+
68+
algs = [SimpleNewtonRaphson(), SimpleBroyden(), SimpleKlement(), SimpleDFSane(),
69+
SimpleTrustRegion(), SimpleLimitedMemoryBroyden(; threshold = 2)]
70+
71+
algs_no_iip = [SimpleHalley()]
72+
73+
@compile_workload begin
74+
for alg in algs
75+
solve(prob_no_brack_scalar, alg, abstol = T(1e-2))
76+
solve(prob_no_brack_iip, alg, abstol = T(1e-2))
77+
solve(prob_no_brack_oop, alg, abstol = T(1e-2))
78+
end
6679

67-
#=
68-
for alg in (SimpleNewtonRaphson,)
69-
for u0 in ([1., 1.], StaticArraysCore.SA[1.0, 1.0])
70-
u0 = T.(.1)
71-
probN = NonlinearProblem{false}((u,p) -> u .* u .- p, u0, T(2))
72-
solve(probN, alg(), tol = T(1e-2))
80+
for alg in algs_no_iip
81+
solve(prob_no_brack_scalar, alg, abstol = T(1e-2))
82+
solve(prob_no_brack_oop, alg, abstol = T(1e-2))
7383
end
7484
end
75-
=#
7685

7786
prob_brack = IntervalNonlinearProblem{false}((u, p) -> u * u - p,
78-
T.((0.0, 2.0)),
79-
T(2))
80-
for alg in (Bisection, Falsi, Ridder, Brent, Alefeld, ITP)
81-
solve(prob_brack, alg(), abstol = T(1e-2))
87+
T.((0.0, 2.0)), T(2))
88+
algs = [Bisection(), Falsi(), Ridder(), Brent(), Alefeld(), ITP()]
89+
@compile_workload begin
90+
for alg in algs
91+
solve(prob_brack, alg, abstol = T(1e-2))
92+
end
8293
end
8394
end
8495
end
8596

86-
export Bisection, Brent, Broyden, LBroyden, SimpleDFSane, Falsi, SimpleHalley, Klement,
87-
Ridder, SimpleNewtonRaphson, SimpleTrustRegion, Alefeld, ITP, SimpleGaussNewton
88-
export BatchedBroyden, BatchedSimpleNewtonRaphson, BatchedSimpleDFSane
97+
export SimpleBroyden, SimpleDFSane, SimpleGaussNewton, SimpleHalley, SimpleKlement,
98+
SimpleLimitedMemoryBroyden, SimpleNewtonRaphson, SimpleTrustRegion
99+
export Alefeld, Bisection, Brent, Falsi, ITP, Ridder
89100

90101
end # module

0 commit comments

Comments
 (0)