Skip to content

Instantly share code, notes, and snippets.

@silgon
Last active October 14, 2024 16:59
Show Gist options
  • Save silgon/0892f410b025f2a82f2b to your computer and use it in GitHub Desktop.
Save silgon/0892f410b025f2a82f2b to your computer and use it in GitHub Desktop.

Installation of IPOPT on LINUX

NOTE: this page is for a from-source install (useful if you want to contribute to CasADi). If you just want to evaluate CasADi quickly, use a binary install.

  • To get started quickly, start off by grabbing as many dependencies as possible from repositories.
  • Ubuntu: sudo apt-get install gcc g++ gfortran git cmake liblapack-dev pkg-config --install-recommends
  • Fedora: sudo yum install gcc gcc-c++ gcc-gfortran git cmake lapack-devel
  • To compile the Python interface, you also need SWIG and a decent Python installation:
  • Ubuntu: sudo apt-get install swig ipython python-dev python-numpy python-scipy python-matplotlib --install-recommends
  • Fedora: sudo yum install swig ipython python-devel numpy scipy python-matplotlib
  • If you want an easy-to-use Python IDE with a Matlab-like usage, we recommend you to install Spyder:
  • Ubuntu: sudo apt-get install spyder
  • Fedora: sudo yum install spyder
  • Install Third-party software that you wish to use from CasADi. Note the following:
  • The QP-solver qpOASES, the sparse direct linear solver CSparse and the integrator suite Sundials are included in CasADi and do not need to be installed separately.
  • See section on IPOPT below for installing IPOPT, including its sIPOPT extension
  • See section on WORHP below for instructions on installing WORHP.
  • Download and install CasADi from GitHub, see below.

Installing IPOPT (recommended if you plan to solve optimal control problems)

IPOPT can either be obtained from a package manager, downloaded as a binary or compiled from sources. Note that if you use the prebuilt CasADi binaries for Windows or Linux, IPOPT is included and does not need to be installed separately. You will find more information about all of these topics on the IPOPT website.

Option 1: Getting IPOPT from a package manager

On Ubuntu (or Debian) Linux and Mac OS X you can obtain IPOPT from a package manager:

  • OS X (Homebrew): brew install ipopt --with-openblas
  • Ubuntu (apt-get): sudo apt-get install coinor-libipopt-dev

Option 2: Compiling IPOPT from sources

On Linux and Mac OS X, IPOPT can be compiled from sources. You will find instructions on how to do this on their website. Our experience is that installing IPOPT is relatively easy if you follow the installation instructions on website carefully, but very hard if you try to improvise. Here is a condensed version of the installation instructions:

  • Download the latest version from SVN:
  • svn co https://projects.coin-or.org/svn/Ipopt/stable/3.11 CoinIpopt
  • Get third-party dependencies via the provided script:
  • cd CoinIpopt/ThirdParty
  • cd Blas && ./get.Blas && cd ..
  • cd Lapack && ./get.Lapack && cd ..
  • cd Metis && ./get.Metis && cd .. (Graph Coloring tool used by e.g. Mumps)
  • cd Mumps && ./get.Mumps && cd .. (Sparse direct linear solver with permissive license)
  • cd ..; mkdir build; cd build
  • Compile and install IPOPT. Compiling -fPIC often helps:
  • ../configure --prefix=/usr/local ADD_FFLAGS=-fPIC ADD_CFLAGS=-fPIC ADD_CXXFLAGS=-fPIC
  • make; sudo make install
  • If you wish to compile IPOPT with support for parametric sensitivities (sIPOPT), follow the instructions below.
  • Test if pkg-config is able to find your Ipopt installation:
  • pkg-config --libs ipopt

If this last test does not return your installed Ipopt libraries, you must set the variable PKG_CONFIG_PATH, e.g. by adding export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:<your_ipopt_pkgconfig_path> to your .bashrc or .profile file. <your_ipopt_pkgconfig_path> is the path where ipopt.pc of your Ipopt installation lives (typically <ipopt_install_dir>/lib/pkgconfig).

Option 3: Download a binary with IPOPT

On the download section of the IPOPT website you will find IPOPT compiled for a number of platforms.

Adding additional linear solvers (recommended)

To really benefit from from IPOPT, you should also try to get additional linear solvers, which can be done post-installation, regardless of how IPOPT was installed. We strongly recommend you to get at least the HSL solver MA27 (which is free). You will find instructions on that here. When filling out the forms for obtaining HSL, please mention that you plan to use the routines with Ipopt/CasADi. Unfortunately, we cannot guarantee the stability of using the newer linear solvers (MA57, MA77, MA86 and MA97 that are only free for academics) since HSL has not granted us any maintenance license.

Compiling IPOPT with support for parametric sensitivities (sIPOPT)

To compile support for parametric sensitivities in Ipopt you need to compile sIPOPT:

cd <ipopt_build_dir>/Ipopt/contrib/sIPOPT
make
sudo make install

The compilation of sIPOPT is known to fail if the AMPL interface was not compiled. So make sure to include the AMPL Solver Library (ASL) when compiling IPOPT.

If the sIPOPT header files are not automatically installed, you can copy them manually to your IPOPT installation:

cp <ipopt_source_dir>/Ipopt/contrib/sIPOPT/src/*.hpp <ipopt_installation_dir>/include/coin/
cp <ipopt_source_dir>/Ipopt/src/Algorithm/*.hpp <ipopt_installation_dir>/include/coin/

The reduced Hessian calculator in sIPOPT only prints out the calculated reduced Hessian to screen. If you want to be able to retrieve it, you need to download and apply the following patch to sIPOPT:

cd <ipopt_source_dir>
patch -p0 < path-to-get_reduced_hessian.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment