@@ -11,7 +11,7 @@ Fetch required packages
11
11
```julia
12
12
using NonlinearSolve, SparseDiffTools, LinearAlgebra, SparseArrays, DiffEqDevTools,
13
13
CairoMakie, Symbolics, BenchmarkTools, PolyesterForwardDiff, LinearSolve, Sundials,
14
- Enzyme, SparseConnectivityTracer, DifferentiationInterface
14
+ Enzyme, SparseConnectivityTracer, DifferentiationInterface, SparseMatrixColorings
15
15
import NLsolve, MINPACK, PETSc, RecursiveFactorization
16
16
17
17
const RUS = RadiusUpdateSchemes;
@@ -156,31 +156,38 @@ function cache_and_compute_10_jacobians(adtype, f!::F, y, x, p) where {F}
156
156
return J
157
157
end
158
158
159
- Ns = [2^i for i in 1 :8]
159
+ Ns = [2^i for i in 3 :8];
160
160
161
161
adtypes = [
162
162
(
163
- AutoSparse(AutoFiniteDiff(); sparsity_detector=TracerSparsityDetector()),
163
+ AutoSparse(
164
+ AutoFiniteDiff();
165
+ sparsity_detector=TracerSparsityDetector(),
166
+ coloring_algorithm=GreedyColoringAlgorithm(LargestFirst())
167
+ ),
164
168
[:finitediff, :exact_sparse]
165
169
),
166
170
(
167
171
AutoSparse(
168
172
AutoPolyesterForwardDiff(; chunksize=8);
169
- sparsity_detector=TracerSparsityDetector()
173
+ sparsity_detector=TracerSparsityDetector(),
174
+ coloring_algorithm=GreedyColoringAlgorithm(LargestFirst())
170
175
),
171
176
[:polyester, :exact_sparse]
172
177
),
173
178
(
174
179
AutoSparse(
175
180
AutoEnzyme(; mode=Enzyme.Forward);
176
- sparsity_detector=TracerSparsityDetector()
181
+ sparsity_detector=TracerSparsityDetector(),
182
+ coloring_algorithm=GreedyColoringAlgorithm(LargestFirst())
177
183
),
178
184
[:enzyme, :exact_sparse]
179
185
),
180
186
(
181
187
AutoSparse(
182
188
AutoFiniteDiff();
183
- sparsity_detector=DenseSparsityDetector(AutoFiniteDiff(); atol=1e-5)
189
+ sparsity_detector=DenseSparsityDetector(AutoFiniteDiff(); atol=1e-5),
190
+ coloring_algorithm=GreedyColoringAlgorithm(LargestFirst())
184
191
),
185
192
[:finitediff, :approx_sparse]
186
193
),
@@ -189,7 +196,8 @@ adtypes = [
189
196
AutoPolyesterForwardDiff(; chunksize=8);
190
197
sparsity_detector=DenseSparsityDetector(
191
198
AutoPolyesterForwardDiff(; chunksize=8); atol=1e-5
192
- )
199
+ ),
200
+ coloring_algorithm=GreedyColoringAlgorithm(LargestFirst())
193
201
),
194
202
[:polyester, :approx_sparse]
195
203
),
@@ -198,17 +206,18 @@ adtypes = [
198
206
AutoEnzyme(; mode=Enzyme.Forward);
199
207
sparsity_detector=DenseSparsityDetector(
200
208
AutoEnzyme(; mode=Enzyme.Forward); atol=1e-5
201
- )
209
+ ),
210
+ coloring_algorithm=GreedyColoringAlgorithm(LargestFirst())
202
211
),
203
212
[:enzyme, :approx_sparse]
204
213
),
205
214
(
206
215
AutoPolyesterForwardDiff(; chunksize=8),
207
216
[:polyester, :none]
208
217
),
209
- ]
218
+ ];
210
219
211
- times = Matrix{Float64}(undef, length(Ns), length(adtypes))
220
+ times = Matrix{Float64}(undef, length(Ns), length(adtypes));
212
221
213
222
for (i, N) in enumerate(Ns)
214
223
str = "$(lpad(N, 10)) "
@@ -227,6 +236,7 @@ for (i, N) in enumerate(Ns)
227
236
end
228
237
println(str)
229
238
end
239
+ nothing
230
240
```
231
241
232
242
Plotting the results.
@@ -255,10 +265,11 @@ fig = begin
255
265
colormap=:tableau_20)
256
266
257
267
ax = Axis(fig[1, 2]; title="Scaling of Sparse Jacobian Computation",
258
- titlesize=22, titlegap=10, xscale=log10 , yscale=log10 ,
268
+ titlesize=22, titlegap=10, xscale=log2 , yscale=log2 ,
259
269
xticksize=20, yticksize=20, xticklabelsize=20, yticklabelsize=20,
260
270
xtickwidth=2.5, ytickwidth=2.5, spinewidth=2.5,
261
- xlabel=L"Input Dimension ($\mathbf{N}$)", ylabel=L"Time $\mathbf{(s)}$", xlabelsize=22,
271
+ xlabel=L"Input Dimension ($\mathbf{N}$)",
272
+ ylabel=L"Time $\mathbf{(s)}$", xlabelsize=22,
262
273
ylabelsize=22, yaxisposition=:right)
263
274
264
275
colors = cgrad(:tableau_20, length(adtypes); categorical=true)
@@ -334,7 +345,7 @@ fig = begin
334
345
[symbol_to_adname[adtypes[idx][2][1]] for idx in local_sparse_idxs],
335
346
[symbol_to_adname[adtypes[idx][2][1]] for idx in non_sparse_idxs],
336
347
],
337
- ["Exact Sparsity", "Approx. Local Sparsity", "No Sparsity "];
348
+ ["Exact Sparsity", "Approx. Local Sparsity", "Dense "];
338
349
position=:rb, framevisible=true, framewidth=2.5, titlesize=18,
339
350
labelsize=16, patchsize=(40.0f0, 20.0f0)
340
351
)
@@ -447,9 +458,9 @@ fig = begin
447
458
theme = Theme(Lines = (cycle = cycle,), Scatter = (cycle = cycle,))
448
459
LINESTYLES = Dict(
449
460
(:nonlinearsolve, :none) => :solid,
450
- # (:nonlinearsolve, :approx) => :dash,
451
461
(:nonlinearsolve, :exact) => :dashdot,
452
462
# (:simplenonlinearsolve, :none) => :solid,
463
+ (:wrapper, :exact) => :dash,
453
464
(:wrapper, :none) => :dot,
454
465
)
455
466
@@ -553,20 +564,20 @@ Ns = 2 .^ (2:7)
553
564
solvers_scaling_jacobian_free = [
554
565
(; pkg = :nonlinearsolve, name = "Newton Krylov", alg = NewtonRaphson(; linsolve = KrylovJL_GMRES())),
555
566
(; pkg = :nonlinearsolve, name = "Newton Krylov (ILU)", alg = NewtonRaphson(; linsolve = KrylovJL_GMRES(; precs = incompletelu), concrete_jac = true)),
556
- (; pkg = :nonlinearsolve, name = "Newton Krylov (AMG)", alg = NewtonRaphson(; linsolve = KrylovJL_CG (; precs = algebraicmultigrid), concrete_jac = true)),
557
- (; pkg = :nonlinearsolve, name = "Newton Krylov (AMG Jacobi)", alg = NewtonRaphson(; linsolve = KrylovJL_CG (; precs = algebraicmultigrid_jacobi), concrete_jac = true)),
567
+ (; pkg = :nonlinearsolve, name = "Newton Krylov (AMG)", alg = NewtonRaphson(; linsolve = KrylovJL_GMRES (; precs = algebraicmultigrid), concrete_jac = true)),
568
+ (; pkg = :nonlinearsolve, name = "Newton Krylov (AMG Jacobi)", alg = NewtonRaphson(; linsolve = KrylovJL_GMRES (; precs = algebraicmultigrid_jacobi), concrete_jac = true)),
558
569
(; pkg = :wrapper, name = "Newton Krylov [PETSc]", alg = PETScSNES(; snes_type = "newtonls", snes_linesearch_type = "basic", ksp_type = "gmres", snes_mf = true)),
559
570
(; pkg = :wrapper, name = "Newton Krylov (ILU) [PETSc]", alg = PETScSNES(; snes_type = "newtonls", snes_linesearch_type = "basic", ksp_type = "gmres", pc_type = "ilu")),
560
- (; pkg = :wrapper, name = "Newton Krylov (AMG) [PETSc]", alg = PETScSNES(; snes_type = "newtonls", snes_linesearch_type = "basic", ksp_type = "cg ", pc_type = "gamg")),
561
- (; pkg = :wrapper, name = "Newton Krylov (AMG Jacobi) [PETSc]", alg = PETScSNES(; snes_type = "newtonls", snes_linesearch_type = "basic", ksp_type = "cg ", pc_type = "gamg", mg_levels_ksp_type = "richardson", mg_levels_pc_type = "jacobi")),
571
+ (; pkg = :wrapper, name = "Newton Krylov (AMG) [PETSc]", alg = PETScSNES(; snes_type = "newtonls", snes_linesearch_type = "basic", ksp_type = "gmres ", pc_type = "gamg")),
572
+ (; pkg = :wrapper, name = "Newton Krylov (AMG Jacobi) [PETSc]", alg = PETScSNES(; snes_type = "newtonls", snes_linesearch_type = "basic", ksp_type = "gmres ", pc_type = "gamg", mg_levels_ksp_type = "richardson", mg_levels_pc_type = "jacobi")),
562
573
(; pkg = :nonlinearsolve, name = "TR Krylov", alg = TrustRegion(; linsolve = KrylovJL_GMRES())),
563
574
(; pkg = :nonlinearsolve, name = "TR Krylov (ILU)", alg = TrustRegion(; linsolve = KrylovJL_GMRES(; precs = incompletelu), concrete_jac = true)),
564
- (; pkg = :nonlinearsolve, name = "TR Krylov (AMG)", alg = TrustRegion(; linsolve = KrylovJL_CG (; precs = algebraicmultigrid), concrete_jac = true)),
565
- (; pkg = :nonlinearsolve, name = "TR Krylov (AMG Jacobi)", alg = TrustRegion(; linsolve = KrylovJL_CG (; precs = algebraicmultigrid_jacobi), concrete_jac = true)),
575
+ (; pkg = :nonlinearsolve, name = "TR Krylov (AMG)", alg = TrustRegion(; linsolve = KrylovJL_GMRES (; precs = algebraicmultigrid), concrete_jac = true)),
576
+ (; pkg = :nonlinearsolve, name = "TR Krylov (AMG Jacobi)", alg = TrustRegion(; linsolve = KrylovJL_GMRES (; precs = algebraicmultigrid_jacobi), concrete_jac = true)),
566
577
(; pkg = :wrapper, name = "TR Krylov [PETSc]", alg = PETScSNES(; snes_type = "newtontr", ksp_type = "gmres", snes_mf = true)),
567
578
(; pkg = :wrapper, name = "TR Krylov (ILU) [PETSc]", alg = PETScSNES(; snes_type = "newtontr", ksp_type = "gmres", pc_type = "ilu")),
568
- (; pkg = :wrapper, name = "TR Krylov (AMG) [PETSc]", alg = PETScSNES(; snes_type = "newtontr", ksp_type = "cg ", pc_type = "gamg")),
569
- (; pkg = :wrapper, name = "TR Krylov (AMG Jacobi) [PETSc]", alg = PETScSNES(; snes_type = "newtontr", ksp_type = "cg ", pc_type = "gamg", mg_levels_ksp_type = "richardson", mg_levels_pc_type = "jacobi")),
579
+ (; pkg = :wrapper, name = "TR Krylov (AMG) [PETSc]", alg = PETScSNES(; snes_type = "newtontr", ksp_type = "gmres ", pc_type = "gamg")),
580
+ (; pkg = :wrapper, name = "TR Krylov (AMG Jacobi) [PETSc]", alg = PETScSNES(; snes_type = "newtontr", ksp_type = "gmres ", pc_type = "gamg", mg_levels_ksp_type = "richardson", mg_levels_pc_type = "jacobi")),
570
581
(; pkg = :wrapper, name = "Newton Krylov [Sundials]", alg = KINSOL(; linear_solver = :GMRES)),
571
582
]
572
583
@@ -787,7 +798,7 @@ fig = begin
787
798
cycle = Cycle([:marker], covary = true)
788
799
plot_theme = Theme(Lines = (; cycle), Scatter = (; cycle))
789
800
790
- with_theme(plot_theme) do
801
+ with_theme(plot_theme) do
791
802
fig = Figure(; size = (WIDTH, HEIGHT))
792
803
# `textbf` doesn't work
793
804
ax = Axis(fig[1, 1], ylabel = L"Time $\mathbf{(s)}$",
0 commit comments