model.setParam('TimeLimit', )doesn't seem to work.
Answeredmodel.setParam('TimeLimit', 2000)
Should I switch to worklimit instead? the code is taking too long?
How do I know if the code is actually stuck due to problems in constraints or the computation time is just too high?
Does @njit work with gurobi? (from numba package)
Is quicksum faster than sum? And are there times when I can't use quicksum?

Should I switch to worklimit instead? the code is taking too long?
How do I know if the code is actually stuck due to problems in constraints or the computation time is just too high?
What do you mean by "the code is taking too long"? Do you mean the time to build the model is longer than 2000 seconds? Or do you mean the solve time is longer than 2000 seconds?
 The solver parameters including the \(\texttt{TimeLimit}\) parameter control the behaviour of the solver and do not affect the model building time. Setting \(\texttt{TimeLimit}\) to 2000 seconds starts measuring the time when the model.optimize() method is called.
 It is true that the optimization may not stop immediately upon hitting the time limit. It might need to perform additional computational steps to gracefully terminate the solver. However, we do not expect for the additional computational steps to result in a runtime significantly larger than the time limit set a priori.
Is quicksum faster than sum? And are there times when I can't use quicksum?
The \(\texttt{gurobipy.quicksum()}\) is much more efficient than the Python \(\texttt{sum}\) function for building large Gurobi expressions. You can use \(\texttt{gurobipy.quicksum()}\) anywhere you can use the Python \(\texttt{sum}\) function.
Does @njit work with gurobi? (from numba package)
I am not very familiar with numba. The Gurobi Python API is a thin layer on top of our Clibrary, so I do not think you can obtain any meaningful speedup by optimizing the Gurobi API calls via numba compiler. Please follow the suggestions provided in your other post to speed up the model building time.
Best regards,
Maliheh
0 
Thank you for your response.
I used jupyter to construct constraints one by one, and I found that 2 constraints in particular take too long to construct. So you're right, that's why timelimit doesn't work in that case.
So I found where the bottelneck. Basically each of these constraints has a bout 7 million constraints. because it includes combinations of parameters.
Is there a way I can make this more efficient using vectorization techniques in gurobi?
I am not sure what libraries in python work well with gurobi.
0 
You can consider using Gurobi's matrixfriendly API which significantly improved in version 10.0.0. The matrix API leans on numpy concepts and semantics such as vectorization and broadcasting which can be significantly faster than the termbased modelling.
Please checkout the Matrixfriendly Modeling with gurobipy webinar for an overview of the matrix API.
Best regards,
Maliheh
0
Please sign in to leave a comment.
Comments
3 comments