PyPSA / linopy

Linear optimization with N-D labeled arrays in Python
https://linopy.readthedocs.io
MIT License
154 stars 42 forks source link

Error using scip #262

Closed apfelix closed 2 months ago

apfelix commented 3 months ago

Hi,

I encountered a problem using SCIP with the model attached as linopy_pyscipopt_bug.txt (I used the extension .txt to allow the github update).

Then the following code

import linopy

m = linopy.read_netcdf("linopy_pyscipopt_bug.txt")
m.solve(solver_name="scip")

leads to

...
  2.4s|     1 |     0 |  3568 |     - |    20M |   0 |1212 |1294 |1533 | 170 | 34 |  26 |  23 |-1.900244e+02 |-1.900248e+02 |   0.00%| unknown
  2.4s|     1 |     0 |  3571 |     - |    20M |   0 |1212 |1294 |1521 | 171 | 35 |  26 |  23 |-1.900244e+02 |-1.900248e+02 |   0.00%| unknown
 time | node  | left  |LP iter|LP it/n|mem/heur|mdpt |vars |cons |rows |cuts |sepa|confs|strbr|  dualbound   | primalbound  |  gap   | compl. 
  2.4s|     1 |     0 |  3578 |     - |    20M |   0 |1212 |1272 |1521 | 171 | 36 |  31 |  26 |-1.900247e+02 |-1.900248e+02 |   0.00%| unknown
  2.4s|     1 |     2 |  3578 |     - |    20M |   0 |1212 |1272 |1521 | 171 | 37 |  31 |  26 |-1.900247e+02 |-1.900248e+02 |   0.00%| unknown

SCIP Status        : problem is solved [optimal solution found]
Solving Time (sec) : 2.39
Solving Nodes      : 3
Primal Bound       : -1.90024835941863e+02 (3 solutions)
Dual Bound         : -1.90024835941863e+02
Gap                : 0.00 %

[cons_linear.c:18749] ERROR: constraint is not linear
Traceback (most recent call last):
  File "debug.py", line 4, in <module>
    m.solve(solver_name="scip")
  File "venv/lib/python3.11/site-packages/linopy/model.py", line 1060, in solve
    result = func(
             ^^^^^
  File "venv/lib/python3.11/site-packages/linopy/solvers.py", line 758, in run_scip
    solution = safe_get_solution(status, get_solver_solution)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.11/site-packages/linopy/solvers.py", line 116, in safe_get_solution
    return func()
           ^^^^^^
  File "venv/lib/python3.11/site-packages/linopy/solvers.py", line 751, in get_solver_solution
    dual = set_int_index(dual)
           ^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.11/site-packages/linopy/solvers.py", line 142, in set_int_index
    series.index = series.index.str[1:].astype(int)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 1089, in astype
    new_values = astype_array(values, dtype=dtype, copy=copy)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.11/site-packages/pandas/core/dtypes/astype.py", line 183, in astype_array
    values = _astype_nansafe(values, dtype, copy=copy)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.11/site-packages/pandas/core/dtypes/astype.py", line 134, in _astype_nansafe
    return arr.astype(dtype, copy=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'f1_18'

Versions:

linopy==0.3.8
pandas==2.1.3
PySCIPOpt==5.0.0