Skip to content

Commit 798c966

Browse files
committed
refactor: make nothing the default preconditioner
1 parent ea5e0a5 commit 798c966

File tree

12 files changed

+29
-29
lines changed

12 files changed

+29
-29
lines changed

lib/NonlinearSolveBase/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
2323
SciMLJacobianOperators = "19f34311-ddf3-4b8b-af20-060888a46c0e"
2424
SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
2525
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
26+
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
2627
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
2728

2829
[weakdeps]
@@ -67,6 +68,7 @@ SciMLOperators = "0.3.10"
6768
SparseArrays = "1.10"
6869
SparseMatrixColorings = "0.4.8"
6970
StaticArraysCore = "1.4"
71+
SymbolicIndexingInterface = "0.3.31"
7072
Test = "1.10"
7173
TimerOutputs = "0.5.23"
7274
julia = "1.10"

lib/NonlinearSolveBase/src/abstract_types.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module InternalAPI
33
function init end
44
function solve! end
55
function reinit! end
6+
function step! end
67

78
end
89

@@ -134,6 +135,8 @@ for fname in (:preinverted_jacobian, :normal_form)
134135
end
135136
end
136137

138+
139+
137140
"""
138141
AbstractDampingFunction
139142
@@ -145,7 +148,7 @@ Abstract Type for Damping Functions in DampedNewton.
145148
InternalAPI.init(
146149
prob::AbstractNonlinearProblem, f::AbstractDampingFunction, initial_damping,
147150
J, fu, u, args...;
148-
internalnorm::F = L2_NORM, kwargs...
151+
internalnorm = L2_NORM, kwargs...
149152
)::AbstractDampingFunctionCache
150153
```
151154

src/NonlinearSolve.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ using NonlinearSolveBase: NonlinearSolveBase,
2525
AbstractSafeBestNonlinearTerminationMode,
2626
select_forward_mode_autodiff, select_reverse_mode_autodiff,
2727
select_jacobian_autodiff,
28-
construct_linear_solver, construct_jacobian_cache,
28+
construct_jacobian_cache,
2929
DescentResult,
3030
SteepestDescent, NewtonDescent, DampedNewtonDescent, Dogleg,
3131
GeodesicAcceleration,
3232
reset_timer!, @static_timeit
3333

3434
# XXX: Remove
3535
import NonlinearSolveBase: InternalAPI, concrete_jac, supports_line_search,
36-
supports_trust_region, set_du!, last_step_accepted,
37-
get_linear_solver,
36+
supports_trust_region, last_step_accepted, get_linear_solver,
3837
AbstractDampingFunction, AbstractDampingFunctionCache,
3938
requires_normal_form_jacobian, requires_normal_form_rhs,
4039
returns_norm_form_damping, get_timer_output
@@ -59,8 +58,7 @@ using ADTypes: ADTypes, AbstractADType, AutoFiniteDiff, AutoForwardDiff,
5958
using DifferentiationInterface: DifferentiationInterface
6059
using FiniteDiff: FiniteDiff
6160
using ForwardDiff: ForwardDiff, Dual
62-
using SciMLJacobianOperators: AbstractJacobianOperator, VecJacOperator,
63-
JacVecOperator, StatefulJacobianOperator
61+
using SciMLJacobianOperators: VecJacOperator, JacVecOperator, StatefulJacobianOperator
6462

6563
## Sparse AD Support
6664
using SparseArrays: AbstractSparseMatrix, SparseMatrixCSC

src/algorithms/gauss_newton.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
2-
GaussNewton(; concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS,
2+
GaussNewton(; concrete_jac = nothing, linsolve = nothing, precs = nothing,
33
linesearch = nothing, vjp_autodiff = nothing, autodiff = nothing,
44
jvp_autodiff = nothing)
55
66
An advanced GaussNewton implementation with support for efficient handling of sparse
77
matrices via colored automatic differentiation and preconditioned linear solvers. Designed
88
for large-scale and numerically-difficult nonlinear least squares problems.
99
"""
10-
function GaussNewton(; concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS,
10+
function GaussNewton(; concrete_jac = nothing, linsolve = nothing, precs = nothing,
1111
linesearch = nothing, vjp_autodiff = nothing, autodiff = nothing,
1212
jvp_autodiff = nothing)
1313
return GeneralizedFirstOrderAlgorithm{concrete_jac, :GaussNewton}(; linesearch,

src/algorithms/klement.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Klement(; max_resets = 100, linsolve = nothing, linesearch = nothing,
3-
precs = DEFAULT_PRECS, alpha = nothing, init_jacobian::Val = Val(:identity),
3+
precs = nothing, alpha = nothing, init_jacobian::Val = Val(:identity),
44
autodiff = nothing)
55
66
An implementation of `Klement` [klement2014using](@citep) with line search, preconditioning
@@ -25,7 +25,7 @@ over this.
2525
differentiable problems.
2626
"""
2727
function Klement(; max_resets::Int = 100, linsolve = nothing, alpha = nothing,
28-
linesearch = nothing, precs = DEFAULT_PRECS,
28+
linesearch = nothing, precs = nothing,
2929
autodiff = nothing, init_jacobian::Val = Val(:identity))
3030
initialization = klement_init(init_jacobian, autodiff, alpha)
3131
CJ = init_jacobian isa Val{:true_jacobian} ||

src/algorithms/levenberg_marquardt.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
LevenbergMarquardt(; linsolve = nothing,
3-
precs = DEFAULT_PRECS, damping_initial::Real = 1.0, α_geodesic::Real = 0.75,
3+
precs = nothing, damping_initial::Real = 1.0, α_geodesic::Real = 0.75,
44
damping_increase_factor::Real = 2.0, damping_decrease_factor::Real = 3.0,
55
finite_diff_step_geodesic = 0.1, b_uphill::Real = 1.0, autodiff = nothing,
66
min_damping_D::Real = 1e-8, disable_geodesic = Val(false), vjp_autodiff = nothing,
@@ -32,7 +32,7 @@ For the remaining arguments, see [`GeodesicAcceleration`](@ref) and
3232
[`NonlinearSolve.LevenbergMarquardtTrustRegion`](@ref) documentations.
3333
"""
3434
function LevenbergMarquardt(;
35-
linsolve = nothing, precs = DEFAULT_PRECS, damping_initial::Real = 1.0,
35+
linsolve = nothing, precs = nothing, damping_initial::Real = 1.0,
3636
α_geodesic::Real = 0.75, damping_increase_factor::Real = 2.0,
3737
damping_decrease_factor::Real = 3.0, finite_diff_step_geodesic = 0.1,
3838
b_uphill::Real = 1.0, min_damping_D::Real = 1e-8, disable_geodesic = False,

src/algorithms/pseudo_transient.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
PseudoTransient(; concrete_jac = nothing, linsolve = nothing,
3-
linesearch = NoLineSearch(), precs = DEFAULT_PRECS, autodiff = nothing,
3+
linesearch = NoLineSearch(), precs = nothing, autodiff = nothing,
44
jvp_autodiff = nothing, vjp_autodiff = nothing)
55
66
An implementation of PseudoTransient Method [coffey2003pseudotransient](@cite) that is used
@@ -17,7 +17,7 @@ This implementation specifically uses "switched evolution relaxation"
1717
"""
1818
function PseudoTransient(;
1919
concrete_jac = nothing, linsolve = nothing, linesearch = nothing,
20-
precs = DEFAULT_PRECS, alpha_initial = 1e-3, autodiff = nothing,
20+
precs = nothing, alpha_initial = 1e-3, autodiff = nothing,
2121
jvp_autodiff = nothing, vjp_autodiff = nothing)
2222
descent = DampedNewtonDescent(; linsolve, precs, initial_damping = alpha_initial,
2323
damping_fn = SwitchedEvolutionRelaxation())

src/algorithms/raphson.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""
22
NewtonRaphson(; concrete_jac = nothing, linsolve = nothing, linesearch = missing,
3-
precs = DEFAULT_PRECS, autodiff = nothing, vjp_autodiff = nothing,
3+
precs = nothing, autodiff = nothing, vjp_autodiff = nothing,
44
jvp_autodiff = nothing)
55
66
An advanced NewtonRaphson implementation with support for efficient handling of sparse
77
matrices via colored automatic differentiation and preconditioned linear solvers. Designed
88
for large-scale and numerically-difficult nonlinear systems.
99
"""
1010
function NewtonRaphson(; concrete_jac = nothing, linsolve = nothing, linesearch = nothing,
11-
precs = DEFAULT_PRECS, autodiff = nothing, vjp_autodiff = nothing,
11+
precs = nothing, autodiff = nothing, vjp_autodiff = nothing,
1212
jvp_autodiff = nothing)
1313
return GeneralizedFirstOrderAlgorithm{concrete_jac, :NewtonRaphson}(; linesearch,
1414
descent = NewtonDescent(; linsolve, precs), autodiff, vjp_autodiff, jvp_autodiff)

src/algorithms/trust_region.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
TrustRegion(; concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS,
2+
TrustRegion(; concrete_jac = nothing, linsolve = nothing, precs = nothing,
33
radius_update_scheme = RadiusUpdateSchemes.Simple, max_trust_radius::Real = 0 // 1,
44
initial_trust_radius::Real = 0 // 1, step_threshold::Real = 1 // 10000,
55
shrink_threshold::Real = 1 // 4, expand_threshold::Real = 3 // 4,
@@ -20,7 +20,7 @@ for large-scale and numerically-difficult nonlinear systems.
2020
For the remaining arguments, see [`NonlinearSolve.GenericTrustRegionScheme`](@ref)
2121
documentation.
2222
"""
23-
function TrustRegion(; concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS,
23+
function TrustRegion(; concrete_jac = nothing, linsolve = nothing, precs = nothing,
2424
radius_update_scheme = RadiusUpdateSchemes.Simple, max_trust_radius::Real = 0 // 1,
2525
initial_trust_radius::Real = 0 // 1, step_threshold::Real = 1 // 10000,
2626
shrink_threshold::Real = 1 // 4, expand_threshold::Real = 3 // 4,

src/default.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ end
338338

339339
"""
340340
RobustMultiNewton(::Type{T} = Float64; concrete_jac = nothing, linsolve = nothing,
341-
precs = DEFAULT_PRECS, autodiff = nothing)
341+
precs = nothing, autodiff = nothing)
342342
343343
A polyalgorithm focused on robustness. It uses a mixture of Newton methods with different
344344
globalizing techniques (trust region updates, line searches, etc.) in order to find a
@@ -354,7 +354,7 @@ or more precision / more stable linear solver choice is required).
354354
are compatible with the problem type. Defaults to `Float64`.
355355
"""
356356
function RobustMultiNewton(::Type{T} = Float64; concrete_jac = nothing, linsolve = nothing,
357-
precs = DEFAULT_PRECS, autodiff = nothing) where {T}
357+
precs = nothing, autodiff = nothing) where {T}
358358
if __is_complex(T)
359359
# Let's atleast have something here for complex numbers
360360
algs = (NewtonRaphson(; concrete_jac, linsolve, precs, autodiff),)
@@ -375,7 +375,7 @@ end
375375

376376
"""
377377
FastShortcutNonlinearPolyalg(::Type{T} = Float64; concrete_jac = nothing,
378-
linsolve = nothing, precs = DEFAULT_PRECS, must_use_jacobian::Val = Val(false),
378+
linsolve = nothing, precs = nothing, must_use_jacobian::Val = Val(false),
379379
prefer_simplenonlinearsolve::Val{SA} = Val(false), autodiff = nothing,
380380
u0_len::Union{Int, Nothing} = nothing) where {T}
381381
@@ -395,7 +395,7 @@ for more performance and then tries more robust techniques if the faster ones fa
395395
"""
396396
function FastShortcutNonlinearPolyalg(
397397
::Type{T} = Float64; concrete_jac = nothing, linsolve = nothing,
398-
precs = DEFAULT_PRECS, must_use_jacobian::Val{JAC} = Val(false),
398+
precs = nothing, must_use_jacobian::Val{JAC} = Val(false),
399399
prefer_simplenonlinearsolve::Val{SA} = Val(false),
400400
u0_len::Union{Int, Nothing} = nothing, autodiff = nothing) where {T, JAC, SA}
401401
start_index = 1
@@ -457,7 +457,7 @@ end
457457

458458
"""
459459
FastShortcutNLLSPolyalg(::Type{T} = Float64; concrete_jac = nothing, linsolve = nothing,
460-
precs = DEFAULT_PRECS, autodiff = nothing, kwargs...)
460+
precs = nothing, autodiff = nothing, kwargs...)
461461
462462
A polyalgorithm focused on balancing speed and robustness. It first tries less robust methods
463463
for more performance and then tries more robust techniques if the faster ones fail.
@@ -469,7 +469,7 @@ for more performance and then tries more robust techniques if the faster ones fa
469469
"""
470470
function FastShortcutNLLSPolyalg(
471471
::Type{T} = Float64; concrete_jac = nothing, linsolve = nothing,
472-
precs = DEFAULT_PRECS, autodiff = nothing, kwargs...) where {T}
472+
precs = nothing, autodiff = nothing, kwargs...) where {T}
473473
if __is_complex(T)
474474
algs = (GaussNewton(; concrete_jac, linsolve, precs, autodiff, kwargs...),
475475
LevenbergMarquardt(;

src/utils.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Defaults
2-
@inline DEFAULT_PRECS(W, du, u, p, t, newW, Plprev, Prprev, cachedata) = nothing, nothing
3-
41
# Helper Functions
52
@generated function __getproperty(s::S, ::Val{X}) where {S, X}
63
hasfield(S, X) && return :(s.$X)

test/core/rootfind_tests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ end
9696
@test (@ballocated solve!($cache)) < 200
9797
end
9898

99-
precs = [(u0) -> NonlinearSolve.DEFAULT_PRECS,
99+
precs = [(u0) -> nothing,
100100
u0 -> ((args...) -> (Diagonal(rand!(similar(u0))), nothing))]
101101

102102
@testset "[IIP] u0: $(typeof(u0)) precs: $(_nameof(prec)) linsolve: $(_nameof(linsolve))" for u0 in ([
@@ -437,7 +437,7 @@ end
437437
@test (@ballocated solve!($cache)) < 200
438438
end
439439

440-
precs = [NonlinearSolve.DEFAULT_PRECS, :Random]
440+
precs = [nothing, :Random]
441441

442442
@testset "[IIP] u0: $(typeof(u0)) precs: $(_nameof(prec)) linsolve: $(_nameof(linsolve))" for u0 in ([
443443
1.0, 1.0],),

0 commit comments

Comments
 (0)