Skip to content

Commit b703efc

Browse files
committed
make LinearVerbosity concrete, remove setproperty!
1 parent 49fa2f8 commit b703efc

File tree

2 files changed

+39
-140
lines changed

2 files changed

+39
-140
lines changed

src/verbosity.jl

Lines changed: 34 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
mutable struct LinearVerbosity{Enabled} <: AbstractVerbositySpecifier{Enabled}
1+
LinearSolve.@concrete struct LinearVerbosity{Enabled} <:
2+
AbstractVerbositySpecifier{Enabled}
23
# Error control
3-
default_lu_fallback::MessageLevel
4+
default_lu_fallback
45
# Performance
5-
no_right_preconditioning::MessageLevel
6+
no_right_preconditioning
67
# Numerical
7-
using_iterative_solvers::MessageLevel
8-
using_IterativeSolvers::MessageLevel
9-
IterativeSolvers_iterations::MessageLevel
10-
KrylovKit_verbosity::MessageLevel
11-
KrylovJL_verbosity::MessageLevel
12-
HYPRE_verbosity::MessageLevel
13-
pardiso_verbosity::MessageLevel
14-
blas_errors::MessageLevel
15-
blas_invalid_args::MessageLevel
16-
blas_info::MessageLevel
17-
blas_success::MessageLevel
18-
condition_number::MessageLevel
8+
using_iterative_solvers
9+
using_IterativeSolvers
10+
IterativeSolvers_iterations
11+
KrylovKit_verbosity
12+
KrylovJL_verbosity
13+
HYPRE_verbosity
14+
pardiso_verbosity
15+
blas_errors
16+
blas_invalid_args
17+
blas_info
18+
blas_success
19+
condition_number
20+
end
1921

20-
function LinearVerbosity{true}(;
22+
function LinearVerbosity{true}(;
2123
# Error control defaults
2224
default_lu_fallback = WarnLevel(),
2325
# Performance defaults
@@ -35,23 +37,21 @@ mutable struct LinearVerbosity{Enabled} <: AbstractVerbositySpecifier{Enabled}
3537
blas_info = Silent(),
3638
blas_success = Silent(),
3739
condition_number = Silent())
40+
LinearVerbosity{true}(default_lu_fallback, no_right_preconditioning,
41+
using_iterative_solvers, using_IterativeSolvers,
42+
IterativeSolvers_iterations, KrylovKit_verbosity,
43+
KrylovJL_verbosity, HYPRE_verbosity, pardiso_verbosity,
44+
blas_errors, blas_invalid_args, blas_info, blas_success, condition_number)
45+
end
3846

39-
new{true}(default_lu_fallback, no_right_preconditioning,
40-
using_iterative_solvers, using_IterativeSolvers,
41-
IterativeSolvers_iterations, KrylovKit_verbosity,
42-
KrylovJL_verbosity, HYPRE_verbosity, pardiso_verbosity,
43-
blas_errors, blas_invalid_args, blas_info, blas_success, condition_number)
44-
end
4547

46-
function LinearVerbosity{false}()
47-
new{false}(Silent(), Silent(),
48+
function LinearVerbosity{false}()
49+
LinearVerbosity{false}(Silent(), Silent(),
4850
Silent(), Silent(),
4951
Silent(), Silent(),
5052
Silent(), Silent(), Silent(),
5153
Silent(), Silent(), Silent(), Silent(), Silent())
52-
end
5354
end
54-
5555
LinearVerbosity(enabled::Bool) = enabled ? LinearVerbosity{true}() : LinearVerbosity{false}()
5656

5757
function LinearVerbosity(verbose::VerbosityPreset)
@@ -121,23 +121,23 @@ end
121121

122122
function LinearVerbosity(; error_control=nothing, performance=nothing, numerical=nothing, kwargs...)
123123
# Validate group arguments
124-
if error_control !== nothing && !(error_control isa MessageLevel)
125-
throw(ArgumentError("error_control must be a SciMLLogging.MessageLevel, got $(typeof(error_control))"))
124+
if error_control !== nothing && !(error_control isa AbstractMessageLevel)
125+
throw(ArgumentError("error_control must be a SciMLLogging.AbstractMessageLevel, got $(typeof(error_control))"))
126126
end
127-
if performance !== nothing && !(performance isa MessageLevel)
128-
throw(ArgumentError("performance must be a SciMLLogging.MessageLevel, got $(typeof(performance))"))
127+
if performance !== nothing && !(performance isa AbstractMessageLevel)
128+
throw(ArgumentError("performance must be a SciMLLogging.AbstractMessageLevel, got $(typeof(performance))"))
129129
end
130-
if numerical !== nothing && !(numerical isa MessageLevel)
131-
throw(ArgumentError("numerical must be a SciMLLogging.MessageLevel, got $(typeof(numerical))"))
130+
if numerical !== nothing && !(numerical isa AbstractMessageLevel)
131+
throw(ArgumentError("numerical must be a SciMLLogging.AbstractMessageLevel, got $(typeof(numerical))"))
132132
end
133133

134134
# Validate individual kwargs
135135
for (key, value) in kwargs
136136
if !(key in error_control_options || key in performance_options || key in numerical_options)
137137
throw(ArgumentError("Unknown verbosity option: $key. Valid options are: $(tuple(error_control_options..., performance_options..., numerical_options...))"))
138138
end
139-
if !(value isa MessageLevel)
140-
throw(ArgumentError("$key must be a SciMLLogging.MessageLevel, got $(typeof(value))"))
139+
if !(value isa AbstractMessageLevel)
140+
throw(ArgumentError("$key must be a SciMLLogging.AbstractMessageLevel, got $(typeof(value))"))
141141
end
142142
end
143143

@@ -222,47 +222,6 @@ function group_options(verbosity::LinearVerbosity, group::Symbol)
222222
end
223223
end
224224

225-
function Base.setproperty!(verbosity::LinearVerbosity, name::Symbol, value)
226-
# Check if this is a group name
227-
if name === :error_control
228-
if value isa MessageLevel
229-
for opt in error_control_options
230-
setfield!(verbosity, opt, value)
231-
end
232-
else
233-
error("error_control must be set to a SciMLLogging.MessageLevel")
234-
end
235-
elseif name === :performance
236-
if value isa MessageLevel
237-
for opt in performance_options
238-
setfield!(verbosity, opt, value)
239-
end
240-
else
241-
error("performance must be set to a SciMLLogging.MessageLevel")
242-
end
243-
elseif name === :numerical
244-
if value isa MessageLevel
245-
for opt in numerical_options
246-
setfield!(verbosity, opt, value)
247-
end
248-
else
249-
error("numerical must be set to a SciMLLogging.MessageLevel")
250-
end
251-
else
252-
# Check if this is an individual option
253-
if name in error_control_options || name in performance_options || name in numerical_options
254-
if value isa MessageLevel
255-
setfield!(verbosity, name, value)
256-
else
257-
error("$name must be set to a SciMLLogging.MessageLevel")
258-
end
259-
else
260-
# Fall back to default behavior for unknown properties
261-
setfield!(verbosity, name, value)
262-
end
263-
end
264-
end
265-
266225
function Base.getproperty(verbosity::LinearVerbosity, name::Symbol)
267226
# Check if this is a group name
268227
if name === :error_control

test/verbosity.jl

Lines changed: 5 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using LinearSolve
22
using LinearSolve: LinearVerbosity, option_group, group_options, BLISLUFactorization
33
using SciMLLogging
44
using Test
5+
56
@testset "LinearVerbosity Tests" begin
67
@testset "Default constructor" begin
78
v1 = LinearVerbosity()
@@ -132,76 +133,15 @@ using Test
132133
@test :using_IterativeSolvers in keys(numerical_group)
133134
@test :pardiso_verbosity in keys(numerical_group)
134135

135-
# Test values are MessageLevel types
136-
@test error_group.default_lu_fallback isa SciMLLogging.MessageLevel
137-
@test performance_group.no_right_preconditioning isa SciMLLogging.MessageLevel
138-
@test numerical_group.KrylovKit_verbosity isa SciMLLogging.MessageLevel
136+
# Test values are AbstractMessageLevel types
137+
@test error_group.default_lu_fallback isa SciMLLogging.AbstractMessageLevel
138+
@test performance_group.no_right_preconditioning isa SciMLLogging.AbstractMessageLevel
139+
@test numerical_group.KrylovKit_verbosity isa SciMLLogging.AbstractMessageLevel
139140

140141
# Individual field access should still work
141142
@test v.default_lu_fallback isa SciMLLogging.WarnLevel
142143
@test v.KrylovKit_verbosity isa SciMLLogging.WarnLevel
143144
end
144-
145-
@testset "Group setproperty! setting" begin
146-
v = LinearVerbosity()
147-
148-
# Test setting entire error_control group
149-
v.error_control = ErrorLevel()
150-
@test v.default_lu_fallback isa SciMLLogging.ErrorLevel
151-
152-
# Test setting entire performance group
153-
v.performance = InfoLevel()
154-
@test v.no_right_preconditioning isa SciMLLogging.InfoLevel
155-
156-
# Test setting entire numerical group
157-
v.numerical = Silent()
158-
@test v.KrylovKit_verbosity isa SciMLLogging.Silent
159-
@test v.using_IterativeSolvers isa SciMLLogging.Silent
160-
@test v.pardiso_verbosity isa SciMLLogging.Silent
161-
@test v.HYPRE_verbosity isa SciMLLogging.Silent
162-
163-
# Test that other groups aren't affected
164-
@test v.default_lu_fallback isa SciMLLogging.ErrorLevel # error_control unchanged
165-
@test v.no_right_preconditioning isa SciMLLogging.InfoLevel # performance unchanged
166-
167-
# Test individual setting still works after group setting
168-
v.KrylovKit_verbosity = WarnLevel()
169-
@test v.KrylovKit_verbosity isa SciMLLogging.WarnLevel
170-
# Other numerical options should still be Silent
171-
@test v.using_IterativeSolvers isa SciMLLogging.Silent
172-
end
173-
174-
@testset "Group setproperty! error handling" begin
175-
v = LinearVerbosity()
176-
177-
# Test error for invalid group value type
178-
@test_throws ErrorException v.error_control = "invalid"
179-
@test_throws ErrorException v.performance = 123
180-
@test_throws ErrorException v.numerical = :invalid
181-
182-
# Test error for invalid individual option type
183-
@test_throws ErrorException v.KrylovKit_verbosity = "invalid"
184-
@test_throws ErrorException v.default_lu_fallback = 123
185-
end
186-
187-
@testset "getproperty and setproperty! consistency" begin
188-
v = LinearVerbosity()
189-
190-
# Set a group and verify getproperty reflects the change
191-
v.numerical = ErrorLevel()
192-
numerical_group = v.numerical
193-
194-
@test all(x -> x isa SciMLLogging.ErrorLevel, values(numerical_group))
195-
196-
# Set individual option and verify both individual and group access work
197-
v.KrylovKit_verbosity = InfoLevel()
198-
@test v.KrylovKit_verbosity isa SciMLLogging.InfoLevel
199-
200-
updated_numerical = v.numerical
201-
@test updated_numerical.KrylovKit_verbosity isa SciMLLogging.InfoLevel
202-
# Other numerical options should still be Error
203-
@test updated_numerical.using_IterativeSolvers isa SciMLLogging.ErrorLevel
204-
end
205145
end
206146

207147

0 commit comments

Comments
 (0)