jump-dev / ECOS.jl

A Julia interface to the ECOS conic optimization solver
https://github.com/embotech/ecos
Other
41 stars 17 forks source link

Claims that OPTIMIZE_NOT_CALLED if it runs out of Iterations #113

Closed oxinabox closed 3 years ago

oxinabox commented 3 years ago

Consider this code based on the code from the readme: Only difference from readme is we cap "maxit" at 3 -- it needs 6 to complete successfully

using JuMP
using ECOS

optimizer = optimizer_with_attributes(ECOS.Optimizer, "maxit" => 3)

items  = [:Gold, :Silver, :Bronze]
values = Dict(:Gold => 5.0,  :Silver => 3.0,  :Bronze => 1.0)
weight = Dict(:Gold => 2.0,  :Silver => 1.5,  :Bronze => 0.3)

model = Model(optimizer)
@variable(model, 0 <= take[items] <= 1)  # Define a variable for each item
@objective(model, Max, sum(values[item] * take[item] for item in items))
@constraint(model, sum(weight[item] * take[item] for item in items) <= 3)
optimize!(model)

termination_status(model)

This is the output:

julia> optimize!(model)

ECOS 2.0.5 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS

It     pcost       dcost      gap   pres   dres    k/t    mu     step   sigma     IR    |   BT
 0  -5.808e+00  -1.695e+01  +8e+00  5e-03  3e-01  1e+00  1e+00    ---    ---    1  1  - |  -  -
 1  -7.021e+00  -8.183e+00  +9e-01  4e-04  4e-02  8e-02  1e-01  0.8975  1e-02   0  0  0 |  0  0
 2  -7.342e+00  -7.486e+00  +1e-01  5e-05  5e-03  1e-02  2e-02  0.9055  3e-02   0  0  0 |  0  0
 3  -7.399e+00  -7.401e+00  +2e-03  7e-07  6e-05  2e-04  2e-04  0.9867  6e-04   0  0  0 |  0  0
Maximum number of iterations reached, stopping.

RAN OUT OF ITERATIONS (reached feastol=6.3e-05, reltol=2.1e-04, abstol=1.5e-03).
Runtime: 0.000062 seconds.

julia> termination_status(model)
OPTIMIZE_NOT_CALLED::TerminationStatusCode = 0

It seems it is returning the wrong code, optimize was called, it just didn't succeed. I believe It should be returning ITERATION_LIMIT

raw_status also seems to be doing the wrong thing

julia> JuMP.raw_status(model)
ERROR: OptimizeNotCalled()

This error was confusing to me, since I assumed I had some how messed up my code somewhere and not called optimize!.


(jl_FtIZTw) pkg> st
Status `/private/var/folders/1r/4cjj1xk90qbb6njj7dn_cmt40000gn/T/jl_FtIZTw/Project.toml`
  [e2685f51] ECOS v0.12.1
  [4076af6c] JuMP v0.21.5

julia> versioninfo()
Julia Version 1.5.4-pre.0
Commit 599ecd8210 (2020-11-10 10:50 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.6.0)
  CPU: Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
blegat commented 3 years ago

https://github.com/jump-dev/ECOS.jl/pull/114 should solve it, can you confirm ?

oxinabox commented 3 years ago

Confirmed it fixes it