@@ -114,41 +114,12 @@ const error_control_options = (:dt_NaN, :init_NaN, :dense_output_saveat, :max_it
114114const performance_options = (:alg_switch , :stiff_detection , :mismatched_input_output_type , :jacobian_update , :w_factorization , :newton_iterations )
115115const numerical_options = (:rosenbrock_no_differential_states , :shampine_dt , :unlimited_dt , :dt_epsilon , :stability_check , :near_singular )
116116
117- function ODEVerbosity (;
118- error_control = nothing , performance = nothing , numerical = nothing ,
119- linear_verbosity = nothing , nonlinear_verbosity = nothing , kwargs... )
117+ # Runtime helper for complex verbosity construction path
118+ function _build_ode_verbosity_runtime (
119+ error_control, performance, numerical,
120+ linear_verbosity, nonlinear_verbosity, kwargs
121+ )
120122 # Validate group arguments
121-
122- if error_control === nothing && performance === nothing && numerical === nothing &&
123- linear_verbosity === nothing && nonlinear_verbosity === nothing && isempty (kwargs)
124- return ODEVerbosity (
125- linear_verbosity = Minimal (),
126- nonlinear_verbosity = Minimal (),
127- dt_NaN = WarnLevel (),
128- init_NaN = WarnLevel (),
129- dense_output_saveat = WarnLevel (),
130- max_iters = WarnLevel (),
131- dt_min_unstable = WarnLevel (),
132- instability = WarnLevel (),
133- newton_convergence = Silent (),
134- step_rejected = Silent (),
135- step_accepted = Silent (),
136- convergence_limit = Silent (),
137- alg_switch = Silent (),
138- stiff_detection = Silent (),
139- mismatched_input_output_type = WarnLevel (),
140- jacobian_update = Silent (),
141- w_factorization = Silent (),
142- newton_iterations = Silent (),
143- rosenbrock_no_differential_states = WarnLevel (),
144- shampine_dt = Silent (),
145- unlimited_dt = WarnLevel (),
146- dt_epsilon = Silent (),
147- stability_check = Silent (),
148- near_singular = Silent ()
149- )
150- end
151-
152123 if error_control != = nothing && ! (error_control isa AbstractMessageLevel)
153124 throw (ArgumentError (" error_control must be a SciMLLogging.AbstractMessageLevel, got $(typeof (error_control)) " ))
154125 end
@@ -160,7 +131,7 @@ function ODEVerbosity(;
160131 end
161132
162133 # Validate individual kwargs
163- for (key, value) in kwargs
134+ for (key, value) in pairs ( kwargs)
164135 if ! (key in error_control_options || key in performance_options ||
165136 key in numerical_options)
166137 throw (ArgumentError (" Unknown verbosity option: $key . Valid options are: $(tuple (error_control_options... , performance_options... , numerical_options... )) " ))
@@ -242,6 +213,113 @@ function ODEVerbosity(;
242213 ODEVerbosity (values (final_args)... )
243214end
244215
216+ # Optionally-generated function for ODEVerbosity construction
217+ # Uses compile-time type information to optimize the common default case
218+ function _build_ode_verbosity (
219+ error_control,
220+ performance,
221+ numerical,
222+ linear_verbosity,
223+ nonlinear_verbosity,
224+ kwargs
225+ )
226+ if @generated
227+ # Generated path: In this block, we're at compile time
228+ # error_control, performance, numerical, etc. are the actual type values
229+ # Check if all group params are Nothing and kwargs is empty (fast default path)
230+ if error_control === Nothing && performance === Nothing && numerical === Nothing &&
231+ linear_verbosity === Nothing && nonlinear_verbosity === Nothing &&
232+ kwargs <: NamedTuple{()}
233+ # Return an expression that constructs the default directly
234+ return quote
235+ ODEVerbosity (
236+ Minimal (), # linear_verbosity
237+ Minimal (), # nonlinear_verbosity
238+ WarnLevel (), # dt_NaN
239+ WarnLevel (), # init_NaN
240+ WarnLevel (), # dense_output_saveat
241+ WarnLevel (), # max_iters
242+ WarnLevel (), # dt_min_unstable
243+ WarnLevel (), # instability
244+ Silent (), # newton_convergence
245+ Silent (), # step_rejected
246+ Silent (), # step_accepted
247+ Silent (), # convergence_limit
248+ Silent (), # alg_switch
249+ Silent (), # stiff_detection
250+ WarnLevel (), # mismatched_input_output_type
251+ Silent (), # jacobian_update
252+ Silent (), # w_factorization
253+ Silent (), # newton_iterations
254+ WarnLevel (), # rosenbrock_no_differential_states
255+ Silent (), # shampine_dt
256+ WarnLevel (), # unlimited_dt
257+ Silent (), # dt_epsilon
258+ Silent (), # stability_check
259+ Silent () # near_singular
260+ )
261+ end
262+ else
263+ # For non-default cases, delegate to runtime logic
264+ return quote
265+ _build_ode_verbosity_runtime (
266+ error_control, performance, numerical,
267+ linear_verbosity, nonlinear_verbosity, kwargs
268+ )
269+ end
270+ end
271+ else
272+ # Runtime fallback: error_control, performance, etc. are VALUES
273+ if error_control === nothing && performance === nothing && numerical === nothing &&
274+ linear_verbosity === nothing && nonlinear_verbosity === nothing &&
275+ isempty (kwargs)
276+ # Fast default path at runtime
277+ ODEVerbosity (
278+ Minimal (), # linear_verbosity
279+ Minimal (), # nonlinear_verbosity
280+ WarnLevel (), # dt_NaN
281+ WarnLevel (), # init_NaN
282+ WarnLevel (), # dense_output_saveat
283+ WarnLevel (), # max_iters
284+ WarnLevel (), # dt_min_unstable
285+ WarnLevel (), # instability
286+ Silent (), # newton_convergence
287+ Silent (), # step_rejected
288+ Silent (), # step_accepted
289+ Silent (), # convergence_limit
290+ Silent (), # alg_switch
291+ Silent (), # stiff_detection
292+ WarnLevel (), # mismatched_input_output_type
293+ Silent (), # jacobian_update
294+ Silent (), # w_factorization
295+ Silent (), # newton_iterations
296+ WarnLevel (), # rosenbrock_no_differential_states
297+ Silent (), # shampine_dt
298+ WarnLevel (), # unlimited_dt
299+ Silent (), # dt_epsilon
300+ Silent (), # stability_check
301+ Silent () # near_singular
302+ )
303+ else
304+ # Complex path
305+ _build_ode_verbosity_runtime (
306+ error_control, performance, numerical,
307+ linear_verbosity, nonlinear_verbosity, kwargs
308+ )
309+ end
310+ end
311+ end
312+
313+ function ODEVerbosity (;
314+ error_control = nothing , performance = nothing , numerical = nothing ,
315+ linear_verbosity = nothing , nonlinear_verbosity = nothing , kwargs... )
316+ _build_ode_verbosity (
317+ error_control, performance, numerical,
318+ linear_verbosity, nonlinear_verbosity,
319+ NamedTuple (kwargs)
320+ )
321+ end
322+
245323# Constructor for verbosity presets following the hierarchical levels:
246324# None < Minimal < Standard < Detailed < All
247325# Each level includes all messages from levels below it plus additional ones
0 commit comments