- Tue 01 July 2014
- notebook
- Jason K. Moore
- #notebook, #ipopt, #python
uh, trying to use IPopt in Python.
Ipopt installation
I tried to install from the Ubuntu repos, but had trouble linking to it or running the example:
$ sudo aptitude install coinor-libipopt1 coinor-libipopt-dev coinor-libipopt-doc
So then I removed it:
$ sudo aptitude remove coinor-libipopt1 coinor-libipopt-dev coinor-libipopt-doc
The Ipopt documentation gives very nice instructions for installing it from source, which basically goes like this:
$ cd ~/src $ svn co https://projects.coin-or.org/svn/Ipopt/stable/3.11 CoinIpopt $ cd CoinIpopt/ThirdParty/Blas $ ./get.Blas $ cd ../Lapack $ ./get.Lapack $ cd ../ASL $ ./get.ASL $ cd ../Mumps $ ./get.Mumps $ cd ../Metis $ ./get.Metis
This downloads the BLAS and LAPACK reference implementations, but I think the compilation process looks in the system for the system installed implementations and uses them if you have them.
It is a good idea to get the HSL code (but not necessarily required because Mumps can be used) and drop it in the ThirdParty/HSL directory. You have to get the free academic license 2011 code and sign a form to use it. It also takes a day to get the download link by email. (Note that this can be linked as a shared lib after compiling ipopt, so recompiling is required, but it may be easier to just recompile).
I compiled without HSL because I'm waiting for the download link.
First change into the build directory:
$ cd ../../build
And run configure:
$ ./configure
These are some potential options I may want to set in the future:
--prefix /usr/local # for system install --with-blas="-L$HOME/lib -lmyblas" # link to better blas implementations
Now compile, test, and install:
$ make -j5 $ make test $ make install # sudo if system install
This ended up putting everything in ~/src/CoinIpopt/ like ~/src/CoinIpopt/include, ~/src/CoinIpopt/lib, etc. So I did something wrong, as I thought it should have ended up in ~src/CoinIpopt/build/.
cyipopt
I'm hoping to use Ipopt through a Python wrapper. Seems like there are two existing standalone wrappers pyipopt and cyipopt. I like cython and cyipopt was newer, so I gave it a shot.
I first created a conda Python 2.7 environment:
$ conda create -n cyipopt numpy scipy cython matplotlib sphinx $ source activate cyipopt
Then got the source code from bitbucket:
$ cd ~/src $ hg clone https://bitbucket.org/amitibo/cyipopt $ cd cyipopt
I installed on Ubuntu 14.04 so I had to do some pruning in the setup.py file. Basically just remove some odd stuff from main_unix() so it looks like this:
def main_unix(): setup( name=PACKAGE_NAME, version=VERSION, description=DESCRIPTION, author=AUTHOR, author_email=EMAIL, url=URL, packages=[PACKAGE_NAME], cmdclass={'build_ext': build_ext}, ext_modules=[ Extension( PACKAGE_NAME + '.' + 'cyipopt', ['src/cyipopt.pyx'], **pkgconfig('ipopt') ) ], )
Since I didn't install IPopt system wide I needed to export these two environment variables to get things to work:
$ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:~/src/CoinIpopt/lib/pkgconfig $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/src/CoinIpopt/lib
And finally:
$ python setup.py install $ python test/examplehs071.py $ python test/lasso.py
And it worked.
Other Things
Here are a bunch of other notes about things I found today:
- A list of Python optimization tools: https://software.sandia.gov/trac/coopr/wiki/Documentation/RelatedProjects
- Casadi is a symbolic framework for numerica optimization with automatic differentiation, has python bindings and includes Ipopt: https://github.com/casadi/casadi/
- NLOPT: has a bunch of optimizers plus python bindings: http://ab-initio.mit.edu/wiki/index.php/NLopt
- Most all of the large scale NLP optimizers seem to be guarded behind close source licenses.
- pagmo: parallel optimization includes python bindings and has SciPy, SNOPT, and IPOPT connections https://github.com/esa/pagmo
- nlpy: large scale optimization with python https://github.com/dpo/nlpy
- Nice SO question on NLP in Python: http://scicomp.stackexchange.com/questions/83/is-there-a-high-quality-nonlinear-programming-solver-for-python
- The paper that explains SNOPT's algorithm: http://www-leland.stanford.edu/group/SOL/reports/snopt.pdf
- JSModelica seems to have some Pyton interfaces to things.
- PyOpt interfaces lots of code, but mostly commercial code.
- OpenMDAO uses PyOpt.
- My old labmate Gilbert has a Python Optimal Control package https://github.com/gilbertgede/PyOCP and an interior point optimizer https://github.com/gilbertgede/PyIntropt