Skip to content

Invalid literal for int: error while solving MPS files with longer column names #396

@siddharth-krishna

Description

@siddharth-krishna

I'm facing an error when running linopy on MPS files where column names have more than one letter in them (e.g. col01 as opposed to x01). Here is an example MPS file:

NAME        sample_mip
ROWS
 N  obj     
 G  c1      
 L  c2      
 E  c3      
COLUMNS
    col1        obj       5
    col1        c1        2
    col1        c2        4
    col1        c3        1
    MARK0000  'MARKER'                 'INTORG'
    col2        obj       3
    col2        c1        3
    col2        c2        2
    col2        c3        1
    col3        obj       7
    col3        c1        4
    col3        c2        3
    col3        c3        1
    MARK0001  'MARKER'                 'INTEND'
RHS
    RHS_V     c1        12
    RHS_V     c2        15
    RHS_V     c3        6
BOUNDS
 UP BOUND     col1        4
 UI BOUND     col2        3
 UI BOUND     col3        5
ENDATA

I run this using the python script

import sys
from pathlib import Path
from linopy import solvers

s = solvers.Highs()
result = s.solve_problem(problem_fn=Path(sys.argv[1]), solution_fn=Path("/tmp/sid-linopy-out.sol"))
print(result)
print(result.solution.objective)

Which results in the following error (a similar error appears when using GLPK/Gurobi solvers):

Traceback (most recent call last):
  File ".../linopy-test.py", line 6, in <module>                                           
    result = s.solve_problem(problem_fn=Path(sys.argv[1]), solution_fn=Path("/tmp/sid-linopy-out.sol"))                       
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                       
  File ".../lib/python3.12/site-packages/linopy/solvers.py", line 299, in solve_problem
    return self.solve_problem_from_file(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                      
  File ".../lib/python3.12/site-packages/linopy/solvers.py", line 775, in solve_problem_from_file
    return self._solve(                                                                                                       
           ^^^^^^^^^^^^
  File ".../lib/python3.12/site-packages/linopy/solvers.py", line 867, in _solve    
    solution = self.safe_get_solution(status=status, func=get_solver_solution)                                                
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                
  File ".../lib/python3.12/site-packages/linopy/solvers.py", line 224, in safe_get_solution
    return func()                                                                                                             
           ^^^^^^
  File ".../lib/python3.12/site-packages/linopy/solvers.py", line 860, in get_solver_solution
    ).pipe(set_int_index)
      ^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.12/site-packages/pandas/core/generic.py", line 6231, in pipe
    return common.pipe(self, func, *args, **kwargs)                                                                           
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.12/site-packages/pandas/core/common.py", line 502, in pipe  
    return func(obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.12/site-packages/linopy/solvers.py", line 138, in set_int_index
    series.index = series.index.str[1:].astype(int)                                                                           
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                           
  File ".../lib/python3.12/site-packages/pandas/core/indexes/base.py", line 1097, in astype
    new_values = astype_array(values, dtype=dtype, copy=copy)                                                                 
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.12/site-packages/pandas/core/dtypes/astype.py", line 182, in astype_array
    values = _astype_nansafe(values, dtype, copy=copy)                                                                        
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                        
  File ".../lib/python3.12/site-packages/pandas/core/dtypes/astype.py", line 133, in _astype_nansafe
    return arr.astype(dtype, copy=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                       
ValueError: invalid literal for int() with base 10: 'ol1'  

I first noticed this error when running on the following JuMP-HiGHS benchmark: Sienna_modified_RTS_GMLC_DA_sys_NetDC_Horizon12_Day332

Could it be that linopy is expecting all column names to look like \w\d+? @FabianHofmann 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions