5
$\begingroup$

I need to use Pyomo with Ipopt solver on Google-Colab.

In order to install it I did as follows: enter image description here

Now I need to use it , I get the following error ? ApplicationError: No executable found for solver 'ipopt'

enter image description here

How can I resolve it ?

$\endgroup$

3 Answers 3

7
$\begingroup$

The following package installation should be done before staring the Pyomo model

!pip install pyomo 
from pyomo.environ import *
import matplotlib.pyplot as plt
!wget -N -q "https://matematica.unipv.it/gualandi/solvers/ipopt-linux64.zip"
!unzip -o -q ipopt-linux64

Then you can run your NLP model

model = AbstractModel()
model.x = Var(bounds=(0,1.2), within=Reals)
model.obj1 = Objective(expr=model.x**2, sense=maximize)
#opt = SolverFactory('ipopt')
opt=SolverFactory('ipopt', executable='/content/ipopt')
instance = model.create_instance()
results = opt.solve(instance) # solves and updates instance
print('OF= ',value(instance.obj1))
$\endgroup$
1
  • $\begingroup$ thanks is it possible to show how to use the same approach for MINLP ? how can I give the address of solver ? for example, instaed of using your ipopt address which one of these can be used ? coin-or.org/download/binary/Ipopt $\endgroup$ Commented Feb 25, 2023 at 1:12
5
$\begingroup$

If your notebook could be executed both on Colab or on a different environment (such as a local Jupyter notebook), you could add a couple of checks, before downloading and reinstalling pyomo and ipopt every time, as follows:

import shutil
import sys
import os.path

if not shutil.which("pyomo"):
    !pip install -q pyomo
    assert(shutil.which("pyomo"))

if not (shutil.which("ipopt") or os.path.isfile("ipopt")):
    if "google.colab" in sys.modules:
        !wget -N -q "https://matematica.unipv.it/gualandi/solvers/ipopt-linux64.zip"
        !unzip -o -q ipopt-linux64
    else:
        try:
            !conda install -c conda-forge ipopt 
        except:
            pass

NOTE: I have modified the link to ipopt-linux64.zip on Feb. 22nd, 2023. Older binaries of IpOpt are available at COIN-OR

Thanks to Stefano Coniglio and Pietro Belotti for the support on this.

NOTE 2: Since it was asked in a comment, you can install GLPK as follows:

if not (shutil.which("glpk") or os.path.isfile("glpk")):
    if "google.colab" in sys.modules:
        !apt-get install -y -qq glpk-utils
    else:
        try:
            !conda install -c conda-forge glpk 
        except:
            pass

For other solvers, the process is quite similar (e.g., for CBC).

$\endgroup$
5
  • 1
    $\begingroup$ Hi Stefano, ampl.com/dl/open/ipopt/ipopt-linux64.zip no longer exists $\endgroup$ Commented Feb 21, 2023 at 22:21
  • $\begingroup$ This is a pity. We should look for an alternative website with that code. Thanks for letting us know about it. $\endgroup$ Commented Feb 22, 2023 at 7:59
  • 1
    $\begingroup$ @Optimizationteam I stored the ipopt file somewhere else (and I hope nobody complaints about it). $\endgroup$ Commented Feb 22, 2023 at 12:36
  • $\begingroup$ I understand, my question is when I give the address of ipopt or other coin-or solvers it does not work how can I use your approach for otehr solvers ? coin-or.org/download/source $\endgroup$ Commented Feb 26, 2023 at 11:59
  • $\begingroup$ I tried all the methods in this answer, but mostly I'm getting the error : [ipopt-linux64.zip] End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive. unzip: cannot find zipfile directory in one of ipopt-linux64 or ipopt-linux64.zip, and cannot find ipopt-linux64.ZIP, period. $\endgroup$ Commented Jun 21, 2023 at 5:27
0
$\begingroup$

I found a link that works for installing the solver on windows, i dont know if that will help, but here it is :

https://www.youtube.com/watch?v=EB_qVoM74Fg

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.