Skip to content

Commit a1c1e93

Browse files
committed
add ability for ODEVerbosity constructor to take more kwargs
1 parent 614bc89 commit a1c1e93

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

src/verbosity.jl

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,21 @@
77
Edge
88
All
99
Default
10-
1110
end
1211

12+
# Defaults
13+
14+
defaults =
15+
Dict(
16+
:dt_NaN => Verbosity.Warn(),
17+
:init_NaN => Verbosity.Warn(),
18+
:rosenbrock_no_differential_states => Verbosity.Warn(),
19+
:dense_output_saveat => Verbosity.Warn(),
20+
:alg_switch => Verbosity.Warn(),
21+
:mismatched_input_output_type => Verbosity.Warn()
22+
)
23+
24+
1325
# Linear Verbosity
1426

1527
mutable struct LinearErrorControlVerbosity
@@ -35,7 +47,6 @@ function LinearErrorControlVerbosity(verbose::Verbosity.Type)
3547
end
3648

3749
mutable struct LinearPerformanceVerbosity
38-
3950
@add_kwonly function LinearPerformanceVerbosity()
4051
new()
4152
end
@@ -132,8 +143,6 @@ mutable struct NonlinearErrorControlVerbosity
132143
end
133144
end
134145

135-
136-
137146
function NonlinearErrorControlVerbosity(verbose::Verbosity.Type)
138147
@match verbose begin
139148
Verbosity.None() => NonlinearErrorControlVerbosity(fill(
@@ -254,9 +263,12 @@ end
254263
mutable struct ODEErrorControlVerbosity
255264
dt_NaN::Verbosity.Type
256265
init_NaN::Verbosity.Type
266+
rosenbrock_no_differential_states::Verbosity.Type
267+
dense_output_saveat::Verbosity.Type
257268

258-
@add_kwonly function ODEErrorControlVerbosity(dt_NaN, init_NaN)
259-
new(dt_NaN, init_NaN)
269+
function ODEErrorControlVerbosity(dt_NaN = defaults[:dt_NaN], init_NaN = defaults[:init_NaN],
270+
rosenbrock_no_differential_states = defaults[:rosenbrock_no_differential_states], dense_output_saveat = defaults[:dense_output_saveat])
271+
new(dt_NaN, init_NaN, rosenbrock_no_differential_states, dense_output_saveat)
260272
end
261273
end
262274

@@ -276,24 +288,23 @@ function ODEErrorControlVerbosity(verbose::Verbosity.Type)
276288
Verbosity.Error() => ODEErrorControlVerbosity(fill(
277289
Verbosity.Error(), length(fieldnames(ODEErrorControlVerbosity)))...)
278290

279-
Verbosity.Default() => ODEErrorControlVerbosity(Verbosity.Info(), Verbosity.Error())
291+
Verbosity.Default() => ODEErrorControlVerbosity()
280292

281-
Verbosity.Edge() => ODEErrorControlVerbosity(Verbosity.Info(), Verbosity.Warn())
293+
Verbosity.Edge() => ODEErrorControlVerbosity()
282294

283295
_ => @error "Not a valid choice for verbosity."
284296
end
285297
end
286298

287299
mutable struct ODEPerformanceVerbosity
288-
alg_switch
300+
alg_switch::Verbosity.Type
301+
mismatched_input_output_type::Verbosity.Type
289302

290-
@add_kwonly function ODEPerformanceVerbosity(alg_switch)
291-
new(alg_switch)
303+
function ODEPerformanceVerbosity(;alg_switch = defaults[:alg_switch], mismatched_input_output_type = defaults[:mismatched_input_output_type])
304+
new(alg_switch, mismatched_input_output_type)
292305
end
293306
end
294307

295-
296-
297308
function ODEPerformanceVerbosity(verbose::Verbosity.Type)
298309
@match verbose begin
299310
Verbosity.None() => ODEPerformanceVerbosity(fill(
@@ -308,7 +319,7 @@ function ODEPerformanceVerbosity(verbose::Verbosity.Type)
308319
Verbosity.Error() => ODEPerformanceVerbosity(fill(
309320
Verbosity.Error(), length(fieldnames(ODEPerformanceVerbosity)))...)
310321

311-
Verbosity.Default() => ODEPerformanceVerbosity(alg_switch = Verbosity.None())
322+
Verbosity.Default() => ODEPerformanceVerbosity()
312323

313324
_ => @error "Not a valid choice for verbosity."
314325
end
@@ -381,7 +392,7 @@ function ODEVerbosity(verbose::Verbosity.Type)
381392
end
382393
end
383394

384-
function ODEVerbosity(; error_control = Verbosity.Default(), performance = Verbosity.Default(), numerical = Verbosity.Default(), linear_verbosity = Verbosity.Default(), nonlinear_verbosity = Verbosity.Default())
395+
function ODEVerbosity(; error_control = Verbosity.Default(), performance = Verbosity.Default(), numerical = Verbosity.Default(), linear_verbosity = Verbosity.Default(), nonlinear_verbosity = Verbosity.Default(), kwargs...)
385396

386397
if error_control isa Verbosity.Type
387398
error_control_verbosity = ODEErrorControlVerbosity(error_control)
@@ -413,6 +424,20 @@ function ODEVerbosity(; error_control = Verbosity.Default(), performance = Verbo
413424
nonlinear = nonlinear_verbosity
414425
end
415426

427+
if !isempty(kwargs)
428+
for (key, value) in pairs(kwargs)
429+
if hasfield(ODEErrorControlVerbosity, key)
430+
setproperty!(error_control_verbosity, key, value)
431+
elseif hasfield(ODEPerformanceVerbosity, key)
432+
setproperty!(performance_verbosity, key, value)
433+
elseif hasfield(ODENumericalVerbosity, key)
434+
setproperty!(numerical_verbosity, key, value)
435+
else
436+
error("$key is not a recognized verbosity toggle.")
437+
end
438+
end
439+
end
440+
416441
ODEVerbosity{true}(linear, nonlinear, error_control_verbosity, performance_verbosity, numerical_verbosity)
417442
end
418443

@@ -484,4 +509,5 @@ macro SciMLMessage(f_or_message, verb, option, group)
484509
_module = __module__
485510
return :(emit_message(
486511
$(esc(f_or_message)), $(esc(verb)), $option, $group, $file, $line, $_module))
487-
end
512+
end
513+

0 commit comments

Comments
 (0)