3

So, i'm currently working with a pyomo model with multiple instances that are being solved in parallel. Issue is, solving them takes pyomo quite a long time (like 2 to 3 secs, even though the solving part by gurobi takes about 0.08s). I've found out that, by exporting a pyomo instance into an .mps file and then giving it to gurobipy i can get like an increase of 30% in overall speed.

The problem comes later, when i want to work with the variables of the solved model, because ive noticed that, when exporting the original instance from pyomo into a .mps file, variable names get lost; they all get named "x" (so, for example, model.Delta, model.Pg, model.Alpha, etc get turned into x1, x2, ... ,x9999 instead of Delta[0], Delta[1], ... Alpha[99,99]).

Is there a way to keep the original variable name when exporting the model?

Pablo Pablo
  • 165
  • 10

2 Answers2

6

Managed to solve it! To anyone who might find this useful, i passed a dictionary with "symbolic_solver_labels" as an io_options argument for the method, like this:

instance.write(filename = str(es_) + ".mps", io_options = {"symbolic_solver_labels":True})

Now my variables are correctly labeled in the .mps file!

Pablo Pablo
  • 165
  • 10
0

I use Pyomo==5.6.9, in this version, "io_options" should use a different way to set.

model.write(filename = "FILEPATH.mps", symbolic_solver_labels=True)

I check the source code of Pyomo(pyomo/repn/plugins/mps.py:ProblemWriter_mps.__call__), it seems to me that the "io_options" passed to this function is **kargs but not a dict.

    def __call__(self,
                 model,
                 output_filename,
                 solver_capability,
                 io_options):

        # Make sure not to modify the user's dictionary,
        # they may be reusing it outside of this call
        io_options = dict(io_options)
        
        ...

        # Use full Pyomo component names in the MPS file rather
        # than shortened symbols (slower, but useful for debugging).
        symbolic_solver_labels = \
            io_options.pop("symbolic_solver_labels", False)
        
        ...
        
        if len(io_options):
            raise ValueError(
                "ProblemWriter_mps passed unrecognized io_options:\n\t" +
                "\n\t".join("%s = %s" % (k,v) for k,v in iteritems(io_options)))
AmonLee
  • 1
  • 1