Skip to content

We write tokens (hence LP files) Gurobi cannot read if variable names are long enough #3493

Open
@emma58

Description

@emma58

Summary

I'm not actually sure that this really is a bug because the use case is ridiculous, but at least for the sake of documentation, Gurobi has a 255 character limit on tokens. With symbolic_solver_labels set to True we will happily violate this limit.

(Please don't ask me how I know. :P)

Steps to reproduce the issue

In the following script, the first solve is fine because we make sane names. The second solve gives a Gurobi error, recorded below.

from pyomo.environ import *

m = ConcreteModel()
m.s = Set(initialize=["apologies",
                      "This_is_a_name_with_more_than_255_characters_which_I_agree_is_a_totally_ridiculous_thing_to_do_so_why_did_I_do_it_you_might_ask_but_naturally_I_would_dodge_the_question_so_you_will_have_to_imagine_the_reason_which_honestly_should_be_way_more_fun_than_knowing_the_unfortunate_reality"])
m.x = Var(m.s, bounds=(0, 10))

m.obj = Objective(expr=sum(m.x[i] for i in m.s), sense=maximize)

SolverFactory('gurobi').solve(m, tee=True)

# uh oh
SolverFactory('gurobi').solve(m, symbolic_solver_labels=True, tee=True)

Yields the output:

Read LP format model from file /tmp/tmpagj3adcl.pyomo.lp
Reading time = 0.00 seconds
x1: 1 rows, 3 columns, 1 nonzeros
Gurobi Optimizer version 12.0.0 build v12.0.0rc1 (linux64 - "CentOS Linux 7 (Core)")

CPU model: 13th Gen Intel(R) Core(TM) i7-1365U, instruction set [SSE2|AVX|AVX2]
Thread count: 4 physical cores, 4 logical processors, using up to 4 threads

Optimize a model with 1 rows, 3 columns and 1 nonzeros
Model fingerprint: 0x08b875f2
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [1e+00, 1e+00]
  Bounds range     [1e+00, 1e+01]
  RHS range        [1e+00, 1e+00]
Presolve removed 1 rows and 3 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    2.0000000e+01   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  2.000000000e+01
Error reading LP format file /tmp/tmp7mef0crh.pyomo.lp at line 5
Token contains more than 255 characters
Neighboring tokens: " max obj: +1 x(apologies) +1 x(This_is_a_name_with_more_than_255_characters_which_I_agree_is_a_totally_ridiculous_thing_to_do_so_why_did_I_do_it_you_might_ask_but_naturally_I_would_dodge_the_question_so_you_will_have_to_imagine_the_reason_which_honestly_should_be_way_more_fun_than_kno "

Traceback (most recent call last):
  File "/home/esjohn/src/capsiid/capsiid-interdiction/nihba/ha.py", line 13, in <module>
    SolverFactory('gurobi').solve(m, symbolic_solver_labels=True, tee=True)
  File "/home/esjohn/src/pyomo/pyomo/opt/base/solvers.py", line 610, in solve
    _status = self._apply_solver()
              ^^^^^^^^^^^^^^^^^^^^
  File "/home/esjohn/src/pyomo/pyomo/solvers/plugins/solvers/GUROBI.py", line 689, in _apply_solver
    self._soln = GUROBI_RUN.gurobi_run(
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/esjohn/src/pyomo/pyomo/solvers/plugins/solvers/GUROBI_RUN.py", line 66, in gurobi_run
    model = read(model_file)
            ^^^^^^^^^^^^^^^^
  File "src/gurobipy/gurobi.pxi", line 336, in gurobipy._core.read
  File "src/gurobipy/gurobi.pxi", line 121, in gurobipy._core.gurobi.read
gurobipy._exception.GurobiError: Unable to read file

Information on your system

Pyomo version: main
Python version: 3.11
Operating system: linux
How Pyomo was installed (PyPI, conda, source): source
Solver (if applicable): Gurobi

Additional information

For the LP interface the error message is clear and it's easy enough to fix on the user side that this probably doesn't matter. But I thought I might note it because it is a bit more opaque in a direct interface (though the Gurobi error in that case too at least cites the problem, though it does not give the name that is causing it.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions