jump-dev / HiGHS.jl

A Julia interface to the HiGHS solver
https://highs.dev
MIT License
103 stars 14 forks source link

MethodError: no method matching _set_option(::HiGHS.Optimizer, ::String, ::Nothing) #118

Closed sambuddhac closed 2 years ago

sambuddhac commented 2 years ago

Hi, I am facing the following error while trying to run our GenX model written in Julia/JuMP with HiGHS. Can someone please help?

ERROR: LoadError: MethodError: no method matching _set_option(::HiGHS.Optimizer, ::String, ::Nothing)
Closest candidates are:
  _set_option(::HiGHS.Optimizer, ::String, ::Bool) at /Users/sc87/.julia/packages/HiGHS/YP79q/src/MOI_wrapper.jl:485
  _set_option(::HiGHS.Optimizer, ::String, ::Integer) at /Users/sc87/.julia/packages/HiGHS/YP79q/src/MOI_wrapper.jl:489
  _set_option(::HiGHS.Optimizer, ::String, ::AbstractFloat) at /Users/sc87/.julia/packages/HiGHS/YP79q/src/MOI_wrapper.jl:493
  ...
Stacktrace:
 [1] set(model::HiGHS.Optimizer, param::MathOptInterface.RawParameter, value::Nothing)
   @ HiGHS ~/.julia/packages/HiGHS/YP79q/src/MOI_wrapper.jl:506
 [2] _instantiate_and_check(optimizer_constructor::MathOptInterface.OptimizerWithAttributes)
   @ MathOptInterface ~/.julia/packages/MathOptInterface/YDdD3/src/instantiate.jl:88
 [3] instantiate(optimizer_constructor::MathOptInterface.OptimizerWithAttributes; with_bridge_type::Type{Float64}, with_names::Bool)
   @ MathOptInterface ~/.julia/packages/MathOptInterface/YDdD3/src/instantiate.jl:120
 [4] set_optimizer(model::JuMP.Model, optimizer_constructor::MathOptInterface.OptimizerWithAttributes; bridge_constraints::Bool)
   @ JuMP ~/.julia/packages/JuMP/Xrr7O/src/optimizer_interface.jl:109
 [5] JuMP.Model(optimizer_factory::MathOptInterface.OptimizerWithAttributes; bridge_constraints::Bool, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ JuMP ~/.julia/packages/JuMP/Xrr7O/src/JuMP.jl:287
 [6] Model
   @ ~/.julia/packages/JuMP/Xrr7O/src/JuMP.jl:286 [inlined]
 [7] generate_model(setup::Dict{Any, Any}, inputs::Dict{Any, Any}, OPTIMIZER::MathOptInterface.OptimizerWithAttributes, modeloutput::Nothing)
   @ GenX ~/code/GenX_Fork/GenX/src/model/generate_model.jl:99
 [8] generate_model(setup::Dict{Any, Any}, inputs::Dict{Any, Any}, OPTIMIZER::MathOptInterface.OptimizerWithAttributes)
   @ GenX ~/code/GenX_Fork/GenX/src/model/generate_model.jl:92
 [9] top-level scope
   @ ~/code/GenX_Fork/GenX/Example_Systems/SmallNewEngland/OneZone/Run.jl:63
in expression starting at /Users/sc87/code/GenX_Fork/GenX/Example_Systems/SmallNewEngland/OneZone/Run.jl:63

Our code segment consists of a function that looks like this:

function configure_highs(solver_settings_path::String)
    solver_settings = YAML.load(open(solver_settings_path))

    # Optional solver parameters ############################################
    MyFeasibilityTol = 1e-6 # Constraint (primal) feasibility tolerances. See https://github.com/jump-dev/HiGHS.jl, https://github.com/ERGO-Code/HiGHS, and https://highs.dev/
        if(haskey(solver_settings, "Feasib_Tol")) MyFeasibilityTol = solver_settings["Feasib_Tol"] end
    MyOptimalityTol = 1e-6  # Dual feasibility tolerances. See https://github.com/jump-dev/HiGHS.jl, https://github.com/ERGO-Code/HiGHS, and https://highs.dev/
        if(haskey(solver_settings, "Optimal_Tol")) MyOptimalityTol = solver_settings["Optimal_Tol"] end
    MyPresolve = "choose"   # Controls presolve level. See https://github.com/jump-dev/HiGHS.jl, https://github.com/ERGO-Code/HiGHS, and https://highs.dev/
        if(haskey(solver_settings, "Pre_Solve")) MyPresolve = solver_settings["Pre_Solve"] end
    MyTimeLimit = Inf   # Limits total time solver. See https://www.gurobi.com/documentation/8.1/refman/timelimit.html
        if(haskey(solver_settings, "TimeLimit")) MyTimeLimit = solver_settings["TimeLimit"] end

.....

OPTIMIZER = optimizer_with_attributes(HiGHS.Optimizer,
        "primal_feasibility_tolerance" => MyFeasibilityTol,
        "dual_feasibility_tolerance" => MyOptimalityTol,
        "time_limit" => MyTimeLimit
    )

    return OPTIMIZER

end

This OPTIMIZER is then used to build our model.

odow commented 2 years ago

What versions are you using?

MathOptInterface.RawParameter

This suggests you're trying to use a very old version of MathOptInterface.

odow commented 2 years ago

set(model::HiGHS.Optimizer, param::MathOptInterface.RawParameter, value::Nothing)

This also suggests you're trying to set a value that is nothing. What are the values of MyFeasibilityTol, MyOptimalityTol , and MyTimeLimit?

sambuddhac commented 2 years ago

MathOptInterface version I am using is 0.9.22 and here are the values

Feasib_Tol: 1.0e-07        # Primal feasibility tolerance # [type: double, advanced: false, range: [1e-10, inf], default: 1e-07]
Optimal_Tol: 1.0e-07       # Dual feasibility tolerance # [type: double, advanced: false, range: [1e-10, inf], default: 1e-07]
TimeLimit: Inf 
odow commented 2 years ago

Do you have a reproducible example? I can't reproduce:

julia> import HiGHS

julia> const MOI = HiGHS.MOI
MathOptInterface

julia> model = MOI.OptimizerWithAttributes(
           HiGHS.Optimizer,
           "primal_feasibility_tolerance" => 1e-7,
           "dual_feasibility_tolerance" => 1e-6,
           "time_limit" => Inf
       )
MathOptInterface.OptimizerWithAttributes(HiGHS.Optimizer, Pair{MathOptInterface.AbstractOptimizerAttribute, Any}[MathOptInterface.RawParameter("primal_feasibility_tolerance") => 1.0e-7, MathOptInterface.RawParameter("dual_feasibility_tolerance") => 1.0e-6, MathOptInterface.RawParameter("time_limit") => Inf])

julia> MOI.instantiate(model)
A HiGHS model with 0 columns and 0 rows.

(hgh) pkg> st
      Status `/private/tmp/hgh/Project.toml`
  [87dc4568] HiGHS v0.2.3
  [b8f27783] MathOptInterface v0.9.22

But also, you should update to JuMP and MOI v1.0.

odow commented 2 years ago

I have a fix that would at least give a better error message for this: https://github.com/jump-dev/HiGHS.jl/pull/119

But it won't help unless you update to MathOptInterface v1.0.

odow commented 2 years ago

I'll re-open this until we sort the problem. But my guess is that you're trying to pass some option as nothing by mistake. This will report a nicer error on the latest release, but we won't be back porting to HiGHS v0.3.2.

sambuddhac commented 2 years ago

Thank you @odow , can you please also tell me the JuMP version I should upgrade to? I'll be in touch, until we fix this problem. Much appreciated.

sambuddhac commented 2 years ago

Okay, I did a fresh build of Project.toml and Manifest.toml with the latest compatible versions. Here is the environment:

  [6e4b80f9] BenchmarkTools v1.3.1
  [336ed68f] CSV v0.10.4
  [9961bab8] Cbc v1.0.1
  [e2554f3b] Clp v1.0.1
  [aaaa29a8] Clustering v0.14.2
  [861a8166] Combinatorics v1.0.2
  [a93c6f00] DataFrames v1.3.4
  [864edb3b] DataStructures v0.18.13
  [41bf760c] DiffEqSensitivity v6.79.0
  [b4f34e82] Distances v0.10.7
  [e30172f5] Documenter v0.27.19
  [35a29f4d] DocumenterTools v0.1.14
  [60bf3e95] GLPK v1.0.1
  [87dc4568] HiGHS v1.1.3
  [b6b21f68] Ipopt v1.0.2
  [4076af6c] JuMP v1.1.1
  [b8f27783] MathOptInterface v1.6.0
  [fdba3010] MathProgBase v0.7.8
  [1dea7af3] OrdinaryDiffEq v6.18.1
  [8a4e6c94] QuasiMonteCarlo v0.2.9
  [731186ca] RecursiveArrayTools v2.31.0
  [2913bbd2] StatsBase v0.33.18
  [ddb6d928] YAML v0.4.7
  [ade2ca70] Dates
  [37e2e46d] LinearAlgebra
  [9a3f8284] Random
  [10745b16] Statistics

But, I still keep on getting the same error.

sambuddhac commented 2 years ago

As a test system, you can run my fork of GenX here:

https://github.com/sambuddhac/GenX

When you are there, please cd inside GenX/Example_Systems/SmallNewEngland/OneZone and do julia Run.jl

The way it's currently configured, will create the environment and run and in the model creation stage, you can see the error message I am getting. Also, for your convenience (and also as you'll see from the error log) the program floe is from the Run.jl file to GenX/src/model/generate_model.jl and the code snippets I sent earlier are in the GenX/src/configure_solver/configure_highs.jl. Also, the settings files are inside the GenX/Example_Systems/SmallNewEngland/OneZone/Settings folder,

Please let me know if you have more questions and if I can provide further help.

Thank you so very much !!!

sambuddhac commented 2 years ago

PR #120 fixes this. Can you please review and merge PR #120? Thank you very much !!!