Is there a way to use IPOPT and BONMIN with Pyomo under Windows without setting a PATH environment variable?

2,390 views
Skip to first unread message

Thomas W

unread,
Jul 8, 2016, 9:07:48 AM7/8/16
to Pyomo Forum
Is there a way to use IPOPT and BONMIN with Pyomo under Windows without setting a PATH environment variable?
I'm building a piece of software using Pyomo, and it would be easier to distribute without setting the PATH environment variable.

Thanks,
Thomas

Gabe Hackebeil

unread,
Jul 8, 2016, 11:43:04 AM7/8/16
to pyomo...@googlegroups.com
The SolverFactory function accepts the keyword "executable", which you can set to an absolute or relative path to a solver executable. E.g.,

opt = SolverFactory("ipopt", executable="../ipopt")

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.

Thomas W

unread,
Jul 22, 2016, 5:37:27 AM7/22/16
to Pyomo Forum
Hi Gabe,

Here's what I'm using as an absolute path (under Windows), but it doesn't seem to work:

MINLP_SOLVER_PATH = 'D:/Dropbox/SuMO_Package/SuMO/RBFOpt/src/Solvers/bonmin'

Pasting the same path into the command line works fine. 
I've tried different combinations of slashes, but to no avail.
Any idea what could be going on?

Thanks,
Thomas

Gabe Hackebeil

unread,
Jul 22, 2016, 4:53:28 PM7/22/16
to pyomo...@googlegroups.com
Are you on the latest release of Pyomo (pip install -U pyomo)? I don't believe this functionality exists prior to that.

Gabe 
--

Thomas W

unread,
Jul 22, 2016, 8:51:15 PM7/22/16
to pyomo...@googlegroups.com
I'm using 4.3.11388, which should be the newest one, right?

Gabriel Hackebeil

unread,
Jul 22, 2016, 8:55:23 PM7/22/16
to pyomo...@googlegroups.com
Correct.

Can you show me exactly how you are calling SolverFactory?

Gabe

On Jul 22, 2016, at 8:51 PM, Thomas W <thomas....@gmail.com> wrote:

I'm using 4.3.11388, which should be the newest one, right?


Thomas W

unread,
Jul 22, 2016, 9:03:12 PM7/22/16
to pyomo...@googlegroups.com
Hi Gabe,

It looks like this:

MINLP_SOLVER_NAME = 'bonmin'
MINLP_SOLVER_PATH = 'C:/Solvers/bonmin'
opt = pyomo.opt.SolverFactory(config.MINLP_SOLVER_NAME, executable = config.MINLP_SOLVER_PATH, solver_io = 'nl')

Thanks,
Thomas

Gabriel Hackebeil

unread,
Jul 22, 2016, 9:38:11 PM7/22/16
to pyomo...@googlegroups.com
I’ve come across cases where the \ characters in path strings on Windows do not get interpreted correctly. E.g., I am reproducing the behavior right now on Windows 10 using Python 3.5.1 (via Anaconda) where the following happens to a path string:

exe = "C:\gurobi651\win64\bin\gurobi_cl.exe"
print(exe) # outputs: C:\gurobi651\win6in\gurobi_cl.exe

The safest thing to do on any system is to build a path using the os.join function, which fixes the problem for me.

import os
exe = os.path.join("C:\\", "gurobi651", "win64", "bin", "gurobi_cl")
print(exe)
with SolverFactory("gurobi", executable=exe) as opt:
    print(opt.executable())

Gabe

P.S. Anyone coming across this thread should not assume Pyomo’s Gurobi solver plugin uses the gurobi_cl executable. It does not. I just used this file as an example because it existed on my system and was executable.

Gabe

On Jul 22, 2016, at 9:03 PM, Thomas W <thomas....@gmail.com> wrote:

Hi Gabe,

It looks like this:

MINLP_SOLVER_PATH = 'C:/Solvers/bonmin'
opt = pyomo.opt.SolverFactory(config.MINLP_SOLVER_NAME, executable = config.MINLP_SOLVER_PATH, solver_io = 'nl')

Thanks,
Thomas

Thomas W

unread,
Jul 22, 2016, 10:00:42 PM7/22/16
to pyomo...@googlegroups.com
Here's what I'm using now for testing (on Windows 10 with Python 2.7)

import os
import pyomo.opt

MINLP_SOLVER_NAME = 'bonmin'
MINLP_SOLVER_PATH = os.path.join("C:\\", "Solvers", "bonmin.exe")

print(MINLP_SOLVER_PATH)
print(os.path.exists(MINLP_SOLVER_PATH))

with pyomo.opt.SolverFactory(MINLP_SOLVER_NAME, executable = MINLP_SOLVER_PATH) as opt:
    print(opt.executable())

This code results in the following error:

C:\Solvers\bonmin.exe
True
Traceback (most recent call last):
  File "D:\\test.py", line 10, in <module>
    print(opt.executable())
  File "D:\Python27\lib\site-packages\pyomo\opt\base\solvers.py", line 139, in __getattr__
    self._solver_error(attr)
  File "D:\Python27\lib\site-packages\pyomo\opt\base\solvers.py", line 153, in _solver_error
    + "\n\toptions: %s" % ( self.options, ) )
RuntimeError: Attempting to use an unavailable solver.

The SolverFactory was unable to create the solver "bonmin"
and returned an UnknownSolver object.  This error is raised at the point
where the UnknownSolver object was used as if it were valid (by calling
method "executable").

The original solver was created with the following parameters:
        executable: C:\Solvers\bonmin.exe
        type: bonmin
        _args: ()
        options: {}


Gabe Hackebeil

unread,
Jul 22, 2016, 10:04:41 PM7/22/16
to pyomo...@googlegroups.com
What is the result of:

print(os.path.exists(MINLP_SOLVER_PATH))

Gabe

On Jul 22, 2016, at 10:00 PM, Thomas W <thomas....@gmail.com> wrote:

Here's what I'm using now for testing (on Windows 10 with Python 2.7)

import os
import pyomo.opt

MINLP_SOLVER_NAME = 'bonmin'
MINLP_SOLVER_PATH = os.path.join("C:\\", "Solvers", "bonmin.exe")

print(MINLP_SOLVER_PATH)

with pyomo.opt.SolverFactory(MINLP_SOLVER_NAME, executable = MINLP_SOLVER_PATH) as opt:
    print(opt.executable())

This code results in the following error:

C:\Solvers\bonmin.exe
Traceback (most recent call last):
  File "D:\\test.py", line 10, in <module>
    print(opt.executable())
  File "D:\Python27\lib\site-packages\pyomo\opt\base\solvers.py", line 139, in __getattr__
    self._solver_error(attr)
  File "D:\Python27\lib\site-packages\pyomo\opt\base\solvers.py", line 153, in _solver_error
    + "\n\toptions: %s" % ( self.options, ) )
RuntimeError: Attempting to use an unavailable solver.

The SolverFactory was unable to create the solver "bonmin"
and returned an UnknownSolver object.  This error is raised at the point
where the UnknownSolver object was used as if it were valid (by calling
method "executable").

The original solver was created with the following parameters:
        executable: C:\Solvers\bonmin.exe
        type: bonmin
        _args: ()
        options: {}

Thomas W

unread,
Jul 22, 2016, 10:09:37 PM7/22/16
to Pyomo Forum
It results in True

Also, copy pasting the path into the command line successfully brings up bonmin:

C:\Users\Thomas>C:\Solvers\bonmin.exe
Bonmin 1.7.4 using Cbc 2.8.12 and Ipopt 3.11.9
No stub!
usage: bonmin [options] stub [-AMPL] [<assignment> ...]

Options:
        --  {end of options}
        -=  {show name= possibilities}
        -?  {show usage}
        -bf {read boundsfile f}
        -e  {suppress echoing of assignments}
        -of {write .sol file to file f}
        -s  {write .sol file (without -AMPL)}
        -v  {just show version}

Gabriel Hackebeil

