-
-
Notifications
You must be signed in to change notification settings - Fork 5
Add a generator for automatically creating VerbositySpecifier types and constructors #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jClugstor
wants to merge
7
commits into
SciML:main
Choose a base branch
from
jClugstor:verbosity_specifier_generator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+784
−2
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
It needs to be a macro... |
Member
Author
|
I've simplified it and turned it in to a macro. Using LinearVerbosity as an example, you can do @verbosity_specifier LinearVerbosity begin
toggles = (
:default_lu_fallback,
:no_right_preconditioning,
:using_IterativeSolvers,
:IterativeSolvers_iterations,
:KrylovKit_verbosity,
:KrylovJL_verbosity,
:HYPRE_verbosity,
:pardiso_verbosity,
:blas_errors,
:blas_invalid_args,
:blas_info,
:blas_success,
:condition_number,
:convergence_failure,
:solver_failure,
:max_iters
)
presets = (
None = (
default_lu_fallback = Silent(),
no_right_preconditioning = Silent(),
using_IterativeSolvers = Silent(),
IterativeSolvers_iterations = Silent(),
KrylovKit_verbosity = Silent(),
KrylovJL_verbosity = Silent(),
HYPRE_verbosity = Silent(),
pardiso_verbosity = Silent(),
blas_errors = Silent(),
blas_invalid_args = Silent(),
blas_info = Silent(),
blas_success = Silent(),
condition_number = Silent(),
convergence_failure = Silent(),
solver_failure = Silent(),
max_iters = Silent()
),
Minimal = (
default_lu_fallback = Silent(),
no_right_preconditioning = Silent(),
using_IterativeSolvers = Silent(),
IterativeSolvers_iterations = Silent(),
KrylovKit_verbosity = Silent(),
KrylovJL_verbosity = Silent(),
HYPRE_verbosity = Silent(),
pardiso_verbosity = Silent(),
blas_errors = WarnLevel(),
blas_invalid_args = WarnLevel(),
blas_info = Silent(),
blas_success = Silent(),
condition_number = Silent(),
convergence_failure = Silent(),
solver_failure = Silent(),
max_iters = Silent()
),
Standard = (
default_lu_fallback = Silent(),
no_right_preconditioning = Silent(),
using_IterativeSolvers = Silent(),
IterativeSolvers_iterations = Silent(),
KrylovKit_verbosity = CustomLevel(1),
KrylovJL_verbosity = Silent(),
HYPRE_verbosity = InfoLevel(),
pardiso_verbosity = Silent(),
blas_errors = WarnLevel(),
blas_invalid_args = WarnLevel(),
blas_info = Silent(),
blas_success = Silent(),
condition_number = Silent(),
convergence_failure = WarnLevel(),
solver_failure = WarnLevel(),
max_iters = WarnLevel()
),
Detailed = (
default_lu_fallback = WarnLevel(),
no_right_preconditioning = InfoLevel(),
using_IterativeSolvers = InfoLevel(),
IterativeSolvers_iterations = Silent(),
KrylovKit_verbosity = CustomLevel(2),
KrylovJL_verbosity = CustomLevel(1),
HYPRE_verbosity = InfoLevel(),
pardiso_verbosity = CustomLevel(1),
blas_errors = WarnLevel(),
blas_invalid_args = WarnLevel(),
blas_info = InfoLevel(),
blas_success = InfoLevel(),
condition_number = Silent(),
convergence_failure = WarnLevel(),
solver_failure = WarnLevel(),
max_iters = WarnLevel()
),
All = (
default_lu_fallback = WarnLevel(),
no_right_preconditioning = InfoLevel(),
using_IterativeSolvers = InfoLevel(),
IterativeSolvers_iterations = InfoLevel(),
KrylovKit_verbosity = CustomLevel(3),
KrylovJL_verbosity = CustomLevel(1),
HYPRE_verbosity = InfoLevel(),
pardiso_verbosity = CustomLevel(1),
blas_errors = WarnLevel(),
blas_invalid_args = WarnLevel(),
blas_info = InfoLevel(),
blas_success = InfoLevel(),
condition_number = InfoLevel(),
convergence_failure = WarnLevel(),
solver_failure = WarnLevel(),
max_iters = WarnLevel()
)
)
groups = (
error_control = (:default_lu_fallback, :blas_errors, :blas_invalid_args),
performance = (:no_right_preconditioning,),
numerical = (:using_IterativeSolvers, :IterativeSolvers_iterations,
:KrylovKit_verbosity, :KrylovJL_verbosity, :HYPRE_verbosity,
:pardiso_verbosity, :blas_info, :blas_success, :condition_number,
:convergence_failure, :solver_failure, :max_iters)
)
end
and get const _preset_map_LinearVerbosity = NamedTuple{(:None, :Minimal, :All, :Standard, :Detailed)}((NamedTuple{(:default_lu_fallback, :no_right_preconditioning, :using_IterativeSolvers, :IterativeSolvers_iterations, :KrylovKit_verbosity, :KrylovJL_verbosity, :HYPRE_verbosity, :pardiso_verbosity, :blas_errors, :blas_invalid_args, :blas_info, :blas_success, :condition_number, :convergence_failure, :solver_failure, :max_iters)}((Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent())), NamedTuple{(:default_lu_fallback, :no_right_preconditioning, :using_IterativeSolvers, :IterativeSolvers_iterations, :KrylovKit_verbosity, :KrylovJL_verbosity, :HYPRE_verbosity, :pardiso_verbosity, :blas_errors, :blas_invalid_args, :blas_info, :blas_success, :condition_number, :convergence_failure, :solver_failure, :max_iters)}((Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), WarnLevel(), WarnLevel(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent())), NamedTuple{(:default_lu_fallback, :no_right_preconditioning, :using_IterativeSolvers, :IterativeSolvers_iterations, :KrylovKit_verbosity, :KrylovJL_verbosity, :HYPRE_verbosity, :pardiso_verbosity, :blas_errors, :blas_invalid_args, :blas_info, :blas_success, :condition_number, :convergence_failure, :solver_failure, :max_iters)}((WarnLevel(), InfoLevel(), InfoLevel(), InfoLevel(), CustomLevel(3), CustomLevel(1), InfoLevel(), CustomLevel(1), WarnLevel(), WarnLevel(), InfoLevel(), InfoLevel(), InfoLevel(), WarnLevel(), WarnLevel(), WarnLevel())), NamedTuple{(:default_lu_fallback, :no_right_preconditioning, :using_IterativeSolvers, :IterativeSolvers_iterations, :KrylovKit_verbosity, :KrylovJL_verbosity, :HYPRE_verbosity, :pardiso_verbosity, :blas_errors, :blas_invalid_args, :blas_info, :blas_success, :condition_number, :convergence_failure, :solver_failure, :max_iters)}((Silent(), Silent(), Silent(), Silent(), CustomLevel(1), Silent(), InfoLevel(), Silent(), WarnLevel(), WarnLevel(), Silent(), Silent(), Silent(), WarnLevel(), WarnLevel(), WarnLevel())), NamedTuple{(:default_lu_fallback, :no_right_preconditioning, :using_IterativeSolvers, :IterativeSolvers_iterations, :KrylovKit_verbosity, :KrylovJL_verbosity, :HYPRE_verbosity, :pardiso_verbosity, :blas_errors, :blas_invalid_args, :blas_info, :blas_success, :condition_number, :convergence_failure, :solver_failure, :max_iters)}((WarnLevel(), InfoLevel(), InfoLevel(), Silent(), CustomLevel(2), CustomLevel(1), InfoLevel(), CustomLevel(1), WarnLevel(), WarnLevel(), InfoLevel(), InfoLevel(), Silent(), WarnLevel(), WarnLevel(), WarnLevel()))))
struct LinearVerbosity{T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16} <: AbstractVerbositySpecifier
default_lu_fallback::T1
no_right_preconditioning::T2
using_IterativeSolvers::T3
IterativeSolvers_iterations::T4
KrylovKit_verbosity::T5
KrylovJL_verbosity::T6
HYPRE_verbosity::T7
pardiso_verbosity::T8
blas_errors::T9
blas_invalid_args::T10
blas_info::T11
blas_success::T12
condition_number::T13
convergence_failure::T14
solver_failure::T15
max_iters::T16
end
function LinearVerbosity(::None)
return LinearVerbosity(Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent())
end
function LinearVerbosity(::Minimal)
return LinearVerbosity(Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent(), WarnLevel(), WarnLevel(), Silent(), Silent(), Silent(), Silent(), Silent(), Silent())
end
function LinearVerbosity(::All)
return LinearVerbosity(WarnLevel(), InfoLevel(), InfoLevel(), InfoLevel(), CustomLevel(3), CustomLevel(1), InfoLevel(), CustomLevel(1), WarnLevel(), WarnLevel(), InfoLevel(), InfoLevel(), InfoLevel(), WarnLevel(), WarnLevel(), WarnLevel())
end
function LinearVerbosity(::Standard)
return LinearVerbosity(Silent(), Silent(), Silent(), Silent(), CustomLevel(1), Silent(), InfoLevel(), Silent(), WarnLevel(), WarnLevel(), Silent(), Silent(), Silent(), WarnLevel(), WarnLevel(), WarnLevel())
end
function LinearVerbosity(::Detailed)
return LinearVerbosity(WarnLevel(), InfoLevel(), InfoLevel(), Silent(), CustomLevel(2), CustomLevel(1), InfoLevel(), CustomLevel(1), WarnLevel(), WarnLevel(), InfoLevel(), InfoLevel(), Silent(), WarnLevel(), WarnLevel(), WarnLevel())
end
begin
function LinearVerbosity(; preset = nothing, numerical = nothing, performance = nothing, error_control = nothing, kwargs...)
kwargs = NamedTuple(kwargs)
if numerical === nothing && (performance === nothing && (error_control === nothing && (preset === nothing && isempty(kwargs))))
return LinearVerbosity(Silent(), Silent(), Silent(), Silent(), CustomLevel(1), Silent(), InfoLevel(), Silent(), WarnLevel(), WarnLevel(), Silent(), Silent(), Silent(), WarnLevel(), WarnLevel(), WarnLevel())
end
begin
if numerical !== nothing && !(numerical isa AbstractMessageLevel)
throw(ArgumentError("$(:numerical) must be a SciMLLogging.AbstractMessageLevel, got $(typeof(numerical))"))
end
end
begin
if performance !== nothing && !(performance isa AbstractMessageLevel)
throw(ArgumentError("$(:performance) must be a SciMLLogging.AbstractMessageLevel, got $(typeof(performance))"))
end
end
begin
if error_control !== nothing && !(error_control isa AbstractMessageLevel)
throw(ArgumentError("$(:error_control) must be a SciMLLogging.AbstractMessageLevel, got $(typeof(error_control))"))
end
end
if preset !== nothing && !(preset isa AbstractVerbosityPreset)
throw(ArgumentError("preset must be a SciMLLogging.AbstractVerbosityPreset, got $(typeof(preset))"))
end
for (key, value) = pairs(kwargs)
if !(key in (:default_lu_fallback, :no_right_preconditioning, :using_IterativeSolvers, :IterativeSolvers_iterations, :KrylovKit_verbosity, :KrylovJL_verbosity, :HYPRE_verbosity, :pardiso_verbosity, :blas_errors, :blas_invalid_args, :blas_info, :blas_success, :condition_number, :convergence_failure, :solver_failure, :max_iters))
throw(ArgumentError("Unknown verbosity option: $(key). Valid options are: $((:default_lu_fallback, :no_right_preconditioning, :using_IterativeSolvers, :IterativeSolvers_iterations, :KrylovKit_verbosity, :KrylovJL_verbosity, :HYPRE_verbosity, :pardiso_verbosity, :blas_errors, :blas_invalid_args, :blas_info, :blas_success, :condition_number, :convergence_failure, :solver_failure, :max_iters))"))
end
if !(value isa AbstractMessageLevel)
throw(ArgumentError("$(key) must be a SciMLLogging.AbstractMessageLevel, got $(typeof(value))"))
end
end
preset_to_use = if preset === nothing
Standard()
else
preset
end
preset_config = _preset_map_LinearVerbosity[(typeof(preset_to_use)).name.name]
default_lu_fallback = if haskey(kwargs, :default_lu_fallback)
kwargs[:default_lu_fallback]
else
if error_control !== nothing
error_control
else
preset_config[:default_lu_fallback]
end
end
no_right_preconditioning = if haskey(kwargs, :no_right_preconditioning)
kwargs[:no_right_preconditioning]
else
if performance !== nothing
performance
else
preset_config[:no_right_preconditioning]
end
end
using_IterativeSolvers = if haskey(kwargs, :using_IterativeSolvers)
kwargs[:using_IterativeSolvers]
else
if numerical !== nothing
numerical
else
preset_config[:using_IterativeSolvers]
end
end
IterativeSolvers_iterations = if haskey(kwargs, :IterativeSolvers_iterations)
kwargs[:IterativeSolvers_iterations]
else
if numerical !== nothing
numerical
else
preset_config[:IterativeSolvers_iterations]
end
end
KrylovKit_verbosity = if haskey(kwargs, :KrylovKit_verbosity)
kwargs[:KrylovKit_verbosity]
else
if numerical !== nothing
numerical
else
preset_config[:KrylovKit_verbosity]
end
end
KrylovJL_verbosity = if haskey(kwargs, :KrylovJL_verbosity)
kwargs[:KrylovJL_verbosity]
else
if numerical !== nothing
numerical
else
preset_config[:KrylovJL_verbosity]
end
end
HYPRE_verbosity = if haskey(kwargs, :HYPRE_verbosity)
kwargs[:HYPRE_verbosity]
else
if numerical !== nothing
numerical
else
preset_config[:HYPRE_verbosity]
end
end
pardiso_verbosity = if haskey(kwargs, :pardiso_verbosity)
kwargs[:pardiso_verbosity]
else
if numerical !== nothing
numerical
else
preset_config[:pardiso_verbosity]
end
end
blas_errors = if haskey(kwargs, :blas_errors)
kwargs[:blas_errors]
else
if error_control !== nothing
error_control
else
preset_config[:blas_errors]
end
end
blas_invalid_args = if haskey(kwargs, :blas_invalid_args)
kwargs[:blas_invalid_args]
else
if error_control !== nothing
error_control
else
preset_config[:blas_invalid_args]
end
end
blas_info = if haskey(kwargs, :blas_info)
kwargs[:blas_info]
else
if numerical !== nothing
numerical
else
preset_config[:blas_info]
end
end
blas_success = if haskey(kwargs, :blas_success)
kwargs[:blas_success]
else
if numerical !== nothing
numerical
else
preset_config[:blas_success]
end
end
condition_number = if haskey(kwargs, :condition_number)
kwargs[:condition_number]
else
if numerical !== nothing
numerical
else
preset_config[:condition_number]
end
end
convergence_failure = if haskey(kwargs, :convergence_failure)
kwargs[:convergence_failure]
else
if numerical !== nothing
numerical
else
preset_config[:convergence_failure]
end
end
solver_failure = if haskey(kwargs, :solver_failure)
kwargs[:solver_failure]
else
if numerical !== nothing
numerical
else
preset_config[:solver_failure]
end
end
max_iters = if haskey(kwargs, :max_iters)
kwargs[:max_iters]
else
if numerical !== nothing
numerical
else
preset_config[:max_iters]
end
end
return LinearVerbosity(default_lu_fallback, no_right_preconditioning, using_IterativeSolvers, IterativeSolvers_iterations, KrylovKit_verbosity, KrylovJL_verbosity, HYPRE_verbosity, pardiso_verbosity, blas_errors, blas_invalid_args, blas_info, blas_success, condition_number, convergence_failure, solver_failure, max_iters)
end
end
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
The idea here is to automatically generate the struct plus the constructors in such a way that the constructors end up being type stable, with the added benefit that it makes adding toggles and presets much easier than when you have to make the constructors manually.
Currently, you need a tuple of symbols representing toggles, a named tuple where keys are presets, and values are named tuples where the keys are toggles and values are the
AbstractMessageLevelthat is associated with that toggle in that preset. This also allows for a more flexible constructor, where users will be able to set the verbosity specifier to a preset while changing individual settings at the time of construction. So for example if you want a Minimal LinearVerbosity except for:default_lu_fallbackyou can doLinearVerbosity(preset = Minimal(), default_lu_fallback = WarnLevel()).Example
when put through the generator gives