Network Time Out When Writing Result - Compute Server
Hi Team,
I am working with a compute server set up and have python api to pass the model and optimizer and save results in csv. However right after optimal run is complete and results are ready to be retrieved, I get " Network timed out" error and has happened a couple of time now. The run completes in about ~3hrs and face no network timeout issue while it is in progress.
Below is snippet of my code , followed by error-
m.optimize()
m.getVars()
var_names = []
var_values = []
print('Retrieving Variables')
for var in m.getVars():
if var.X > 0:
var_names.append(str(var.varName))
var_values.append(var.X)
with open('/gurobi_shared/gurobi_output/result.csv', 'w') as myfile:
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
wr.writerows(zip(var_names, var_values))
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Sneha,
How big is your model? Also, do you know exactly where in the code the network connection error appears?
Individually querying string-valued attributes like VarName can be very inefficient (see here). Could you try retrieving the variable names and values in bulk using Model.getAttr()?
vars = m.getVars()
var_names = m.getAttr('VarName', vars)
var_values = m.getAttr('X', vars)You can filter out the zero-valued variables afterwards if you want. Also, note that you can use Model.write() to write out a .sol solution file in a very similar style:
m.write('/gurobi_shared/gurobi_output/result.sol')
Thanks,
Eli
0 -
Hi Eli,
Thank you for response. Model is quite big ~45M binary variable and 19K continuous variables. As far as I can tell from logs, the network connection appears right after it defines the var_names and var_Values but maybe somewhere around for (because it does print the python code "Retrieving variables" that sits between the two.
Will add the .sol as backup to get a result after the 3 hrs run. And follow your suggestion for extracting variables all together instead of for.
Thank you!
0
Post is closed for comments.
Comments
3 comments