Export to MPS format from a python script (not command line)

1,309 views
Skip to first unread message

XG

unread,
Aug 22, 2017, 10:34:02 AM8/22/17
to Pyomo Forum
How can I export a pyomo model to MPS format from within a python script, e.g.,

optModel = ConcreteModel()
# Define the model
...

# Write optModel to MPS in a user-specified directory and file name
???

Thanks!

Gabe Hackebeil

unread,
Aug 22, 2017, 10:36:25 AM8/22/17
to pyomo...@googlegroups.com
optModel.write("something.mps")

Gabe
--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

XG

unread,
Aug 22, 2017, 12:12:49 PM8/22/17
to Pyomo Forum

I get the following error:

  File "/projectnb/bioinfor/xg/lib/python2.7/site-packages/coopr/pyomo/base/PyomoModel.py", line 900, in write
    (filename, symbol_map) = problem_writer(self, filename, solver_capability, io_options)
  File "/projectnb/bioinfor/xg/lib/python2.7/site-packages/coopr/pyomo/plugins/io/cpxlp.py", line 105, in __call__
    output_fixed_variable_bounds)
  File "/projectnb/bioinfor/xg/lib/python2.7/site-packages/coopr/pyomo/plugins/io/cpxlp.py", line 411, in _print_model_LP
    raise ValueError("Unable to find an active Suffix with name 'canonical_repn' on block: %s" % (model.cname(True)))
ValueError: Unable to find an active Suffix with name 'canonical_repn' on block: unknown

Gabe Hackebeil

unread,
Aug 22, 2017, 12:17:59 PM8/22/17
to pyomo...@googlegroups.com
Are you doing this on a PySP model? If not, what version of Pyomo are you using?

Gabe

XG

unread,
Aug 22, 2017, 3:47:40 PM8/22/17
to Pyomo Forum
No. It's not a PySP model. The version of pyomo I am using is 3.6.4. I initially managed to get that MPS file using optModel.write() after adding "from coopr.environ import *" to the beginning of my script, but then it couldn't load the solution after solving the model. I removed "from coopr.environ import *" and the problem with loading the solution was resolved however, I am not able to get the optModel.write() to work again even after adding "from coopr.environ import *" back (I get the same error message I was getting initially).

Gabe Hackebeil

unread,
Aug 22, 2017, 4:05:00 PM8/22/17
to pyomo...@googlegroups.com
You are working with a very outdated version of Pyomo. We've even renamed the global package imports since then. Although we are on Pyomo 5.2, the following blog post should cover most of the changes you will need to make to existing code in order to update:


The MPS writer did not exist in the version you are using, which is also why the error occurs inside the LP writer.

Also be sure to use the pyomo_uninstall script mentioned in that blog post before installing the most recent version using pip.

Gabe

XG

unread,
Aug 24, 2017, 2:50:13 PM8/24/17
to Pyomo Forum
Upgrading to pyomo 5.2 fixed the issue. Thanks!
PS.:  Is there a way of getting notified about pyomo's major updates?
Reply all
Reply to author
Forward
0 new messages