OSQP.jl icon indicating copy to clipboard operation
OSQP.jl copied to clipboard

OSQP.Optimizer doesn't handle kwargs correctly

Open qua4tre opened this issue 2 years ago • 1 comments

The following gives me an error:

julia> OSQP.Optimizer(max_iter=10)
ERROR: MethodError: Cannot `convert` an object of type Symbol to an object of type String
Closest candidates are:
  convert(::Type{String}, ::String) at essentials.jl:218
  convert(::Type{T}, ::T) where T<:AbstractString at strings/basic.jl:231
  convert(::Type{T}, ::AbstractString) where T<:AbstractString at strings/basic.jl:232   
  ...
Stacktrace:
 [1] MathOptInterface.RawOptimizerAttribute(name::Symbol)
   @ MathOptInterface ~\.julia\packages\MathOptInterface\src\attributes.jl:868
 [2] OSQP.MathOptInterfaceOSQP.Optimizer(; kwargs::Base.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:max_iter,), Tuple{Int64}}})
   @ OSQP.MathOptInterfaceOSQP ~\.julia\packages\OSQP\src\MOI_wrapper.jl:81
 [3] top-level scope
   @ REPL[12]:1

The backtrace points to the following lines in MOI_wrapper.jl:

for (key, value) in kwargs
    MOI.set(optimizer, MOI.RawOptimizerAttribute(key), value)
end

I looked up the call signature for RawOptimizerAttribute in MathOptInterface and it's RawOptimizerAttribute(name::String). So I think the keys need to be converted into Strings. Or add support in MathOptInterface for RawOptimizerAttribute(name::Symbol)? If that's preferable, I can open an issue over there instead.

qua4tre avatar Feb 16 '23 20:02 qua4tre

Yes, not that passing these in the constructor is deprecated (which is why this error was overlooked), you should use JuMP.optimizer_with_attributes

blegat avatar Feb 17 '23 08:02 blegat