I’m comparing several ways of solving the same problem. One of these approaches create extremely large models, so large that @variable(model, variable[e in edges(graph), d in edges(graph2), v in vertices(graph)]) takes roughly five minutes (yes, just creating the variables). If you want to reproduce (maybe this is a performance bug in JuMP?), here are the sizes:
I don’t believe there is a way to limit the time this operation takes (by cancelling it if it takes too long): I’d like to have something like @variable(model, variable[e in edges(graph), d in edges(graph2), v in vertices(graph)], time_limit=Minute(5)), with Minute coming from Dates. I wouldn’t care if that threw an exception, for instance, to simplify error management.
By the way, I’m using Julia 1.8.2 on Windows 11 x64 and JuMP 1.3.1.
julia> versioninfo()
Julia Version 1.8.2
Commit 36034abf26 (2022-09-29 15:21 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 12 × Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
Threads: 1 on 12 virtual cores
(@v1.8) pkg> status JuMP
Status `C:\Users\Thibaut\.julia\environments\v1.8\Project.toml`
[4076af6c] JuMP v1.3.1
It seems you want to change the API to (optionally) terminate. That’s always possible for some code. A lot of code has timeouts, and you could make a PR to JuMP, though I’m not sure if it’s wanted, too much overhead? [The user couldn’t add timeouts from the calling code (unless your calling code that korks a new Julia process).]
If it’s just a hack, to not take up resources (e.g. on a cluster), you can stop any process after some time, with the timeout command (I guess e.g. Windows might have similar, or could do in WSL2):
but you got me interested in knowing if you can stop some code from within the program, and my first thought was start it as a thread, and if there’s a way to time-limit it. That doesn’t seem to be the case in most languages, at least not Julia (safely, is it still possible, if you basically want to terminate after?) or C (likely possible in Elixir/Erlang, and Java?):
julia> using JuMP
julia> function main(flag)
model = Model()
set_string_names_on_creation(model, flag)
@variable(model, x[1:386, 1:596, 1:149])
return model
end
main (generic function with 1 method)
julia> @time main(false)
6.122188 seconds (68.56 M allocations: 4.652 GiB, 22.75% gc time)
A JuMP Model
Feasibility problem with:
Variables: 34278344
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.
Names registered in the model: x
julia> @time main(true)
ERROR: InterruptException:
# [ ... I didn't want to wait ...]