Skip to content

Commit 79995ab

Browse files
Merge pull request #190 from oscardssmith/use-NLStats
use NLStats
2 parents 753173e + 11185fe commit 79995ab

File tree

14 files changed

+403
-347
lines changed

14 files changed

+403
-347
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
1111
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1212
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1313
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
14+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1415
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
1516
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1617
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
1718
SimpleNonlinearSolve = "727e6d20-b764-4bd8-a329-72de5adea6c7"
18-
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1919
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2020
SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
2121
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
@@ -28,11 +28,11 @@ EnumX = "1"
2828
FiniteDiff = "2"
2929
ForwardDiff = "0.10.3"
3030
LinearSolve = "2"
31+
PrecompileTools = "1"
3132
RecursiveArrayTools = "2"
3233
Reexport = "0.2, 1"
33-
SciMLBase = "1.73"
34+
SciMLBase = "1.92.4"
3435
SimpleNonlinearSolve = "0.1"
35-
PrecompileTools = "1"
3636
SparseDiffTools = "1, 2"
3737
StaticArraysCore = "1.4"
3838
UnPack = "1.0"

docs/make.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
using Documenter, NonlinearSolve, SimpleNonlinearSolve, Sundials, SciMLNLSolve,
2-
NonlinearSolveMINPACK, SteadyStateDiffEq
2+
NonlinearSolveMINPACK, SteadyStateDiffEq
33

44
cp("./docs/Manifest.toml", "./docs/src/assets/Manifest.toml", force = true)
55
cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)
66

77
include("pages.jl")
88

99
makedocs(sitename = "NonlinearSolve.jl",
10-
authors = "Chris Rackauckas",
11-
modules = [NonlinearSolve, NonlinearSolve.SciMLBase, NonlinearSolve.DiffEqBase,
12-
SimpleNonlinearSolve, Sundials, SciMLNLSolve, NonlinearSolveMINPACK,
13-
SteadyStateDiffEq],
14-
clean = true, doctest = false,
15-
strict = [
16-
:doctest,
17-
:linkcheck,
18-
:parse_error,
19-
:example_block,
20-
# Other available options are
21-
# :autodocs_block, :cross_references, :docs_block, :eval_block, :example_block, :footnote, :meta_block, :missing_docs, :setup_block
22-
],
23-
format = Documenter.HTML(assets = ["assets/favicon.ico"],
24-
canonical = "https://docs.sciml.ai/NonlinearSolve/stable/"),
25-
pages = pages)
10+
authors = "Chris Rackauckas",
11+
modules = [NonlinearSolve, NonlinearSolve.SciMLBase, NonlinearSolve.DiffEqBase,
12+
SimpleNonlinearSolve, Sundials, SciMLNLSolve, NonlinearSolveMINPACK,
13+
SteadyStateDiffEq],
14+
clean = true, doctest = false,
15+
strict = [
16+
:doctest,
17+
:linkcheck,
18+
:parse_error,
19+
:example_block,
20+
# Other available options are
21+
# :autodocs_block, :cross_references, :docs_block, :eval_block, :example_block, :footnote, :meta_block, :missing_docs, :setup_block
22+
],
23+
format = Documenter.HTML(assets = ["assets/favicon.ico"],
24+
canonical = "https://docs.sciml.ai/NonlinearSolve/stable/"),
25+
pages = pages)
2626

2727
deploydocs(repo = "github.com/SciML/NonlinearSolve.jl.git";
28-
push_preview = true)
28+
push_preview = true)

docs/pages.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
pages = ["index.md",
44
"Tutorials" => Any["tutorials/nonlinear.md",
5-
"tutorials/iterator_interface.md"],
5+
"tutorials/iterator_interface.md"],
66
"Basics" => Any["basics/NonlinearProblem.md",
7-
"basics/NonlinearFunctions.md",
8-
"basics/solve.md",
9-
"basics/NonlinearSolution.md",
10-
"basics/TerminationCondition.md",
11-
"basics/FAQ.md"],
7+
"basics/NonlinearFunctions.md",
8+
"basics/solve.md",
9+
"basics/NonlinearSolution.md",
10+
"basics/TerminationCondition.md",
11+
"basics/FAQ.md"],
1212
"Solver Summaries and Recommendations" => Any["solvers/NonlinearSystemSolvers.md",
13-
"solvers/BracketingSolvers.md",
14-
"solvers/SteadyStateSolvers.md"],
13+
"solvers/BracketingSolvers.md",
14+
"solvers/SteadyStateSolvers.md"],
1515
"Detailed Solver APIs" => Any["api/nonlinearsolve.md",
16-
"api/simplenonlinearsolve.md",
17-
"api/minpack.md",
18-
"api/nlsolve.md",
19-
"api/sundials.md",
20-
"api/steadystatediffeq.md"],
16+
"api/simplenonlinearsolve.md",
17+
"api/minpack.md",
18+
"api/nlsolve.md",
19+
"api/sundials.md",
20+
"api/steadystatediffeq.md"],
2121
]

docs/src/basics/FAQ.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ myfun(x, lv) = x * sin(x) - lv
1616
function f(out, levels, u0)
1717
for i in 1:N
1818
out[i] = solve(IntervalNonlinearProblem{false}(IntervalNonlinearFunction{false}(myfun),
19-
u0, levels[i]), Falsi()).u
19+
u0, levels[i]), Falsi()).u
2020
end
2121
end
2222
2323
function f2(out, levels, u0)
2424
for i in 1:N
2525
out[i] = solve(NonlinearProblem{false}(NonlinearFunction{false}(myfun),
26-
u0, levels[i]), SimpleNewtonRaphson()).u
26+
u0, levels[i]), SimpleNewtonRaphson()).u
2727
end
2828
end
2929

src/NonlinearSolve.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ using DiffEqBase
1717
using SparseDiffTools
1818

1919
@reexport using SciMLBase
20+
using SciMLBase: NLStats
2021
@reexport using SimpleNonlinearSolve
2122

2223
import SciMLBase: _unwrap_val
@@ -26,8 +27,8 @@ abstract type AbstractNewtonAlgorithm{CS, AD, FDT, ST, CJ} <:
2627
AbstractNonlinearSolveAlgorithm end
2728

2829
function SciMLBase.__solve(prob::NonlinearProblem,
29-
alg::AbstractNonlinearSolveAlgorithm, args...;
30-
kwargs...)
30+
alg::AbstractNonlinearSolveAlgorithm, args...;
31+
kwargs...)
3132
cache = init(prob, alg, args...; kwargs...)
3233
sol = solve!(cache)
3334
end
@@ -56,7 +57,7 @@ PrecompileTools.@compile_workload begin
5657
end
5758

5859
prob = NonlinearProblem{true}((du, u, p) -> du[1] = u[1] * u[1] - p[1], T[0.1],
59-
T[2])
60+
T[2])
6061
for alg in precompile_algs
6162
solve(prob, alg, abstol = T(1e-2))
6263
end

src/ad.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ function scalar_nlsolve_ad(prob, alg, args...; kwargs...)
2424
end
2525

2626
function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, StaticArraysCore.SVector},
27-
iip,
28-
<:Dual{T, V, P}},
29-
alg::AbstractNewtonAlgorithm,
30-
args...; kwargs...) where {iip, T, V, P}
27+
iip,
28+
<:Dual{T, V, P}},
29+
alg::AbstractNewtonAlgorithm,
30+
args...; kwargs...) where {iip, T, V, P}
3131
sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...)
3232
return SciMLBase.build_solution(prob, alg, Dual{T, V, P}(sol.u, partials), sol.resid;
33-
retcode = sol.retcode)
33+
retcode = sol.retcode)
3434
end
3535
function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, StaticArraysCore.SVector},
36-
iip,
37-
<:AbstractArray{<:Dual{T, V, P}}},
38-
alg::AbstractNewtonAlgorithm,
39-
args...;
40-
kwargs...) where {iip, T, V, P}
36+
iip,
37+
<:AbstractArray{<:Dual{T, V, P}}},
38+
alg::AbstractNewtonAlgorithm,
39+
args...;
40+
kwargs...) where {iip, T, V, P}
4141
sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...)
4242
return SciMLBase.build_solution(prob, alg, Dual{T, V, P}(sol.u, partials), sol.resid;
43-
retcode = sol.retcode)
43+
retcode = sol.retcode)
4444
end

src/jacobian.jl

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ end
1717

1818
function jacobian_finitediff_forward!(J, f, x, jac_config, forwardcache, cache)
1919
(FiniteDiff.finite_difference_jacobian!(J, f, x, jac_config, forwardcache);
20-
maximum(jac_config.colorvec))
20+
maximum(jac_config.colorvec))
2121
end
2222
function jacobian_finitediff!(J, f, x, jac_config, cache)
2323
(FiniteDiff.finite_difference_jacobian!(J, f, x, jac_config);
24-
2 * maximum(jac_config.colorvec))
24+
2 * maximum(jac_config.colorvec))
2525
end
2626

