user3548298
user3548298

Reputation: 196

Julia interrupt model solver and resume it

I'm running an optimization problem on Atom, using Julia.

The solver I use is Gurobi:

m=Model(solver=GurobiSolver())
...
solve(m)

My model may need hours to days of computation to reach the optimal value, so I would like to know if I can do the following when solve() is running :

1. Interrupt upon interrupting/stopping Julia
2. Interrupt if the objective function returns a sufficiently good result
3. Interrupt after a set time

and then display and save the current state reached so I can resume the computation later.

Upvotes: 0

Views: 535

Answers (2)

user3548298
user3548298

Reputation: 196

Set SolutionLimit or TimeLimit as GurobiSolver parameters

Upvotes: 0

sascha
sascha

Reputation: 33532

Disclaimer:

That's very broad and misses a lot of details why mentioning things which do not matter (Atom as Editor).

Also: consider this as educated guess.

Can do

  • display something and wait in terminal
  • continue after user-input

This should be easily achievable by defining a callback, which goes through your conditions and act according to these (e.g. waiting some seconds or for user-input).

There is one thing to decide on: Gurobi's Callback Codes of types where, which will decide when your callback is called.

For going through your conditions, you will want to use the values for what (see above docs).

Viable candidates:

POLLING 0   Periodic polling callback
MIPSOL  4   Found a new MIP incumbent

Now polling will in general not allow you to query what values. This makes it pretty useless for your task and we won't consider it. The only advantage is that it's probably very frequently called, without a potentially huge variance of times between calls.

MIPSOL would allow you to get access to the interesting variables like MIP_OBJBST (current best objective) and co.

The core assumption here: Gurobi has no callback-timelimit and kills off your callback (safeguard-like). I don't think there is something like that (at least not without a warning in the docs)!

Cannot do

In general, you can't save the whole state of Gurobi (link applies to Gurobi 7). From a software-engineering-based standpoint, it's not too surprising (not impossible, but potentially tricky).

Can do

You can turn-off your computer (hibernation!), while solving or while being in some waiting-state in your callback. Now i will say it again: we are talking about Hibernation of Operating-systems. Either a suspend-to-ram (PC will use less energy) or suspend-to-disk (completely off).

Now:

  • this will destroy internal-timings (which you can observe in the verbose output)
    • not sure if relevant for you (maybe in interaction with your callback!)
    • warning: i could imagine that there are some statistics / interactive-learning based heuristic decisions (approach A worked in this part of the tree good; do A again) based on timings (as operations are harder to count)
      • it's not impossible that those statistics are completely taken off-balance by hibernation!
  • this depends in it's core on your Operating-sytem
  • this is probably not guaranteed to work or recommended by the Gurobi-devs, but might work (and does run; but it's harder to evaluate the impact on the solution-process)
    • we already saw, that things might change during sleep (time) and assumptions on these things are the potential problem

Can do

Using callbacks and queries on internal-states as mentioned above, you can use your own kind of serialization to outsource the current best solution and maybe more.

These things, the most important being the MIP start vector you can later use for a completely newly started optimization-process.

You need to decide on how to serialize this data. Database, HDF5, Text-files and co.!

Reading out and Reusing should follow Gurobi's docs.

Now:

  • starting from a feasible MIP-solution (your best found yet) is not as good as reusing the whole internal state (we are losing a lot of solving-process dependent information)
    • but it should help a lot in general (probably depends much on the problem itself)
  • you can try to store and re-add the objective-bound as constraint, but i don't think it will help much

Upvotes: 2

Related Questions