lanl-ansi / Juniper.jl

A JuMP-based Nonlinear Integer Program Solver
https://lanl-ansi.github.io/Juniper.jl/stable/
MIT License
179 stars 22 forks source link

KNITRO as nl_solver in Juniper #252

Closed GabrielPonte closed 2 years ago

GabrielPonte commented 2 years ago

This issue is related to the KNITRO Issue #231. I've been trying to use KNITRO as nl_solver, but to no avail. From what I understand, it's not possible to call it directly because KNITRO doesn't support adding constraints after optimize! In the KNITRO Issue, it was suggested using caching optimizer and it worked perfectly with MOI, but can I call nl_solver using caching optimizer? I tried to do

 nl_solver = MOI.Utilities.CachingOptimizer(
    MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
    KNITRO.Optimizer(),
)

but I received this error The provided optimizer_constructor is invalid. It must be callable with zero arguments. For example, "Ipopt.Optimizer" or "() -> ECOS.Optimizer()". It should not be an instantiated optimizer like "Ipopt.Optimizer()" or "ECOS.Optimizer()". (Note the difference in parentheses!) and if I try without parenthesis, I get this error MethodError: no method matching MathOptInterface.Utilities.CachingOptimizer(::MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}, ::Type{KNITRO.Optimizer})

ccoffrin commented 2 years ago

@odow can you field this one?

odow commented 2 years ago

You need to pass a function which creates an optimizer

nl_solver = () -> MOI.Utilities.CachingOptimizer(
    MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
    KNITRO.Optimizer(),
)
GabrielPonte commented 2 years ago

Thank you!