Type error and Gurobi error
OngoingDear Gurobi Team,
Please I am running my Pyomo model which uses Gurobi solver on an HPC platform (linux system). I was advised to save my gurobi solver results while running (to create checkpoints).
Through the help of the Pyomo team, I came up with the following Callback code to save my results:
def mycallback(cb_m, cb_opt, cb_where):
if cb_where == GRB.Callback.MIPSOL:
obj = cb_opt.cbGet(GRB.Callback.MIPSOL_OBJ)
nodecnt = int(cb_opt.cbGet(GRB.Callback.MIPSOL_NODCNT))
solcnt = cb_opt.cbGet(GRB.Callback.MIPSOL_SOLCNT)
var_list = [v for v in model.component_data_objects(Var, descend_into=True)]
var_sol = cb_opt.cbGetSolution(vars=var_list)
for v, v_sol in list(zip(var_list, var_sol)):
print(v, v_sol)
cb_opt.write("mip_14_days.sol")
But when I run my model, I get the following error (excerpt):
Exception ignored in: 'gurobipy.callbackstub'
Traceback (most recent call last):
File "src/gurobipy/callback.pxi", line 180, in gurobipy.CallbackClass.callback
self._callback_func(self._pyomo_model, self, where)
File "improving_model_performance_new4_10_weeks.py", line 2118, in mycallback
for v, v_sol in zip(var_list, var_sol):
TypeError: 'NoneType' object is not iterable
File "src/gurobipy/model.pxi", line 847, in gurobipy.Model.optimize
gurobipy.GurobiError: Unable to write file
I have tried to find how to resolve this problem but unable to. Please can you advice me what to do from the line of code I provide above.
Also I want to ask if the 'SolFiles' parameter works from the Pyomo interface as I do not see where the files are saved. (I set 'SolFiles':"~/Project_folder/mymodel15" in my model but cannot find the file mymodel15)
Thank you for your kind assistance
-
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?. -
You unfortunately can't call Model.write() during the solution process. You would have to write your own solution file using Python's built-in file writing. In addition, it seems there is a problem with the way variables and their values are retrieved from Pyomo in the callback.
Assuming you are using Gurobi 9.0 or later, the SolFiles parameter you mentioned is the easiest way to save intermediate solutions. It should work through the Pyomo interface. Can you try passing the full path name (e.g., \( \texttt{/home/ayo/Project_folder/mymodel15} \)) to the SolFiles parameter? The tilde \( \texttt{~} \) shortcut is resolved by your shell, so it won't necessarily work as expected when used outside a shell environment.
0 -
Thank you so much Eli. SolFiles worked as you mentioned.
0 -
Hey,
I got a gurobipy.GurobiError as well but there is no specification of what exactly went wrong.
That's the error:
File "...", line 109, in <module>
m.optimize(subtourelim)
File "src\gurobipy\model.pxi", line 864, in gurobipy.Model.optimize
gurobipy.GurobiErrorI haven't found any information on solving this.
Can you help me?0
Post is closed for comments.
Comments
4 comments