Skip to content

Strange error when using Gurobi and TimeLimit #467

@KanaBaradei

Description

@KanaBaradei

Version Checks (indicate both or one)

  • I have confirmed this bug exists on the lastest release of Linopy.

  • I have confirmed this bug exists on the current master branch of Linopy.

Issue Description

Hi, I was playing around with some settings in a model and found a strange behaviour when using the TimeLimit option of gurobi. I've tried with a feasible solution found and without one, and in both cases when the time limit is reached the results are shown below. (I've modified part of the directory with "..." for privacy reasons)

File "...\Python\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
self.run()
File "...\Python\Python311\Lib\threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "..." line 1018, in solvemodel
m.solve(solver_name='gurobi',**opt)
File "...\Python\Python311\Lib\site-packages\linopy\model.py", line 1060, in solve
result = func(
^^^^^
File "...\Python\Python311\Lib\site-packages\linopy\solvers.py", line 679, in run_gurobi
solution = safe_get_solution(status, get_solver_solution)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\Python\Python311\Lib\site-packages\linopy\solvers.py", line 117, in safe_get_solution
return func()
^^^^^^
File "...\Python\Python311\Lib\site-packages\linopy\solvers.py", line 665, in get_solver_solution
sol = pd.Series({v.VarName: v.x for v in m.getVars()}, dtype=float)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\Python\Python311\Lib\site-packages\linopy\solvers.py", line 665, in
sol = pd.Series({v.VarName: v.x for v in m.getVars()}, dtype=float)
^^^
File "src\gurobipy\var.pxi", line 128, in gurobipy._core.Var.getattr
File "src\gurobipy\var.pxi", line 156, in gurobipy._core.Var.getAttr
File "src\gurobipy\_attrutil.pyx", line 117, in gurobipy._attrutil._getattr
AttributeError: Unable to retrieve attribute 'x'. Did you mean: 'X'?`

Reproducible Example

Too long to put in here but basically I get the error everytime I hit the time limit.

Expected Behavior

I would expect the solve to finish with either a message from the solver in the case of no solution found within the time, sort of model.status=not ok, or to get the suboptimal solution back. From what I can gather in the error it seems to be a problem with linopy grabbing the variables back or something, for context the "x" value there is the name of one of the variables in the model.

Installed Versions

Latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions