Skip to content

Catch unsupported keyword argumentsΒ #1051

@bertini97

Description

@bertini97

Describe the bug 🐞

If I change solver but forget to remove an unsupported keyword argument, the error is obscure.

Expected behavior

It is explained to the user that the solver does not support that keyword argument.

Minimal Reproducible Example πŸ‘‡

using OptimizationOptimJL: BFGS

solve(.., BFGS(), epochs=10)

Error & Stacktrace ⚠️

MethodError: no method matching Optim.Options(; extended_trace::Bool, epochs::Int64, callback::OptimizationOptimJL.var"#_cb#12"{OptimizationBase.OptimizationCache{OptimizationFunction{true, AutoEnzyme{Nothing, Nothing}, typeof(loss_ridge), OptimizationEnzymeExt.var"#grad#26"{Tuple{Matrix{Float64}, Matrix{Float64}, Float64}, OptimizationFunction{true, AutoEnzyme{Nothing, Nothing}, typeof(loss_ridge), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, ReverseMode{false, false, false, FFIABI, false, false}}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, OptimizationBase.ReInitCache{Matrix{Float64}, Tuple{Matrix{Float64}, Matrix{Float64}, Float64}}, Nothing, Nothing, Nothing, Nothing, Nothing, BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Optim.Flat}, Bool, OptimizationOptimJL.var"#4#6", Nothing}})
This error has been manually thrown, explicitly, so the method may exist but be intentionally marked as unimplemented.

Closest candidates are:
  Optim.Options(; x_tol, f_tol, g_tol, x_abstol, x_reltol, f_abstol, f_reltol, g_abstol, outer_x_tol, outer_f_tol, outer_g_tol, outer_x_abstol, outer_x_reltol, outer_f_abstol, outer_f_reltol, outer_g_abstol, f_calls_limit, g_calls_limit, h_calls_limit, allow_f_increases, allow_outer_f_increases, successive_f_tol, iterations, outer_iterations, store_trace, trace_simplex, show_trace, extended_trace, show_warnings, show_every, callback, time_limit) got unsupported keyword argument "epochs"
   @ Optim ~/.julia/packages/Optim/7krni/src/types.jl:71
  Optim.Options(::T, ::T, ::T, ::T, ::T, ::T, ::T, ::T, ::T, ::T, ::Int64, ::Int64, ::Int64, ::Bool, ::Bool, ::Int64, ::Int64, ::Int64, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Int64, ::TCallback, ::Float64) where {T, TCallback} got unsupported keyword arguments "extended_trace", "epochs", "callback"
   @ Optim ~/.julia/packages/Optim/7krni/src/types.jl:43

As you can see, in the end it tells you "got unsupported keyword argument 'epochs'", but maybe it's good to catch it before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions