Account for transformation time in model.solve#803
Conversation
|
Don't you have the risk that the time gets negative and the solver would throw an error? In the case that the transformations take too long. |
|
This is a tricky topic that we have discussed internally a couple of times which has a lot of caveats. So this should be more of a discussion topic. Challenging parts / open questions:
But it would definitely be something nice to have, since right now we hack something together for running in competitions, conceptually implementing a custom |
|
I agree it should have been a discussion topic. Let me know if it's already internally discussed a lot, and I'm not adding a lot of new ideas, but my replies to the above points would be:
|
|
For point 2 I would say that after the transformations are done you can indeed simply check the time and then without even calling solve return UNKNOWN status. The ValueError seems to be more of a error that should be thrown to the user when they themselves give a negative timeout, not something we should use to stop the solving. |
|
For those interested, the current way to take transformation time into account is by doing the following: Instead of model.solve(solver="ortools", time_limit=60) # example of time limit of 60s, only on the solve part (not taking transformation into account)You can do start = time.time()
s = cp.SolverLookup().get("ortools", model) # This will only do the transformation to the solver backend, without solving
end = time.time()
transformation_time = end - start
s.solve(time_limit=60-transformation_time) # Now solve without re-transforming, run with remaining timeOffcourse this still doesn't take all overhead into account, so more can be subtracted if needed (e.g. a small fixed buffer). |
|
I'm in favor of changing the It also exposes another aspect of that neglection: that So perhaps we need a bit of a more throurough change to capture all things discussed here, e.g. maybe something like:
I would keep a similar exercise on SolveAll as a separate issue/PR |
Generally, we are not accounting for the pre-processing time (mostly transformation) in the given
time_limit, nor in the reported solve time (i.e.slv.status().runtimewill return the solve time without transformation; which means users should really time CPMpy themselves if they want to be accurate).I'm not sure if we need to take some larger action here, but this simple change will at least subtract transformation time from the solve time when you solve directly from the model. There could be adverse effects, perhaps where now the user may not realize that these situations are now different:
One way to make it more consistent would be to not immediately transform the model upon
cp.solvers.CPM_ortools(model), instead waiting until the actual solve call.