Skip to content

Commit d0a6dc7

Browse files
committed
add more message
1 parent 4505591 commit d0a6dc7

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

lib/NonlinearSolveBase/src/autodiff.jl

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@ function select_forward_mode_autodiff(
2323
if warn_check_mode && !(ADTypes.mode(ad) isa ADTypes.ForwardMode) &&
2424
!(ADTypes.mode(ad) isa ADTypes.ForwardOrReverseMode) &&
2525
!is_finite_differences_backend(ad)
26-
@warn "The chosen AD backend $(ad) is not a forward mode AD. Use with caution."
26+
27+
@SciMLMessage("The chosen AD backend $(ad) is not a forward mode AD. Use with caution.",
28+
nonlinear_verbosity[], :fd_ad_caution, :error_control)
29+
2730
end
2831
if incompatible_backend_and_problem(prob, ad)
2932
adₙ = select_forward_mode_autodiff(prob, nothing; warn_check_mode)
30-
@warn "The chosen AD backend `$(ad)` does not support the chosen problem. This \
33+
34+
@SciMLMessage("The chosen AD backend `$(ad)` does not support the chosen problem. This \
3135
could be because the backend package for the chosen AD isn't loaded. After \
3236
running autodiff selection detected `$(adₙ)` as a potential forward mode \
33-
backend."
37+
backend.", nonlinear_verbosity[], :ad_backend_incompatible, :error_control)
38+
3439
return adₙ
3540
end
3641
return ad
@@ -50,14 +55,15 @@ function select_reverse_mode_autodiff(
5055
if warn_check_mode && !(ADTypes.mode(ad) isa ADTypes.ReverseMode) &&
5156
!(ADTypes.mode(ad) isa ADTypes.ForwardOrReverseMode) &&
5257
!is_finite_differences_backend(ad)
53-
@warn "The chosen AD backend $(ad) is not a reverse mode AD. Use with caution."
58+
@SciMLMessage("The chosen AD backend $(ad) is not a forward mode AD. Use with caution.",
59+
nonlinear_verbosity[], :fd_ad_caution, :error_control)
5460
end
5561
if incompatible_backend_and_problem(prob, ad)
5662
adₙ = select_reverse_mode_autodiff(prob, nothing; warn_check_mode)
57-
@warn "The chosen AD backend `$(ad)` does not support the chosen problem. This \
58-
could be because the backend package for the chosen AD isn't loaded. After \
59-
running autodiff selection detected `$(adₙ)` as a potential reverse mode \
60-
backend."
63+
@SciMLMessage("The chosen AD backend `$(ad)` does not support the chosen problem. This \
64+
could be because the backend package for the chosen AD isn't loaded. After \
65+
running autodiff selection detected `$(adₙ)` as a potential forward mode \
66+
backend.", nonlinear_verbosity[], :ad_backend_incompatible, :error_control)
6167
return adₙ
6268
end
6369
return ad
@@ -75,10 +81,10 @@ end
7581
function select_jacobian_autodiff(prob::AbstractNonlinearProblem, ad::AbstractADType)
7682
if incompatible_backend_and_problem(prob, ad)
7783
adₙ = select_jacobian_autodiff(prob, nothing)
78-
@warn "The chosen AD backend `$(ad)` does not support the chosen problem. This \
79-
could be because the backend package for the chosen AD isn't loaded. After \
80-
running autodiff selection detected `$(adₙ)` as a potential jacobian \
81-
backend."
84+
@SciMLMessage("The chosen AD backend `$(ad)` does not support the chosen problem. This \
85+
could be because the backend package for the chosen AD isn't loaded. After \
86+
running autodiff selection detected `$(adₙ)` as a potential forward mode \
87+
backend.", nonlinear_verbosity[], :ad_backend_incompatible, :error_control)
8288
return adₙ
8389
end
8490
return ad

lib/NonlinearSolveBase/src/jacobian.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ function construct_concrete_adtype(f::NonlinearFunction, ad::AbstractADType)
180180
if f.sparsity === nothing
181181
if f.jac_prototype === nothing
182182
if SciMLBase.has_colorvec(f)
183-
@warn "`colorvec` is provided but `sparsity` and `jac_prototype` is not \
184-
specified. `colorvec` will be ignored."
183+
@SciMLMessage("`colorvec` is provided but `sparsity` and `jac_prototype` is not \
184+
specified. `colorvec` will be ignored.", nonlinear_verbosity[], :colorvec_no_prototype, :performance )
185185
end
186186
return ad # No sparse AD
187187
else
188188
if !sparse_or_structured_prototype(f.jac_prototype)
189189
if SciMLBase.has_colorvec(f)
190-
@warn "`colorvec` is provided but `jac_prototype` is not a sparse \
191-
or structured matrix. `colorvec` will be ignored."
190+
@SciMLMessage("`colorvec` is provided but `jac_prototype` is not a sparse \
191+
or structured matrix. `colorvec` will be ignored.", nonlinear_verbosity[], :colorvec_non_sparse, :performance)
192192
end
193193
return ad
194194
end
@@ -223,18 +223,18 @@ function construct_concrete_adtype(f::NonlinearFunction, ad::AbstractADType)
223223
sparsity_detector = f.sparsity
224224
if f.jac_prototype === nothing
225225
if SciMLBase.has_colorvec(f)
226-
@warn "`colorvec` is provided but `jac_prototype` is not specified. \
227-
`colorvec` will be ignored."
226+
@SciMLMessage("`colorvec` is provided but `jac_prototype` is not specified. \
227+
`colorvec` will be ignored.", nonlinear_verbose[], :colorvec_no_prototype, :performance)
228228
end
229229
coloring_algorithm = select_fastest_coloring_algorithm(nothing, f, ad)
230230
coloring_algorithm === nothing && return ad
231231
return AutoSparse(ad; sparsity_detector, coloring_algorithm)
232232
else
233233
if sparse_or_structured_prototype(f.jac_prototype)
234234
if !(sparsity_detector isa NoSparsityDetector)
235-
@warn "`jac_prototype` is a sparse matrix but sparsity = $(f.sparsity) \
235+
@SciMLMessage("`jac_prototype` is a sparse matrix but sparsity = $(f.sparsity) \
236236
has also been specified. Ignoring sparsity field and using \
237-
`jac_prototype` sparsity."
237+
`jac_prototype` sparsity.", nonlinear_verbose[], :sparsity_using_jac_prototype, :performance)
238238
end
239239
sparsity_detector = KnownJacobianSparsityDetector(f.jac_prototype)
240240
end
@@ -255,8 +255,8 @@ end
255255
function select_fastest_coloring_algorithm(
256256
prototype, f::NonlinearFunction, ad::AbstractADType)
257257
if !Utils.is_extension_loaded(Val(:SparseMatrixColorings))
258-
@warn "`SparseMatrixColorings` must be explicitly imported for sparse automatic \
259-
differentiation to work. Proceeding with Dense Automatic Differentiation."
258+
@SciMLMessage("`SparseMatrixColorings` must be explicitly imported for sparse automatic \
259+
differentiation to work. Proceeding with Dense Automatic Differentiation.", :sparse_matrix_colorings_not_loaded, :performance)
260260
return nothing
261261
end
262262
return select_fastest_coloring_algorithm(Val(:SparseMatrixColorings), prototype, f, ad)

lib/NonlinearSolveBase/src/verbosity.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mutable struct NonlinearErrorControlVerbosity
22
immutable_u0::Verbosity.Type
33
non_enclosing_interval::Verbosity.Type
44
non_forward_mode::Verbosity.Type
5+
fd_ad_caution::Verbosity.Type
56
ad_backend_incompatible::Verbosity.Type
67

78
function NonlinearErrorControlVerbosity()
@@ -32,6 +33,10 @@ function NonlinearErrorControlVerbosity(verbose::Verbosity.Type)
3233
end
3334

3435
mutable struct NonlinearPerformanceVerbosity
36+
colorvec_non_sparse::Verbosity.Type
37+
colorvec_no_prototype::Verbosity.Type
38+
sparsity_using_jac_prototype::Verbosity.Type
39+
sparse_matrixcolorings_not_loaded::Verbosity.Type
3540
function NonlinearPerformanceVerbosity()
3641
new()
3742
end

0 commit comments

Comments
 (0)