Skip to content

Commit 5c86b7b

Browse files
committed
fix: use enzyme for the battery problem
1 parent 2471352 commit 5c86b7b

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

benchmarks/NonlinearProblem/Manifest.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,9 +2569,7 @@ version = "7.2.1+1"
25692569

25702570
[[deps.Sundials]]
25712571
deps = ["CEnum", "DataStructures", "DiffEqBase", "Libdl", "LinearAlgebra", "Logging", "PrecompileTools", "Reexport", "SciMLBase", "SparseArrays", "Sundials_jll"]
2572-
git-tree-sha1 = "87b22845424e6c79fa0dadea81880a17759e701a"
2573-
repo-rev = "ap/kinsol_newton"
2574-
repo-url = "https://github.com/SciML/Sundials.jl.git"
2572+
git-tree-sha1 = "7c7a7ee705724b3c80d5451ac49779db36c6f758"
25752573
uuid = "c3572dad-4567-51f8-b174-8c6c989267f4"
25762574
version = "4.28.0"
25772575

benchmarks/NonlinearProblem/Project.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,3 @@ StableRNGs = "1"
6060
StaticArrays = "1"
6161
Sundials = "4.22"
6262
Symbolics = "5, 6"
63-
64-
[sources]
65-
Sundials = {url = "https://github.com/SciML/Sundials.jl", rev = "ap/kinsol_newton"}

benchmarks/NonlinearProblem/nonlinear_battery_problem.jmd

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Doyle-Fuller-Newman (DFN) Battery Model Initialization
33
author: Marc D. Berliner & Avik Pal
4-
priority: 10000
4+
priority: 50000000
55
---
66

77
These benchmarks compares the runtime and error for a range of nonlinear solvers. The solvers are implemented in [NonlinearProblemLibrary.jl](https://github.com/SciML/DiffEqProblemLibrary.jl/blob/master/lib/NonlinearProblemLibrary/src/NonlinearProblemLibrary.jl), where you can find the problem function declarations. We test the following solvers:
@@ -23,7 +23,7 @@ Fetch required packages.
2323
```julia
2424
using NonlinearSolve, LinearSolve, StaticArrays, Sundials, SpeedMapping,
2525
BenchmarkTools, LinearAlgebra, DiffEqDevTools, PolyesterForwardDiff, CairoMakie,
26-
RecursiveFactorization
26+
RecursiveFactorization, Enzyme
2727
import MINPACK, NLsolve, PETSc
2828
import LineSearches
2929

@@ -39,38 +39,43 @@ MoreThuente() = LineSearchesJL(; method = LineSearches.MoreThuente())
3939
GC.enable(false) # for PETSc
4040

4141
solvers_all = [
42-
(; pkg = :nonlinearsolve, name = "Default PolyAlgorithm", solver = Dict(:alg => FastShortcutNonlinearPolyalg())),
43-
(; pkg = :nonlinearsolve, name = "Newton Raphson", solver = Dict(:alg => NewtonRaphson())),
44-
(; pkg = :nonlinearsolve, name = "Newton Raphson (HagerZhang LineSearch)", solver = Dict(:alg => NewtonRaphson(; linesearch = HagerZhang()))),
45-
(; pkg = :nonlinearsolve, name = "Newton Raphson (MoreThuente LineSearch)", solver = Dict(:alg => NewtonRaphson(; linesearch = MoreThuente()))),
46-
(; pkg = :nonlinearsolve, name = "Newton Raphson (BackTracking LineSearch)", solver = Dict(:alg => NewtonRaphson(; linesearch = BackTracking()))),
47-
(; pkg = :nonlinearsolve, name = "Newton Krylov with GMRES", solver = Dict(:alg => NewtonRaphson(; linsolve = KrylovJL_GMRES()))),
42+
(; pkg = :nonlinearsolve, name = "Default PolyAlgorithm", solver = Dict(:alg => FastShortcutNonlinearPolyalg(; autodiff = AutoEnzyme()))),
43+
(; pkg = :nonlinearsolve, name = "Newton Raphson", solver = Dict(:alg => NewtonRaphson(; autodiff = AutoEnzyme()))),
44+
(; pkg = :nonlinearsolve, name = "Newton Raphson (HagerZhang LineSearch)", solver = Dict(:alg => NewtonRaphson(; linesearch = HagerZhang(), autodiff = AutoEnzyme()))),
45+
(; pkg = :nonlinearsolve, name = "Newton Raphson (MoreThuente LineSearch)", solver = Dict(:alg => NewtonRaphson(; linesearch = MoreThuente(), autodiff = AutoEnzyme()))),
46+
(; pkg = :nonlinearsolve, name = "Newton Raphson (BackTracking LineSearch)", solver = Dict(:alg => NewtonRaphson(; linesearch = BackTracking(), autodiff = AutoEnzyme()))),
47+
(; pkg = :nonlinearsolve, name = "Newton Krylov with GMRES", solver = Dict(:alg => NewtonRaphson(; linsolve = KrylovJL_GMRES(), autodiff = AutoEnzyme()))),
4848
(; pkg = :nonlinearsolve, name = "DFSane", solver = Dict(:alg => DFSane())),
49-
(; pkg = :nonlinearsolve, name = "Trust Region", solver = Dict(:alg => TrustRegion())),
50-
(; pkg = :nonlinearsolve, name = "Trust Region (NLsolve Update)", solver = Dict(:alg => TrustRegion(; radius_update_scheme = RUS.NLsolve))),
51-
(; pkg = :nonlinearsolve, name = "Trust Region (Nocedal Wright)", solver = Dict(:alg => TrustRegion(; radius_update_scheme = RUS.NocedalWright))),
52-
(; pkg = :nonlinearsolve, name = "Trust Region (Hei)", solver = Dict(:alg => TrustRegion(; radius_update_scheme = RUS.Hei))),
53-
(; pkg = :nonlinearsolve, name = "Trust Region (Yuan)", solver = Dict(:alg => TrustRegion(; radius_update_scheme = RUS.Yuan))),
54-
(; pkg = :nonlinearsolve, name = "Trust Region (Bastin)", solver = Dict(:alg => TrustRegion(; radius_update_scheme = RUS.Bastin))),
55-
(; pkg = :nonlinearsolve, name = "Trust Region (Fan)", solver = Dict(:alg => TrustRegion(; radius_update_scheme = RUS.Fan))),
56-
(; pkg = :nonlinearsolve, name = "Levenberg-Marquardt", solver = Dict(:alg => LevenbergMarquardt())),
57-
(; pkg = :nonlinearsolve, name = "Levenberg-Marquardt with Cholesky", solver = Dict(:alg => LevenbergMarquardt(; linsolve = CholeskyFactorization()))),
58-
(; pkg = :nonlinearsolve, name = "Levenberg-Marquardt (No Geodesic Accln.)", solver = Dict(:alg => LevenbergMarquardt(; disable_geodesic = Val(true)))),
59-
(; pkg = :nonlinearsolve, name = "Levenberg-Marquardt (No Geodesic Accln.) with Cholesky", solver = Dict(:alg => LevenbergMarquardt(; disable_geodesic = Val(true), linsolve = CholeskyFactorization()))),
49+
(; pkg = :nonlinearsolve, name = "Trust Region", solver = Dict(:alg => TrustRegion(; autodiff = AutoEnzyme()))),
50+
(; pkg = :nonlinearsolve, name = "Trust Region (NLsolve Update)", solver = Dict(:alg => TrustRegion(; radius_update_scheme = RUS.NLsolve, autodiff = AutoEnzyme()))),
51+
(; pkg = :nonlinearsolve, name = "Trust Region (Nocedal Wright)", solver = Dict(:alg => TrustRegion(; radius_update_scheme = RUS.NocedalWright, autodiff = AutoEnzyme()))),
52+
(; pkg = :nonlinearsolve, name = "Trust Region (Hei)", solver = Dict(:alg => TrustRegion(; radius_update_scheme = RUS.Hei, autodiff = AutoEnzyme()))),
53+
(; pkg = :nonlinearsolve, name = "Trust Region (Yuan)", solver = Dict(:alg => TrustRegion(; radius_update_scheme = RUS.Yuan, autodiff = AutoEnzyme()))),
54+
(; pkg = :nonlinearsolve, name = "Trust Region (Bastin)", solver = Dict(:alg => TrustRegion(; radius_update_scheme = RUS.Bastin, autodiff = AutoEnzyme()))),
55+
(; pkg = :nonlinearsolve, name = "Trust Region (Fan)", solver = Dict(:alg => TrustRegion(; radius_update_scheme = RUS.Fan, autodiff = AutoEnzyme()))),
56+
(; pkg = :nonlinearsolve, name = "Levenberg-Marquardt", solver = Dict(:alg => LevenbergMarquardt(; autodiff = AutoEnzyme()))),
57+
(; pkg = :nonlinearsolve, name = "Levenberg-Marquardt with Cholesky", solver = Dict(:alg => LevenbergMarquardt(; linsolve = CholeskyFactorization(), autodiff = AutoEnzyme()))),
58+
(; pkg = :nonlinearsolve, name = "Levenberg-Marquardt (No Geodesic Accln.)", solver = Dict(:alg => LevenbergMarquardt(; disable_geodesic = Val(true), autodiff = AutoEnzyme()))),
59+
(; pkg = :nonlinearsolve, name = "Levenberg-Marquardt (No Geodesic Accln.) with Cholesky", solver = Dict(:alg => LevenbergMarquardt(; disable_geodesic = Val(true), linsolve = CholeskyFactorization(), autodiff = AutoEnzyme()))),
60+
61+
(; pkg = :wrapper, name = "Newton Raphson [Sundials]", solver = Dict(:alg => KINSOL(; linear_solver = :LapackDense, maxsetupcalls=1))),
62+
(; pkg = :wrapper, name = "Newton Krylov [Sundials]", solver = Dict(:alg => KINSOL(; linear_solver = :GMRES, maxsetupcalls=1))),
63+
(; pkg = :wrapper, name = "Newton Raphson with LineSearch [Sundials]", solver = Dict(:alg => KINSOL(; globalization_strategy = :LineSearch, maxsetupcalls=1))),
64+
65+
(; pkg = :wrapper, name = "Newton Raphson [NLsolve.jl]", solver = Dict(:alg => NLsolveJL(; method = :newton, autodiff = :forward))),
66+
(; pkg = :wrapper, name = "Trust Region [NLsolve.jl]", solver = Dict(:alg => NLsolveJL(; autodiff = :forward))),
67+
68+
(; pkg = :wrapper, name = "Modified Powell [MINPACK]", solver = Dict(:alg => CMINPACK(; method = :hybr))),
69+
(; pkg = :wrapper, name = "Levenberg-Marquardt [MINPACK]", solver = Dict(:alg => CMINPACK(; method = :lm))),
70+
71+
(; pkg = :wrapper, name = "Speed Mapping [SpeedMapping.jl]", solver = Dict(:alg => SpeedMappingJL())),
72+
6073
(; pkg = :wrapper, name = "Newton Raphson [PETSc]", solver = Dict(:alg => PETScSNES(; snes_type = "newtonls", snes_linesearch_type = "basic"))),
6174
(; pkg = :wrapper, name = "Newton Raphson with QR [PETSc]", solver = Dict(:alg => PETScSNES(; snes_type = "newtonls", snes_linesearch_type = "basic", pc_type = "qr"))),
6275
(; pkg = :wrapper, name = "Newton Raphson with BackTracking [PETSc]", solver = Dict(:alg => PETScSNES(; snes_type = "newtonls"))),
6376
(; pkg = :wrapper, name = "Newton Raphson with BackTracking & QR [PETSc]", solver = Dict(:alg => PETScSNES(; snes_type = "newtonls", pc_type = "qr"))),
6477
(; pkg = :wrapper, name = "Trust Region [PETSc]", solver = Dict(:alg => PETScSNES(; snes_type = "newtontr"))),
6578
(; pkg = :wrapper, name = "Newton Krylov with GMRES [PETSc]", solver = Dict(:alg => PETScSNES(; snes_type = "newtonls", snes_linesearch_type = "basic", ksp_type = "gmres"))),
66-
(; pkg = :wrapper, name = "Modified Powell [MINPACK]", solver = Dict(:alg => CMINPACK(; method = :hybr))),
67-
(; pkg = :wrapper, name = "Levenberg-Marquardt [MINPACK]", solver = Dict(:alg => CMINPACK(; method = :lm))),
68-
(; pkg = :wrapper, name = "Newton Raphson [NLsolve.jl]", solver = Dict(:alg => NLsolveJL(; method = :newton, autodiff = :forward))),
69-
(; pkg = :wrapper, name = "Trust Region [NLsolve.jl]", solver = Dict(:alg => NLsolveJL(; autodiff = :forward))),
70-
(; pkg = :wrapper, name = "Newton Raphson [Sundials]", solver = Dict(:alg => KINSOL(; linear_solver = :LapackDense, maxsetupcalls=1))),
71-
(; pkg = :wrapper, name = "Newton Krylov [Sundials]", solver = Dict(:alg => KINSOL(; linear_solver = :GMRES, maxsetupcalls=1))),
72-
(; pkg = :wrapper, name = "Newton Raphson with LineSearch [Sundials]", solver = Dict(:alg => KINSOL(; globalization_strategy = :LineSearch, maxsetupcalls=1))),
73-
(; pkg = :wrapper, name = "Speed Mapping [SpeedMapping.jl]", solver = Dict(:alg => SpeedMappingJL())),
7479
];
7580
```
7681

0 commit comments

Comments
 (0)