Skip to content

Commit ee9fb5f

Browse files
committed
fix up the verbosity tests
1 parent 5c9c21f commit ee9fb5f

File tree

1 file changed

+90
-77
lines changed

1 file changed

+90
-77
lines changed

test/interface/verbosity.jl

Lines changed: 90 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using OrdinaryDiffEqCore
2-
using OrdinaryDiffEqCore: ODEVerbosity, option_group, group_options
3-
using OrdinaryDiffEqBDF
4-
using OrdinaryDiffEqExtrapolation
5-
using OrdinaryDiffEqFIRK
6-
using OrdinaryDiffEqRosenbrock
7-
using OrdinaryDiffEqSDIRK
2+
using OrdinaryDiffEqCore: ODEVerbosity
3+
using OrdinaryDiffEq
84
using OrdinaryDiffEqNonlinearSolve: NonlinearSolveAlg
95
using ODEProblemLibrary: prob_ode_vanderpol_stiff
106
using Test
@@ -16,62 +12,126 @@ using NonlinearSolve: NonlinearVerbosity
1612
@testset "Default constructor" begin
1713
v1 = ODEVerbosity()
1814
@test v1 isa ODEVerbosity
15+
16+
# Test solver verbosity
17+
@test v1.linear_verbosity isa SciMLLogging.Minimal
18+
@test v1.nonlinear_verbosity isa SciMLLogging.Minimal
19+
20+
# Test error control group (default: WarnLevel except newton_convergence, step_rejected, step_accepted, convergence_limit)
1921
@test v1.dt_NaN isa SciMLLogging.WarnLevel
2022
@test v1.init_NaN isa SciMLLogging.WarnLevel
2123
@test v1.dense_output_saveat isa SciMLLogging.WarnLevel
22-
@test v1.alg_switch isa SciMLLogging.WarnLevel
24+
@test v1.max_iters isa SciMLLogging.WarnLevel
25+
@test v1.dt_min_unstable isa SciMLLogging.WarnLevel
26+
@test v1.instability isa SciMLLogging.WarnLevel
27+
@test v1.newton_convergence isa SciMLLogging.Silent
28+
@test v1.step_rejected isa SciMLLogging.Silent
29+
@test v1.step_accepted isa SciMLLogging.Silent
30+
@test v1.convergence_limit isa SciMLLogging.Silent
31+
32+
# Test performance group (default: Silent except mismatched_input_output_type)
33+
@test v1.alg_switch isa SciMLLogging.Silent
34+
@test v1.stiff_detection isa SciMLLogging.Silent
2335
@test v1.mismatched_input_output_type isa SciMLLogging.WarnLevel
36+
@test v1.jacobian_update isa SciMLLogging.Silent
37+
@test v1.w_factorization isa SciMLLogging.Silent
38+
@test v1.newton_iterations isa SciMLLogging.Silent
39+
40+
# Test numerical group (default: WarnLevel except shampine_dt, dt_epsilon, stability_check)
2441
@test v1.rosenbrock_no_differential_states isa SciMLLogging.WarnLevel
25-
@test v1.shampine_dt isa SciMLLogging.WarnLevel
42+
@test v1.shampine_dt isa SciMLLogging.Silent
2643
@test v1.unlimited_dt isa SciMLLogging.WarnLevel
27-
@test v1.linear_verbosity isa SciMLLogging.AbstractVerbosityPreset
28-
@test v1.nonlinear_verbosity isa SciMLLogging.AbstractVerbosityPreset
44+
@test v1.dt_epsilon isa SciMLLogging.Silent
45+
@test v1.stability_check isa SciMLLogging.Silent
46+
@test v1.near_singular isa SciMLLogging.Silent
2947
end
3048

3149
@testset "ODEVerbosity preset constructors" begin
3250
v_none = ODEVerbosity(SciMLLogging.None())
33-
v_all = ODEVerbosity(SciMLLogging.All())
3451
v_minimal = ODEVerbosity(SciMLLogging.Minimal())
3552
v_standard = ODEVerbosity(SciMLLogging.Standard())
3653
v_detailed = ODEVerbosity(SciMLLogging.Detailed())
54+
v_all = ODEVerbosity(SciMLLogging.All())
3755

56+
# Test None - everything Silent
57+
@test v_none.linear_verbosity isa SciMLLogging.None
58+
@test v_none.nonlinear_verbosity isa SciMLLogging.None
3859
@test v_none.dt_NaN isa SciMLLogging.Silent
3960
@test v_none.init_NaN isa SciMLLogging.Silent
4061
@test v_none.alg_switch isa SciMLLogging.Silent
4162
@test v_none.rosenbrock_no_differential_states isa SciMLLogging.Silent
4263

64+
# Test Minimal - only critical errors
65+
@test v_minimal.linear_verbosity isa SciMLLogging.Minimal
66+
@test v_minimal.nonlinear_verbosity isa SciMLLogging.Minimal
4367
@test v_minimal.dt_NaN isa SciMLLogging.WarnLevel
4468
@test v_minimal.init_NaN isa SciMLLogging.WarnLevel
69+
@test v_minimal.max_iters isa SciMLLogging.WarnLevel
70+
@test v_minimal.newton_convergence isa SciMLLogging.WarnLevel
71+
@test v_minimal.near_singular isa SciMLLogging.WarnLevel
4572
@test v_minimal.alg_switch isa SciMLLogging.Silent
4673
@test v_minimal.dense_output_saveat isa SciMLLogging.Silent
74+
@test v_minimal.mismatched_input_output_type isa SciMLLogging.Silent
4775

76+
# Test Standard - same as default
4877
@test v_standard.dt_NaN isa SciMLLogging.WarnLevel
4978
@test v_standard.init_NaN isa SciMLLogging.WarnLevel
50-
@test v_standard.alg_switch isa SciMLLogging.WarnLevel
79+
@test v_standard.alg_switch isa SciMLLogging.Silent
80+
@test v_standard.dense_output_saveat isa SciMLLogging.WarnLevel
81+
@test v_standard.mismatched_input_output_type isa SciMLLogging.WarnLevel
5182

83+
# Test Detailed - includes debugging info
84+
@test v_detailed.linear_verbosity isa SciMLLogging.Detailed
85+
@test v_detailed.nonlinear_verbosity isa SciMLLogging.Detailed
5286
@test v_detailed.alg_switch isa SciMLLogging.InfoLevel
5387
@test v_detailed.dense_output_saveat isa SciMLLogging.InfoLevel
5488
@test v_detailed.shampine_dt isa SciMLLogging.InfoLevel
89+
@test v_detailed.jacobian_update isa SciMLLogging.InfoLevel
90+
@test v_detailed.w_factorization isa SciMLLogging.InfoLevel
91+
@test v_detailed.convergence_limit isa SciMLLogging.InfoLevel
5592

93+
# Test All - maximum verbosity
94+
@test v_all.linear_verbosity isa SciMLLogging.All
95+
@test v_all.nonlinear_verbosity isa SciMLLogging.All
5696
@test v_all.alg_switch isa SciMLLogging.InfoLevel
5797
@test v_all.shampine_dt isa SciMLLogging.InfoLevel
5898
@test v_all.dense_output_saveat isa SciMLLogging.InfoLevel
99+
@test v_all.step_rejected isa SciMLLogging.InfoLevel
100+
@test v_all.step_accepted isa SciMLLogging.InfoLevel
101+
@test v_all.stiff_detection isa SciMLLogging.InfoLevel
59102
end
60103

61104
@testset "Group-level keyword constructors" begin
62105
v_error = ODEVerbosity(error_control = SciMLLogging.ErrorLevel())
106+
# Test all error_control fields
63107
@test v_error.dt_NaN isa SciMLLogging.ErrorLevel
64108
@test v_error.init_NaN isa SciMLLogging.ErrorLevel
65109
@test v_error.dense_output_saveat isa SciMLLogging.ErrorLevel
110+
@test v_error.max_iters isa SciMLLogging.ErrorLevel
111+
@test v_error.dt_min_unstable isa SciMLLogging.ErrorLevel
112+
@test v_error.instability isa SciMLLogging.ErrorLevel
113+
@test v_error.newton_convergence isa SciMLLogging.ErrorLevel
114+
@test v_error.step_rejected isa SciMLLogging.ErrorLevel
115+
@test v_error.step_accepted isa SciMLLogging.ErrorLevel
116+
@test v_error.convergence_limit isa SciMLLogging.ErrorLevel
66117

67118
v_numerical = ODEVerbosity(numerical = SciMLLogging.Silent())
119+
# Test all numerical fields
68120
@test v_numerical.rosenbrock_no_differential_states isa SciMLLogging.Silent
69121
@test v_numerical.shampine_dt isa SciMLLogging.Silent
70122
@test v_numerical.unlimited_dt isa SciMLLogging.Silent
123+
@test v_numerical.dt_epsilon isa SciMLLogging.Silent
124+
@test v_numerical.stability_check isa SciMLLogging.Silent
125+
@test v_numerical.near_singular isa SciMLLogging.Silent
71126

72127
v_performance = ODEVerbosity(performance = SciMLLogging.InfoLevel())
128+
# Test all performance fields
73129
@test v_performance.alg_switch isa SciMLLogging.InfoLevel
130+
@test v_performance.stiff_detection isa SciMLLogging.InfoLevel
74131
@test v_performance.mismatched_input_output_type isa SciMLLogging.InfoLevel
132+
@test v_performance.jacobian_update isa SciMLLogging.InfoLevel
133+
@test v_performance.w_factorization isa SciMLLogging.InfoLevel
134+
@test v_performance.newton_iterations isa SciMLLogging.InfoLevel
75135
end
76136

77137
@testset "Mixed group and individual settings" begin
@@ -120,69 +180,22 @@ using NonlinearSolve: NonlinearVerbosity
120180
@test v_with_solvers2.nonlinear_verbosity isa SciMLLogging.All
121181
end
122182

123-
@testset "Group classification functions" begin
124-
@test option_group(:dt_NaN) == :error_control
125-
@test option_group(:init_NaN) == :error_control
126-
@test option_group(:dense_output_saveat) == :error_control
127-
@test option_group(:alg_switch) == :performance
128-
@test option_group(:mismatched_input_output_type) == :performance
129-
@test option_group(:rosenbrock_no_differential_states) == :numerical
130-
@test option_group(:shampine_dt) == :numerical
131-
@test option_group(:unlimited_dt) == :numerical
132-
133-
# Test error for unknown option
134-
@test_throws ErrorException option_group(:unknown_option)
135-
end
183+
@testset "Validation tests" begin
184+
# Test that invalid group arguments throw errors
185+
@test_throws ArgumentError ODEVerbosity(error_control = "invalid")
186+
@test_throws ArgumentError ODEVerbosity(performance = 123)
187+
@test_throws ArgumentError ODEVerbosity(numerical = :wrong)
136188

137-
@testset "Group options function" begin
138-
v = ODEVerbosity(numerical = SciMLLogging.WarnLevel())
139-
numerical_opts = group_options(v, :numerical)
140-
@test numerical_opts isa NamedTuple
141-
@test :rosenbrock_no_differential_states in keys(numerical_opts)
142-
@test :shampine_dt in keys(numerical_opts)
143-
@test :unlimited_dt in keys(numerical_opts)
144-
@test numerical_opts.rosenbrock_no_differential_states isa SciMLLogging.WarnLevel
145-
@test numerical_opts.shampine_dt isa SciMLLogging.WarnLevel
146-
@test numerical_opts.unlimited_dt isa SciMLLogging.WarnLevel
147-
148-
error_opts = group_options(v, :error_control)
149-
@test :dt_NaN in keys(error_opts)
150-
@test :init_NaN in keys(error_opts)
151-
@test :dense_output_saveat in keys(error_opts)
152-
153-
performance_opts = group_options(v, :performance)
154-
@test :alg_switch in keys(performance_opts)
155-
@test :mismatched_input_output_type in keys(performance_opts)
156-
157-
# Test error for unknown group
158-
@test_throws ErrorException group_options(v, :unknown_group)
159-
end
160-
161-
@testset "All error control fields" begin
162-
v = ODEVerbosity(error_control = InfoLevel())
163-
@test v.dt_NaN isa SciMLLogging.InfoLevel
164-
@test v.init_NaN isa SciMLLogging.InfoLevel
165-
@test v.dense_output_saveat isa SciMLLogging.InfoLevel
166-
end
167-
168-
@testset "All performance fields" begin
169-
v = ODEVerbosity(performance = ErrorLevel())
170-
@test v.alg_switch isa SciMLLogging.ErrorLevel
171-
@test v.mismatched_input_output_type isa SciMLLogging.ErrorLevel
172-
end
173-
174-
@testset "All numerical fields" begin
175-
v = ODEVerbosity(numerical = InfoLevel())
176-
@test v.rosenbrock_no_differential_states isa SciMLLogging.InfoLevel
177-
@test v.shampine_dt isa SciMLLogging.InfoLevel
178-
@test v.unlimited_dt isa SciMLLogging.InfoLevel
189+
# Test that invalid individual fields throw errors
190+
@test_throws ArgumentError ODEVerbosity(dt_NaN = "invalid")
191+
@test_throws ArgumentError ODEVerbosity(unknown_field = SciMLLogging.InfoLevel())
179192
end
180193

181194
@testset "Multiple group settings" begin
182195
v = ODEVerbosity(
183-
error_control = ErrorLevel(),
184-
performance = InfoLevel(),
185-
numerical = Silent()
196+
error_control = SciMLLogging.ErrorLevel(),
197+
performance = SciMLLogging.InfoLevel(),
198+
numerical = SciMLLogging.Silent()
186199
)
187200
@test v.dt_NaN isa SciMLLogging.ErrorLevel
188201
@test v.alg_switch isa SciMLLogging.InfoLevel
@@ -191,13 +204,13 @@ using NonlinearSolve: NonlinearVerbosity
191204

192205
@testset "Complex mixed settings" begin
193206
v = ODEVerbosity(
194-
error_control = WarnLevel(),
195-
performance = InfoLevel(),
196-
numerical = Silent(),
207+
error_control = SciMLLogging.WarnLevel(),
208+
performance = SciMLLogging.InfoLevel(),
209+
numerical = SciMLLogging.Silent(),
197210
linear_verbosity = SciMLLogging.Detailed(),
198211
nonlinear_verbosity = SciMLLogging.Minimal(),
199-
dt_NaN = ErrorLevel(), # Override specific error_control field
200-
shampine_dt = WarnLevel() # Override specific numerical field
212+
dt_NaN = SciMLLogging.ErrorLevel(), # Override specific error_control field
213+
shampine_dt = SciMLLogging.WarnLevel() # Override specific numerical field
201214
)
202215
# Check overrides took precedence
203216
@test v.dt_NaN isa SciMLLogging.ErrorLevel
@@ -212,7 +225,7 @@ using NonlinearSolve: NonlinearVerbosity
212225
end
213226

214227
@testset "Stiff Switching Message" begin
215-
verb = ODEVerbosity(performance = ODEPerformanceVerbosity(alg_switch = Verbosity.Info()))
228+
verb = ODEVerbosity(alg_switch = SciMLLogging.InfoLevel())
216229
solve(prob_ode_vanderpol_stiff, AutoTsit5(Rodas5()), verbose = verb)
217230
end
218231

@@ -345,7 +358,7 @@ using NonlinearSolve: NonlinearVerbosity
345358
integrator = init(prob, ImplicitDeuflhardExtrapolation(), verbose = verbose, dt = 1e-3)
346359

347360
for ls in integrator.cache.linsolve
348-
@test ls.cacheval.verbose isa SciMLLogging.None
361+
@test ls.verbose == LinearVerbosity(SciMLLogging.None())
349362
end
350363
end
351364

0 commit comments

Comments
 (0)