unread,
Jul 22, 2016, 10:19:53 PM7/22/16
to pyomo...@googlegroups.com
Actually, I can reproduce the issue if I change the solver name (not the executable name) to something that is not a registered Pyomo plugin (e.g., “bonmin"). So this really is a bug. Thanks helping me chase this down.

I will work on fixing this. In the meantime, I think you can work around it by changing the solver name to “asl”, which is the general interface we use for AMPL solvers. Let me know if that doesn’t work.

Gabe

Thomas W

unread,
Jul 22, 2016, 10:29:06 PM7/22/16
to Pyomo Forum
Hi Gabe,

Thank you for looking into this!

Using "asl" results in the same error though.
Any other ideas? Else I will use a PATH variable until you get around to fixing it.

Cheers,
Thomas

Gabriel Hackebeil

unread,
Jul 22, 2016, 10:54:40 PM7/22/16
to pyomo...@googlegroups.com
I pushed what seems to be a fix to Pyomo trunk. If you want to test it, you must first uninstall Pyomo and PyUtilib (pip uninstall Pyomo Pyutilib), and then reinstall by either cloning each of those packages from GitHub and installing manually, or by following this blog post that explains how to do it with pip.

Let me know if that doesn’t fix the problem for you.

Gabe

Thomas W

unread,
Jul 22, 2016, 11:19:10 PM7/22/16
to Pyomo Forum
That was quick! I'm getting a new error, though:

Solver name: bonmin
Solver path: C:\Solvers\bonmin.exe
Path exists: True

Traceback (most recent call last):
  File "D:\\test.py", line 11, in <module>
    with pyomo.opt.SolverFactory(MINLP_SOLVER_NAME, executable = MINLP_SOLVER_PATH) as opt:
  File "C:\Python27\lib\site-packages\pyomo\opt\base\solvers.py", line 190, in __solver_call__
    "IO mode=%s" % (_implicit_solvers[mode], mode) )
RuntimeError: The asl solver plugin was not registered as a valid solver plugin - cannot construct solver plugin with IO mode=nl

Gabriel Hackebeil

unread,
Jul 22, 2016, 11:24:48 PM7/22/16
to pyomo...@googlegroups.com
Okay, that’s indicative of a more serious problem. The asl plugin should always be available. This is probably why the workaround I gave you earlier did not work.

Were there any errors during installation? How did you install?

Gabe

Thomas W

unread,
Jul 22, 2016, 11:35:13 PM7/22/16
to Pyomo Forum
I used pip and git, as in the blog post you linked.
The previous installation was just from pip.
There were no errors as far as I can tell, and "pip show pyomo" shows pyomo as 4.4.

However, I just restarted my computer, and now it is back to the previous error:

Gabriel Hackebeil

unread,
Jul 22, 2016, 11:43:49 PM7/22/16
to pyomo...@googlegroups.com
Hmm. Well, I think I am at a loss. My only guess is that you have an older installation of Pyomo sitting around somewhere, or that you have multiple Python installations and pip is not pointing to the one that you think.

I would recommend downloading the pyomo_uninstall.py script (https://software.sandia.gov/trac/pyomo/downloader) and executing that to make sure any older stuff and turfed, and then reinstall.

Gabe

Gabriel Hackebeil

unread,
Jul 23, 2016, 12:20:38 AM7/23/16
to pyomo...@googlegroups.com
Thomas,

I just realized there is a simple fix on your end. You need to execute the line “import pyomo.environ” before you try to use the SolverFactory function. This registers all of the Pyomo solver plugins. I’m not sure why they are not registered automatically, but that’s the way it is for now.

Sorry for the confusion.

Gabe

Thomas W

unread,
Jul 23, 2016, 12:27:49 AM7/23/16
to pyomo...@googlegroups.com
Thanks Gabe, that seems to do the trick!

(I actually had this line in my original code, so it looks like one needs "import pyomo.environ" plus the Pyomo 4.4 beta that you fixed.)

Thanks again!
Reply all
Reply to author
Forward
0 new messages