Skip to content

Commit e78048b

Browse files
Use verbosity system (#622)
* add SciMLLogging * add verbosity types * replace verbose::Bool with verbose::LinearVerbosity * export symbols, include verbosity.jl * add verbosity documentation * add verbosity to IterativeSolversExt * add verbosity to KrylovKitExt * add verbose to PardisoExt * add verbose to HYPREExt * add verbose for iterative solvers * bring in LinearVerbosity * imports * fix default * add tests * make verbose = Bool also valid for backwards compat * allow bool verbose * fix _init_cacheval * fix verbose for HYPRE * add compat for SciMLLogging * get rid of stale import * Update runtests.jl * change bool to LinearVerbosity * add messages for fallbacks --------- Co-authored-by: Christopher Rackauckas <[email protected]>
1 parent ff7947f commit e78048b

31 files changed

+539
-186
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Preferences = "21216c6a-2e73-6563-6e65-726566657250"
2222
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
2323
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2424
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
25+
SciMLLogging = "a6db7da4-7206-11f0-1eab-35f2a5dbe1d1"
2526
SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
2627
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
2728
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
@@ -122,6 +123,7 @@ Reexport = "1.2.2"
122123
SafeTestsets = "0.1"
123124
SciMLBase = "2.70"
124125
SciMLOperators = "1"
126+
SciMLLogging = "1"
125127
Setfield = "1.1.1"
126128
SparseArrays = "1.10"
127129
Sparspak = "0.3.9"

docs/src/advanced/developing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct MyLUFactorization{P} <: LinearSolve.SciMLLinearSolveAlgorithm end
1919

2020
function LinearSolve.init_cacheval(
2121
alg::MyLUFactorization, A, b, u, Pl, Pr, maxiters::Int, abstol, reltol,
22-
verbose::Bool, assump::LinearSolve.OperatorAssumptions)
22+
verbose::LinearVerbosity, assump::LinearSolve.OperatorAssumptions)
2323
lu!(convert(AbstractMatrix, A))
2424
end
2525

docs/src/basics/common_solver_opts.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,92 @@ solve completely. Error controls only apply to iterative solvers.
2626
- `maxiters`: The number of iterations allowed. Defaults to `length(prob.b)`
2727
- `Pl,Pr`: The left and right preconditioners, respectively. For more information,
2828
see [the Preconditioners page](@ref prec).
29+
30+
## Verbosity Controls
31+
32+
The verbosity system in LinearSolve.jl provides fine-grained control over the diagnostic messages, warnings, and errors that are displayed during the solution of linear systems.
33+
34+
The verbosity system is organized hierarchically into three main categories:
35+
36+
1. Error Control - Messages related to fallbacks and error handling
37+
2. Performance - Messages related to performance considerations
38+
3. Numerical - Messages related to numerical solvers and iterations
39+
40+
Each category can be configured independently, and individual settings can be adjusted to suit your needs.
41+
42+
### Verbosity Levels
43+
The following verbosity levels are available:
44+
45+
#### Individual Settings
46+
These settings are meant for individual settings within a category. These can also be used to set all of the individual settings in a group to the same value.
47+
- Verbosity.None() - Suppress all messages
48+
- Verbosity.Info() - Show message as log message at info level
49+
- Verbosity.Warn() - Show warnings (default for most settings)
50+
- Verbosity.Error() - Throw errors instead of warnings
51+
- Verbosity.Level(n) - Show messages with a log level setting of n
52+
53+
#### Group Settings
54+
These settings are meant for controlling a group of settings.
55+
- Verbosity.Default() - Use the default settings
56+
- Verbosity.All() - Show all possible messages
57+
58+
### Basic Usage
59+
60+
#### Global Verbosity Control
61+
62+
```julia
63+
using LinearSolve
64+
65+
# Suppress all messages
66+
verbose = LinearVerbosity(Verbosity.None())
67+
prob = LinearProblem(A, b)
68+
sol = solve(prob; verbose=verbose)
69+
70+
# Show all messages
71+
verbose = LinearVerbosity(Verbosity.All())
72+
sol = solve(prob; verbose=verbose)
73+
74+
# Use default settings
75+
verbose = LinearVerbosity(Verbosity.Default())
76+
sol = solve(prob; verbose=verbose)
77+
```
78+
79+
#### Group Level Control
80+
81+
```julia
82+
# Customize by category
83+
verbose = LinearVerbosity(
84+
error_control = Verbosity.Warn(), # Show warnings for error control related issues
85+
performance = Verbosity.None(), # Suppress performance messages
86+
numerical = Verbosity.Info() # Show all numerical related log messages at info level
87+
)
88+
89+
sol = solve(prob; verbose=verbose)
90+
```
91+
92+
#### Fine-grained Control
93+
The constructor for `LinearVerbosity` allows you to set verbosity for each specific message toggle, giving you fine-grained control.
94+
The verbosity settings for the toggles are automatically passed to the group objects.
95+
```julia
96+
# Set specific message types
97+
verbose = LinearVerbosity(
98+
default_lu_fallback = Verbosity.Info(), # Show info when LU fallback is used
99+
KrylovJL_verbosity = Verbosity.Warn(), # Show warnings from KrylovJL
100+
no_right_preconditioning = Verbosity.None(), # Suppress right preconditioning messages
101+
KrylovKit_verbosity = Verbosity.Level(KrylovKit.WARN_LEVEL) # Set KrylovKit verbosity level using KrylovKit's own verbosity levels
102+
)
103+
104+
sol = solve(prob; verbose=verbose)
105+
106+
```
107+
108+
#### Verbosity Levels
109+
##### Error Control Settings
110+
- default_lu_fallback: Controls messages when falling back to LU factorization (default: Warn)
111+
##### Performance Settings
112+
- no_right_preconditioning: Controls messages when right preconditioning is not used (default: Warn)
113+
##### Numerical Settings
114+
- using_IterativeSolvers: Controls messages when using the IterativeSolvers.jl package (default: Warn)
115+
- IterativeSolvers_iterations: Controls messages about iteration counts from IterativeSolvers.jl (default: Warn)
116+
- KrylovKit_verbosity: Controls messages from the KrylovKit.jl package (default: Warn)
117+
- KrylovJL_verbosity: Controls verbosity of the KrylovJL.jl package (default: None)

