Skip to content

Commit 1053de8

Browse files
committed
format things related to verbosity
1 parent e2534ae commit 1053de8

12 files changed

+81
-56
lines changed

docs/src/basics/common_solver_opts.md

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,65 +32,72 @@ The verbosity system in LinearSolve.jl provides fine-grained control over the di
3232

3333
The verbosity system is organized hierarchically into three main categories:
3434

35-
1. Error Control - Messages related to fallbacks and error handling
36-
2. Performance - Messages related to performance considerations
37-
3. Numerical - Messages related to numerical solvers and iterations
35+
1. Error Control - Messages related to fallbacks and error handling
36+
2. Performance - Messages related to performance considerations
37+
3. Numerical - Messages related to numerical solvers and iterations
3838

3939
Each category can be configured independently, and individual settings can be adjusted to suit your needs.
4040

4141
### Verbosity Levels
42+
4243
The following verbosity levels are available:
4344

4445
#### Individual Settings
46+
4547
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.
46-
- Verbosity.None() - Suppress all messages
47-
- Verbosity.Info() - Show message as log message at info level
48-
- Verbosity.Warn() - Show warnings (default for most settings)
49-
- Verbosity.Error() - Throw errors instead of warnings
50-
- Verbosity.Level(n) - Show messages with a log level setting of n
48+
49+
- Verbosity.None() - Suppress all messages
50+
- Verbosity.Info() - Show message as log message at info level
51+
- Verbosity.Warn() - Show warnings (default for most settings)
52+
- Verbosity.Error() - Throw errors instead of warnings
53+
- Verbosity.Level(n) - Show messages with a log level setting of n
5154

5255
#### Group Settings
53-
These settings are meant for controlling a group of settings.
54-
- Verbosity.Default() - Use the default settings
55-
- Verbosity.All() - Show all possible messages
5656

57-
### Basic Usage
57+
These settings are meant for controlling a group of settings.
58+
59+
- Verbosity.Default() - Use the default settings
60+
- Verbosity.All() - Show all possible messages
61+
62+
### Basic Usage
5863

5964
#### Global Verbosity Control
6065

61-
```julia
66+
```julia
6267
using LinearSolve
6368

6469
# Suppress all messages
6570
verbose = LinearVerbosity(Verbosity.None())
6671
prob = LinearProblem(A, b)
67-
sol = solve(prob; verbose=verbose)
72+
sol = solve(prob; verbose = verbose)
6873

6974
# Show all messages
7075
verbose = LinearVerbosity(Verbosity.All())
71-
sol = solve(prob; verbose=verbose)
76+
sol = solve(prob; verbose = verbose)
7277

7378
# Use default settings
7479
verbose = LinearVerbosity(Verbosity.Default())
75-
sol = solve(prob; verbose=verbose)
80+
sol = solve(prob; verbose = verbose)
7681
```
7782

78-
#### Group Level Control
83+
#### Group Level Control
7984

80-
```julia
85+
```julia
8186
# Customize by category
8287
verbose = LinearVerbosity(
8388
error_control = Verbosity.Warn(), # Show warnings for error control related issues
8489
performance = Verbosity.None(), # Suppress performance messages
8590
numerical = Verbosity.Info() # Show all numerical related log messages at info level
8691
)
8792

88-
sol = solve(prob; verbose=verbose)
93+
sol = solve(prob; verbose = verbose)
8994
```
9095

9196
#### Fine-grained Control
92-
The constructor for `LinearVerbosity` allows you to set verbosity for each specific message toggle, giving you fine-grained control.
93-
The verbosity settings for the toggles are automatically passed to the group objects.
97+
98+
The constructor for `LinearVerbosity` allows you to set verbosity for each specific message toggle, giving you fine-grained control.
99+
The verbosity settings for the toggles are automatically passed to the group objects.
100+
94101
```julia
95102
# Set specific message types
96103
verbose = LinearVerbosity(
@@ -100,17 +107,23 @@ verbose = LinearVerbosity(
100107
KrylovKit_verbosity = Verbosity.Level(KrylovKit.WARN_LEVEL) # Set KrylovKit verbosity level using KrylovKit's own verbosity levels
101108
)
102109

103-
sol = solve(prob; verbose=verbose)
110+
sol = solve(prob; verbose = verbose)
104111

105112
```
106113

107114
#### Verbosity Levels
115+
108116
##### Error Control Settings
109-
- default_lu_fallback: Controls messages when falling back to LU factorization (default: Warn)
117+
118+
- default_lu_fallback: Controls messages when falling back to LU factorization (default: Warn)
119+
110120
##### Performance Settings
111-
- no_right_preconditioning: Controls messages when right preconditioning is not used (default: Warn)
121+
122+
- no_right_preconditioning: Controls messages when right preconditioning is not used (default: Warn)
123+
112124
##### Numerical Settings
113-
- using_IterativeSolvers: Controls messages when using the IterativeSolvers.jl package (default: Warn)
114-
- IterativeSolvers_iterations: Controls messages about iteration counts from IterativeSolvers.jl (default: Warn)
115-
- KrylovKit_verbosity: Controls messages from the KrylovKit.jl package (default: Warn)
116-
- KrylovJL_verbosity: Controls verbosity of the KrylovJL.jl package (default: None)
125+
126+
- using_IterativeSolvers: Controls messages when using the IterativeSolvers.jl package (default: Warn)
127+
- IterativeSolvers_iterations: Controls messages about iteration counts from IterativeSolvers.jl (default: Warn)
128+
- KrylovKit_verbosity: Controls messages from the KrylovKit.jl package (default: Warn)
129+
- KrylovJL_verbosity: Controls verbosity of the KrylovJL.jl package (default: None)

ext/LinearSolveCUDAExt.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,22 @@ end
5555

5656
function LinearSolve.init_cacheval(
5757
::SparspakFactorization, A::CUDA.CUSPARSE.CuSparseMatrixCSR, b, u,
58-
Pl, Pr, maxiters::Int, abstol, reltol, verbose::LinearVerbosity, assumptions::OperatorAssumptions)
58+
Pl, Pr, maxiters::Int, abstol, reltol,
59+
verbose::LinearVerbosity, assumptions::OperatorAssumptions)
5960
nothing
6061
end
6162

6263
function LinearSolve.init_cacheval(
6364
::KLUFactorization, A::CUDA.CUSPARSE.CuSparseMatrixCSR, b, u,
64-
Pl, Pr, maxiters::Int, abstol, reltol, verbose::LinearVerbosity, assumptions::OperatorAssumptions)
65+
Pl, Pr, maxiters::Int, abstol, reltol,
66+
verbose::LinearVerbosity, assumptions::OperatorAssumptions)
6567
nothing
6668
end
6769

6870
function LinearSolve.init_cacheval(
6971
::UMFPACKFactorization, A::CUDA.CUSPARSE.CuSparseMatrixCSR, b, u,
70-
Pl, Pr, maxiters::Int, abstol, reltol, verbose::LinearVerbosity, assumptions::OperatorAssumptions)
72+
Pl, Pr, maxiters::Int, abstol, reltol,
73+
verbose::LinearVerbosity, assumptions::OperatorAssumptions)
7174
nothing
7275
end
7376

ext/LinearSolveHYPREExt.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ function create_solver(alg::HYPREAlgorithm, cache::LinearCache)
161161

162162
# Construct solver options
163163

164-
165164
verbose = verbosity_to_int(cache.verbose.numerical.HYPRE_verbosity)
166165

167166
solver_options = (;

ext/LinearSolveIterativeSolversExt.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function LinearSolve.init_cacheval(alg::IterativeSolversJL, A, b, u, Pl, Pr, max
6666
kwargs...)
6767
elseif alg.generate_iterator === IterativeSolvers.idrs_iterable!
6868
!!LinearSolve._isidentity_struct(Pr) &&
69-
@SciMLMessage("$(alg.generate_iterator) doesn't support right preconditioning",
69+
@SciMLMessage("$(alg.generate_iterator) doesn't support right preconditioning",
7070
verbose, :no_right_preconditioning, :performance)
7171
history = IterativeSolvers.ConvergenceHistory(partial = true)
7272
history[:abstol] = abstol
@@ -107,11 +107,13 @@ function SciMLBase.solve!(cache::LinearCache, alg::IterativeSolversJL; kwargs...
107107
end
108108
purge_history!(cache.cacheval, cache.u, cache.b)
109109

110-
@SciMLMessage("Using IterativeSolvers.$(alg.generate_iterator)", cache.verbose, :using_IterativeSolvers, :numerical)
110+
@SciMLMessage("Using IterativeSolvers.$(alg.generate_iterator)",
111+
cache.verbose, :using_IterativeSolvers, :numerical)
111112
i = 0
112113
for iter in enumerate(cache.cacheval)
113114
i += 1
114-
@SciMLMessage("Iter: $(iter[1]), residual: $(iter[2])", cache.verbose, :IterativeSolvers_iterations, :numerical)
115+
@SciMLMessage("Iter: $(iter[1]), residual: $(iter[2])",
116+
cache.verbose, :IterativeSolvers_iterations, :numerical)
115117
# TODO inject callbacks KSP into solve! cb!(cache.cacheval)
116118
end
117119

ext/LinearSolveSparseArraysExt.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ using LinearSolve: LinearSolve, BLASELTYPES, pattern_changed, ArrayInterface,
55
GenericLUFactorization,
66
KLUFactorization, LUFactorization, NormalCholeskyFactorization,
77
OperatorAssumptions,
8-
QRFactorization, RFLUFactorization, UMFPACKFactorization, solve, LinearVerbosity
8+
QRFactorization, RFLUFactorization, UMFPACKFactorization, solve,
9+
LinearVerbosity
910
using ArrayInterface: ArrayInterface
1011
using LinearAlgebra: LinearAlgebra, I, Hermitian, Symmetric, cholesky, ldiv!, lu, lu!, QR
1112
using SparseArrays: SparseArrays, AbstractSparseArray, AbstractSparseMatrixCSC,
@@ -289,7 +290,7 @@ function LinearSolve.init_cacheval(alg::CHOLMODFactorization,
289290
Pl, Pr,
290291
maxiters::Int, abstol, reltol,
291292
verbose::LinearVerbosity, assumptions::OperatorAssumptions) where {T <:
292-
Float64}
293+
Float64}
293294
PREALLOCATED_CHOLMOD
294295
end
295296

@@ -298,7 +299,7 @@ function LinearSolve.init_cacheval(alg::CHOLMODFactorization,
298299
Pl, Pr,
299300
maxiters::Int, abstol, reltol,
300301
verbose::LinearVerbosity, assumptions::OperatorAssumptions) where {T <:
301-
BLASELTYPES}
302+
BLASELTYPES}
302303
cholesky(sparse(reshape([one(T)], 1, 1)))
303304
end
304305

src/LinearSolve.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ using SciMLBase: SciMLBase, LinearAliasSpecifier, AbstractSciMLOperator,
2121
using SciMLOperators: SciMLOperators, AbstractSciMLOperator, IdentityOperator,
2222
MatrixOperator,
2323
has_ldiv!, issquare
24-
using SciMLVerbosity: Verbosity, @SciMLMessage, @match, AbstractVerbositySpecifier, verbosity_to_int
24+
using SciMLVerbosity: Verbosity, @SciMLMessage, @match, AbstractVerbositySpecifier,
25+
verbosity_to_int
2526
using Setfield: @set, @set!
2627
using UnPack: @unpack
2728
using DocStringExtensions: DocStringExtensions
@@ -231,7 +232,8 @@ error_no_cudss_lu(A) = nothing
231232
cudss_loaded(A) = false
232233
is_cusparse(A) = false
233234

234-
export LinearVerbosity, LinearErrorControlVerbosity, LinearPerformanceVerbosity, LinearNumericalVerbosity
235+
export LinearVerbosity, LinearErrorControlVerbosity, LinearPerformanceVerbosity,
236+
LinearNumericalVerbosity
235237

236238
export LUFactorization, SVDFactorization, QRFactorization, GenericFactorization,
237239
GenericLUFactorization, SimpleLUFactorization, RFLUFactorization,

src/default.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ end
365365
newex = quote
366366
sol = SciMLBase.solve!(cache, $(algchoice_to_alg(alg)), args...; kwargs...)
367367
if sol.retcode === ReturnCode.Failure && alg.safetyfallback
368-
@SciMLMessage("LU factorization failed, falling back to QR factorization. `A` is potentially rank-deficient.",
369-
cache.verbose, :default_lu_fallback, :error_control)
368+
@SciMLMessage("LU factorization failed, falling back to QR factorization. `A` is potentially rank-deficient.",
369+
cache.verbose, :default_lu_fallback, :error_control)
370370

371371
sol = SciMLBase.solve!(
372372
cache, QRFactorization(ColumnNorm()), args...; kwargs...)

src/factorization.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ function init_cacheval(alg::CholeskyFactorization, A::SMatrix{S1, S2}, b, u, Pl,
385385
end
386386

387387
function init_cacheval(alg::CholeskyFactorization, A::GPUArraysCore.AnyGPUArray, b, u, Pl,
388-
Pr, maxiters::Int, abstol, reltol, verbose::LinearVerbosity, assumptions::OperatorAssumptions)
388+
Pr, maxiters::Int, abstol, reltol, verbose::LinearVerbosity,
389+
assumptions::OperatorAssumptions)
389390
cholesky(A; check = false)
390391
end
391392

src/iterative_wrappers.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,5 +335,3 @@ function SciMLBase.solve!(cache::LinearCache, alg::KrylovJL; kwargs...)
335335
return SciMLBase.build_linear_solution(alg, cache.u, Ref(resid), cache;
336336
iters = stats.niter, retcode, stats)
337337
end
338-
339-

src/verbosity.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,4 @@ function LinearVerbosity(;
181181

182182
LinearVerbosity{true}(error_control_verbosity,
183183
performance_verbosity, numerical_verbosity)
184-
end
184+
end

0 commit comments

Comments
 (0)