Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch [CTRL+C] and gracefully exit #349

Merged
merged 6 commits into from
Oct 5, 2020
Merged

Catch [CTRL+C] and gracefully exit #349

merged 6 commits into from
Oct 5, 2020

Conversation

odow
Copy link
Member

@odow odow commented Sep 29, 2020

Closes #52
Closes #53

An updated attempt at #52, inspired by #53.

Does anyone watching this repository have access to a Windows machine they could test this on?

Throwing an interrupt from a callback worked, but on Mac, I could not get a script to exit correctly on CTRL+C. I have to hold down CTRL+C to force a SIGINT, and then I get a Gurobi Error 10017, OPTIMIZATION_IN_PROGRESS.

ERROR: Gurobi Error 10017: 
Stacktrace:
 [1] _check_ret at /Users/oscar/.julia/dev/Gurobi/src/MOI_wrapper.jl:266 [inlined]
 [2] _get_intattr(::Gurobi.Optimizer, ::String) at /Users/oscar/.julia/dev/Gurobi/src/MOI_wrapper.jl:2398
 [3] _is_mip at /Users/oscar/.julia/dev/Gurobi/src/MOI_wrapper.jl:2429 [inlined]
 [4] get(::Gurobi.Optimizer, ::MathOptInterface.DualStatus) at /Users/oscar/.julia/dev/Gurobi/src/MOI_wrapper.jl:2436
 [5] optimize!(::Gurobi.Optimizer) at /Users/oscar/.julia/dev/Gurobi/src/MOI_wrapper.jl:2335
 [6] top-level scope at /Users/oscar/.julia/dev/Gurobi/interrupt.jl:17
 [7] include(::Function, ::Module, ::String) at ./Base.jl:380
 [8] include(::Module, ::String) at ./Base.jl:368
 [9] exec_options(::Base.JLOptions) at ./client.jl:296
 [10] _start() at ./client.jl:506
in expression starting at /Users/oscar/.julia/dev/Gurobi/interrupt.jl:17

Here is the script I was running:

using Gurobi
const MOI = Gurobi.MOI

download(
    "ftp://ftp.numerical.rl.ac.uk/pub/cuter/netlib/QAP12.SIF",
    "QAP12.mps"
)
mps = MOI.FileFormats.MPS.Model()
MOI.read_from_file(mps, "QAP12.mps")
model = Gurobi.Optimizer()
MOI.copy_to(model, mps)
MOI.add_constraint.(
    model,
    MOI.get(model, MOI.ListOfVariableIndices()),
    MOI.Integer(),
);
MOI.optimize!(model)
@show MOI.get(model, MOI.PrimalStatus())
@assert MOI.get(model, MOI.TerminationStatus()) == MOI.INTERRUPTED

I'll reach out to Gurobi support. Not sure if this is publicly accessible, but here is the support ticket: https://support.gurobi.com/hc/en-us/requests/12868.

@odow
Copy link
Member Author

odow commented Sep 29, 2020

Updated GIF with the latest commit. We successfully interrupt with a feasible primal solution.
ezgif com-video-to-gif-2

image

@odow odow changed the title WIP: Catch [CTRL+C] and gracefully exit Catch [CTRL+C] and gracefully exit Sep 29, 2020
@odow
Copy link
Member Author

odow commented Oct 4, 2020

Barring objections, I'll leave this open for another 48 hours, then merge.

@blegat
Copy link
Member

blegat commented Oct 4, 2020

Works for me too with your example

julia> versioninfo()
Julia Version 1.5.0
Commit 96786e22cc (2020-08-01 23:44 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)

julia> MOI.optimize!(model)
Gurobi Optimizer version 9.0.3 build v9.0.3rc0 (linux64)
Optimize a model with 3192 rows, 8856 columns and 38304 nonzeros
Model fingerprint: 0xb5c0f40e
Variable types: 0 continuous, 8856 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [2e+00, 1e+02]
  Bounds range     [0e+00, 0e+00]
  RHS range        [1e+00, 1e+00]
Presolve time: 0.08s
Presolved: 3192 rows, 8856 columns, 38304 nonzeros
Variable types: 0 continuous, 8856 integer (8856 binary)
Found heuristic solution: objective 724.0000000

Root simplex log...

Iteration    Objective       Primal Inf.    Dual Inf.      Time
   19534    3.5605418e+02   1.925783e+05   0.000000e+00      5s
   29944    4.2440709e+02   2.400263e+05   0.000000e+00     10s
   36504    4.5645955e+02   1.263004e+05   0.000000e+00     15s
   42934    4.7864415e+02   4.219360e+03   0.000000e+00     20s
   49554    4.9218340e+02   7.402823e+04   0.000000e+00     25s
   55524    5.0254681e+02   6.533896e+04   0.000000e+00     30s
   61624    5.0807071e+02   2.470515e+05   0.000000e+00     35s
   67314    5.1246736e+02   5.730068e+02   0.000000e+00     40s
   72334    5.1533665e+02   1.126381e+03   0.000000e+00     45s
^C
Root relaxation: interrupted, 76764 iterations, 48.21 seconds

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0          -    0       724.00000    0.00000   100%     -   48s

Explored 0 nodes (76764 simplex iterations) in 48.33 seconds
Thread count was 8 (of 8 available processors)

Solution count 1: 724 

Solve interrupted
Best objective 7.240000000000e+02, best bound 0.000000000000e+00, gap 100.0000%

User-callback calls 1348, time in user-callback 0.01 sec

julia> MOI.get(model, MOI.TerminationStatus())
INTERRUPTED::TerminationStatusCode = 23

julia> MOI.get(model, MOI.RawStatusString())
"Optimization was terminated by the user."

@odow odow merged commit d0e573d into master Oct 5, 2020
@odow odow deleted the od/ctrl-c branch October 5, 2020 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Segfault on ctrl-c
2 participants