ext/LinearSolveAMDGPUExt.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::AMDGPUOffloadLUFa
2525
end
2626

2727
function LinearSolve.init_cacheval(alg::AMDGPUOffloadLUFactorization, A, b, u, Pl, Pr,
28-
maxiters::Int, abstol, reltol, verbose::Bool,
28+
maxiters::Int, abstol, reltol, verbose::LinearVerbosity,
2929
assumptions::OperatorAssumptions)
3030
AMDGPU.rocSOLVER.getrf!(AMDGPU.ROCArray(A))
3131
end
@@ -57,7 +57,7 @@ function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::AMDGPUOffloadQRFa
5757
end
5858

5959
function LinearSolve.init_cacheval(alg::AMDGPUOffloadQRFactorization, A, b, u, Pl, Pr,
60-
maxiters::Int, abstol, reltol, verbose::Bool,
60+
maxiters::Int, abstol, reltol, verbose::LinearVerbosity,
6161
assumptions::OperatorAssumptions)
6262
A_gpu = AMDGPU.ROCArray(A)
6363
tau = AMDGPU.ROCVector{eltype(A_gpu)}(undef, min(size(A_gpu)...))

ext/LinearSolveBLISExt.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ const PREALLOCATED_BLIS_LU = begin
204204
end
205205

206206
function LinearSolve.init_cacheval(alg::BLISLUFactorization, A, b, u, Pl, Pr,
207-
maxiters::Int, abstol, reltol, verbose::Bool,
207+
maxiters::Int, abstol, reltol, verbose::LinearVerbosity,
208208
assumptions::OperatorAssumptions)
209209
PREALLOCATED_BLIS_LU
210210
end
211211

212212
function LinearSolve.init_cacheval(alg::BLISLUFactorization, A::AbstractMatrix{<:Union{Float32,ComplexF32,ComplexF64}}, b, u, Pl, Pr,
213-
maxiters::Int, abstol, reltol, verbose::Bool,
213+
maxiters::Int, abstol, reltol, verbose::LinearVerbosity,
214214
assumptions::OperatorAssumptions)
215215
A = rand(eltype(A), 0, 0)
216216
ArrayInterface.lu_instance(A), Ref{BlasInt}()

ext/LinearSolveBandedMatricesExt.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ for alg in (:SVDFactorization, :MKLLUFactorization, :DiagonalFactorization,
4141
:AppleAccelerateLUFactorization, :CholeskyFactorization)
4242
@eval begin
4343
function init_cacheval(::$(alg), ::BandedMatrix, b, u, Pl, Pr, maxiters::Int,
44-
abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions)
44+
abstol, reltol, verbose::LinearVerbosity, assumptions::OperatorAssumptions)
4545
return nothing
4646
end
4747
end
4848
end
4949

5050
function init_cacheval(::LUFactorization, A::BandedMatrix{T}, b, u, Pl, Pr, maxiters::Int,
51-
abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions) where {T}
51+
abstol, reltol, verbose::LinearVerbosity, assumptions::OperatorAssumptions) where {T}
5252
(T <: BigFloat) && return qr(similar(A, 0, 0))
5353
return lu(similar(A, 0, 0))
5454
end
@@ -61,7 +61,7 @@ for alg in (:SVDFactorization, :MKLLUFactorization, :DiagonalFactorization,
6161
:AppleAccelerateLUFactorization, :QRFactorization, :LUFactorization)
6262
@eval begin
6363
function init_cacheval(::$(alg), ::Symmetric{<:Number, <:BandedMatrix}, b, u, Pl,
64-
Pr, maxiters::Int, abstol, reltol, verbose::Bool,
64+
Pr, maxiters::Int, abstol, reltol, verbose::LinearVerbosity,
6565
assumptions::OperatorAssumptions)
6666
return nothing
6767
end

ext/LinearSolveCUDAExt.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::CudaOffloadLUFact
5050
end
5151

5252
function LinearSolve.init_cacheval(alg::CudaOffloadLUFactorization, A, b, u, Pl, Pr,
53-
maxiters::Int, abstol, reltol, verbose::Bool,
53+
maxiters::Int, abstol, reltol, verbose::LinearVerbosity,
5454
assumptions::OperatorAssumptions)
5555
T = eltype(A)
5656
noUnitT = typeof(zero(T))
@@ -73,7 +73,7 @@ function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::CudaOffloadQRFact
7373
end
7474

7575
function LinearSolve.init_cacheval(alg::CudaOffloadQRFactorization, A, b, u, Pl, Pr,
76-
maxiters::Int, abstol, reltol, verbose::Bool,
76+
maxiters::Int, abstol, reltol, verbose::LinearVerbosity,
7777
assumptions::OperatorAssumptions)
7878
qr(CUDA.CuArray(A))
7979
end
@@ -92,26 +92,26 @@ function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::CudaOffloadFactor
9292
end
9393

9494
function LinearSolve.init_cacheval(alg::CudaOffloadFactorization, A, b, u, Pl, Pr,
95-
maxiters::Int, abstol, reltol, verbose::Bool,
95+
maxiters::Int, abstol, reltol, verbose::LinearVerbosity,
9696
assumptions::OperatorAssumptions)
9797
qr(CUDA.CuArray(A))
9898
end
9999

100100
function LinearSolve.init_cacheval(
101101
::SparspakFactorization, A::CUDA.CUSPARSE.CuSparseMatrixCSR, b, u,
102-
Pl, Pr, maxiters::Int, abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions)
102+
Pl, Pr, maxiters::Int, abstol, reltol, verbose::LinearVerbosity, assumptions::OperatorAssumptions)
103103
nothing
104104
end
105105

106106
function LinearSolve.init_cacheval(
107107
::KLUFactorization, A::CUDA.CUSPARSE.CuSparseMatrixCSR, b, u,
108-
Pl, Pr, maxiters::Int, abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions)
108+
Pl, Pr, maxiters::Int, abstol, reltol, verbose::LinearVerbosity, assumptions::OperatorAssumptions)
109109
nothing
110110
end
111111

112112
function LinearSolve.init_cacheval(
113113
::UMFPACKFactorization, A::CUDA.CUSPARSE.CuSparseMatrixCSR, b, u,
114-
Pl, Pr, maxiters::Int, abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions)
114+
Pl, Pr, maxiters::Int, abstol, reltol, verbose::LinearVerbosity, assumptions::OperatorAssumptions)
115115
nothing
116116
end
117117

ext/LinearSolveCUSOLVERRFExt.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ using SciMLBase: SciMLBase, LinearProblem, ReturnCode
1010
function LinearSolve.init_cacheval(alg::LinearSolve.CUSOLVERRFFactorization,
1111
A, b, u, Pl, Pr,
1212
maxiters::Int, abstol, reltol,
13-
verbose::Bool, assumptions::OperatorAssumptions)
13+
verbose::LinearVerbosity, assumptions::OperatorAssumptions)
1414
nothing
1515
end
1616

1717
function LinearSolve.init_cacheval(alg::LinearSolve.CUSOLVERRFFactorization,
1818
A::Union{CuSparseMatrixCSR{Float64, Int32}, SparseMatrixCSC{Float64, <:Integer}},
1919
b, u, Pl, Pr,
2020
maxiters::Int, abstol, reltol,
21-
verbose::Bool, assumptions::OperatorAssumptions)
21+
verbose::LinearVerbosity, assumptions::OperatorAssumptions)
2222
# Create initial factorization with appropriate options
2323
nrhs = b isa AbstractMatrix ? size(b, 2) : 1
2424
symbolic = alg.symbolic

ext/LinearSolveCliqueTreesExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ end
2222

2323
function LinearSolve.init_cacheval(
2424
alg::CliqueTreesFactorization, A::AbstractMatrix, b, u, Pl, Pr, maxiters::Int, abstol,
25-
reltol, verbose::Bool, assumptions::OperatorAssumptions)
25+
reltol, verbose::LinearVerbosity, assumptions::OperatorAssumptions)
2626
symbfact = _symbolic(A, alg)
2727
cholfact, cholwork = cholinit(A, symbfact)
2828
linwork = lininit(1, cholfact)

ext/LinearSolveFastAlmostBandedMatricesExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ for alg in (:SVDFactorization, :MKLLUFactorization, :DiagonalFactorization,
2121
:AppleAccelerateLUFactorization, :CholeskyFactorization, :LUFactorization)
2222
@eval begin
2323
function init_cacheval(::$(alg), ::AlmostBandedMatrix, b, u, Pl, Pr, maxiters::Int,
24-
abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions)
24+
abstol, reltol, verbose::LinearVerbosity, assumptions::OperatorAssumptions)
2525
return nothing
2626
end
2727
end

0 commit comments

Comments
 (0)