2727
function jacobian!(J::AbstractMatrix{<:Number}, cache)
@@ -43,7 +43,7 @@ function jacobian!(J::AbstractMatrix{<:Number}, cache)
4343
uf(fx, x)
4444
#cache.destats.nf += 1
4545
tmp = jacobian_finitediff_forward!(J, uf, x, jac_config, fx,
46-
cache)
46+
cache)
4747
else # not forward difference
4848
tmp = jacobian_finitediff!(J, uf, x, jac_config, cache)
4949
end
@@ -71,18 +71,18 @@ function build_jac_config(alg, f::F1, uf::F2, du1, u, tmp, du2) where {F1, F2}
7171
typeof(ForwardDiff.Tag(uf, eltype(u)))
7272
end
7373
jac_config = ForwardColorJacCache(uf, u, _chunksize; colorvec = colorvec,
74-
sparsity = sparsity, tag = T)
74+
sparsity = sparsity, tag = T)
7575
else
7676
if alg_difftype(alg) !== Val{:complex}
7777
jac_config = FiniteDiff.JacobianCache(tmp, du1, du2, alg_difftype(alg),
78-
colorvec = colorvec,
79-
sparsity = sparsity)
78+
colorvec = colorvec,
79+
sparsity = sparsity)
8080
else
8181
jac_config = FiniteDiff.JacobianCache(Complex{eltype(tmp)}.(tmp),
82-
Complex{eltype(du1)}.(du1), nothing,
83-
alg_difftype(alg), eltype(u),
84-
colorvec = colorvec,
85-
sparsity = sparsity)
82+
Complex{eltype(du1)}.(du1), nothing,
83+
alg_difftype(alg), eltype(u),
84+
colorvec = colorvec,
85+
sparsity = sparsity)
8686
end
8787
end
8888
else
@@ -91,23 +91,28 @@ function build_jac_config(alg, f::F1, uf::F2, du1, u, tmp, du2) where {F1, F2}
9191
jac_config
9292
end
9393

94-
function get_chunksize(jac_config::ForwardDiff.JacobianConfig{T, V, N, D}) where {T, V, N, D
95-
}
94+
function get_chunksize(jac_config::ForwardDiff.JacobianConfig{
95+
T,
96+
V,
97+
N,
98+
D,
99+
}) where {T, V, N, D
100+
}
96101
Val(N)
97102
end # don't degrade compile time information to runtime information
98103

99104
function jacobian_finitediff(f, x, ::Type{diff_type}, dir, colorvec, sparsity,
100-
jac_prototype) where {diff_type}
105+
jac_prototype) where {diff_type}
101106
(FiniteDiff.finite_difference_derivative(f, x, diff_type, eltype(x), dir = dir), 2)
102107
end
103108
function jacobian_finitediff(f, x::AbstractArray, ::Type{diff_type}, dir, colorvec,
104-
sparsity, jac_prototype) where {diff_type}
109+
sparsity, jac_prototype) where {diff_type}
105110
f_in = diff_type === Val{:forward} ? f(x) : similar(x)
106111
ret_eltype = eltype(f_in)
107112
J = FiniteDiff.finite_difference_jacobian(f, x, diff_type, ret_eltype, f_in,
108-
dir = dir, colorvec = colorvec,
109-
sparsity = sparsity,
110-
jac_prototype = jac_prototype)
113+
dir = dir, colorvec = colorvec,
114+
sparsity = sparsity,
115+
jac_prototype = jac_prototype)
111116
return J, _nfcount(maximum(colorvec), diff_type)
112117
end
113118
function jacobian(cache, f::F) where {F}
@@ -125,7 +130,7 @@ function jacobian(cache, f::F) where {F}
125130
sparsity, colorvec = sparsity_colorvec(cache.f, x)
126131
dir = true
127132
J, tmp = jacobian_finitediff(uf, x, alg_difftype(alg), dir, colorvec, sparsity,
128-
jac_prototype)
133+
jac_prototype)
129134
end
130135
J
131136
end
@@ -141,6 +146,6 @@ function jacobian_autodiff(f, x::AbstractArray, nonlinfun, alg)
141146
SparseDiffTools.getsize(ForwardDiff.pickchunksize(maxcolor)))) :
142147
Int(ceil(maxcolor / _unwrap_val(chunk_size)))
143148
(forwarddiff_color_jacobian(f, x, colorvec = colorvec, sparsity = sparsity,
144-
jac_prototype = jac_prototype, chunksize = chunk_size),
145-
num_of_chunks)
149+
jac_prototype = jac_prototype, chunksize = chunk_size),
150+
num_of_chunks)
146151
end

0 commit comments

Comments
 (0)