Skip to content

Instantly share code, notes, and snippets.

@GiulioRomualdi
Last active March 22, 2024 10:35
Show Gist options
  • Save GiulioRomualdi/22fddb949e7b09bb53ca2ff72cbf8cb6 to your computer and use it in GitHub Desktop.
Save GiulioRomualdi/22fddb949e7b09bb53ca2ff72cbf8cb6 to your computer and use it in GitHub Desktop.

How to install CasADi + IPOPT + HSL

The tutorial has been moved in: https://github.com/ami-iit/ami-commons/blob/master/doc/casadi-ipopt-hsl.md

Click me if you are interested in the original tutorial

This guide should help you to install CasADi with IPOPT and HSL support.

  1. Install some dependencies sudo apt-get install build-essential gfortran liblapack-dev libmetis-dev libopenblas-dev
  2. mkdir -p ~/robot-code/CoinIpopt && cd ~/robot-code/CoinIpopt
  3. Get coinbrew
    1. wget https://raw.githubusercontent.com/coin-or/coinbrew/master/coinbrew
    2. chmod u+x coinbrew
  4. Run ./coinbrew Ipopt and follow the instruction to fetch IPOPT and all the dependencies (Today the latest version of IPOPT is 3.13.4)
  5. mkdir install
  6. Build ipot ./coinbrew build Ipopt --prefix=install --test --no-prompt --verbosity=3 (have a ☕)
  7. Obtain an archive with HSL source code from http://www.hsl.rl.ac.uk/ipopt/. (I'm currently using coinhsl-2019.05.21)
  8. Unzip the folder coinhsl-2019.05.21.zip into ~/robot-code/CoinIpopt/ThirdParty/HSL/ and rename it coinhsl.
  9. cd ~/robot-code/CoinIpopt
  10. Build ipopt ./coinbrew build Ipopt --prefix=install --test --no-prompt --verbosity=3 (have a ☕)
  11. Run ./coinbrew install Ipopt --no-prompt
  12. cd ~/robot-code/CoinIpopt/install/lib
  13. ln -s libcoinhsl.so libhsl.so
  14. Add to the .bashrc the following lines
    export IPOPT_DIR=~/robot-code/CoinIpopt/install
    export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:${IPOPT_DIR}/lib/pkgconfig
    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${IPOPT_DIR}/lib
    
    # ipopt this is required for casadi
    export PATH=${PATH}:${IPOPT_DIR}/lib
    
    # this may speed up ipopt 
    export OMP_NUM_THREADS=1
  15. Clone CasADi cd ~/robot-code && git clone https://github.com/casadi/casadi.git
  16. mkdir -p casadi/build && cd casadi/build
  17. Run cmake -DWITH_IPOPT:BOOL=ON -DWITH_HSL:BOOL=ON -DINCLUDE_PREFIX:PATH=include -DCMAKE_PREFIX:PATH=lib/cmake/casadi -DLIB_PREFIX:PATH=lib -DBIN_PREFIX:PATH=bin ..
  18. make and make install
  19. Enjoy CasADi with IPOPT and HSL solvers 🚀

@lrapetti
Copy link

lrapetti commented Oct 27, 2022

Thanks @GiulioRomualdi, I confirm that the procedure works also on MacOS.

The required changes, with respect to the list above, are the following:

  • at 0.
    The dependencies can be installed using homebrew.
    The following two are required:
    brew install pkg-config
    brew install metis
    (more info can be found in the official Ipopt documentation)

  • at 12.
    ln -s libcoinhsl.so libhsl.so -> ln -s libcoinhsl.dylib libhsl.dylib

  • at 13.
    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${IPOPT_DIR}/lib
    -> export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:${IPOPT_DIR}/lib

@traversaro
Copy link

@GiulioRomualdi can you add a redirect/link to https://github.com/ami-iit/ami-commons/blob/master/doc/casadi-ipopt-hsl.md so that people can propose changes with PRs ? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment