Package: ipyopt
ipyoptipyoptis a Python 🐍 C++ extension that allows you to useIpoptin Python.Ipopt solves general nonlinear programming problems of the formmin f(x)under the constraintsg_l <= g(x) <= g_u,
x_l <= x <= x_u,wherexisndimensional andg(x)ismdimensional.GoalProvide as much performance as possible. This is also reflected in the
fact that the shippedscipy.optimize.minimizeipoptmethod
deviates in some concerns from the usual methods in scipy.
If you are interested in a morescipylike interface, have a look atcyipopt.InstallationNotethe pypi repository currently only provides 🐧 linux wheels.pipinstall[--user]ipyoptThis will install a precompiled binary version from pypi. Please note,
that the precompiled binary is linked against the unoptimized
reference implementation of blas/lapack. If you want to take advantage
of optimized versions of blas/lapack, compile from source:pipinstall--no-binaryipyoptipyoptIn this case, you also needIpoptandNumpy.
On a debian based system:sudoapt-getinstallpython3-numpycoinor-ipoptIfcoinor-ipoptdoes not link correctly, you might have to compileipoptyourself.
See the sectionBuildbelow or.ci/Dockerfileon
how this can be done.UsageYou can useipyoptlike this:importipyopt# define your call back functionsnlp=ipyopt.Problem(...)nlp.solve(...)For an example, seeexamples/hs071.py.Note that theipyopt.Problem.solve(.)mutates some its arguments, including the initial guess for the variables, and the multipliers.For maximal performance, there is also support forPyCapsules/scipy.LowLevelCallable. By
using this approach, there will be no C++ <-> Python interactions
during Ipopt optimization. Here is an exampletest/c_capsules/(C code) andtest/test_ipyopt.py(Python code using the
PyCapsules provided by the C code).For more details and hints, see thedocs.Buildipyoptdepends on the following packages:A compiler and a linker, e.g. gcc, ldIpoptNumpyPython.h (part of the python source code, you can download it fromPython.org)To build from source, first, get the latest source code using:gitclonehttps://gitlab.com/ipyopt-devs/ipyopt.gitCheck whether a fileipopt.pcwas distributed with your Ipopt installation.
If this is the case andipopt.pcis in the search path ofpkg-config(on unix systems:/usr/lib/pkgconfig,/usr/share/pkgconfig,/usr/local/lib/pkgconfig,/usr/local/share/pkgconfig), nothing has to be modified.In this case runpythonsetup.pybuild
sudopythonsetup.pyinstallIfpkg-configis not available for your system, you will need to
pass appropriate information tosetup.pyby setting the environment
variableCFLAGS. Example:CFLAGS="-I/usr/include/coin/ -l/usr/lib64 -lipopt -lmumps_common -ldmumps -lzmumps -lsmumps -lcmumps -llapack -lblas -lblas -lblas -lm  -ldl' ./setup.py buildsudo python setup.py installIf you have anipopt.pcwhich is not in thepkg-configsearch path,
specify the path via thePKG_CONFIG_PATHenvironment variable (see below).
If you cannot find anipopt.pcin youripoptinstallation, there is an
example pc filepkgconfig/ipopt.pc.
Copy it to a location (best of all directly in a subfolder namedpkgconfigof your Ipopt installation) and edit it to reflect the
library and include paths of the dependencies.Then doPKG_CONFIG_PATH=<dircontainingipopt.pc>pythonsetup.pybuild
sudopythonsetup.pyinstallTestingUnit tests:python-munittestRun examples:Use the following command under theexamplesdirectory.pythonhs071.pyThe fileexamples/hs071.pycontains a toy
optimization problem. If everything is OK,ipyoptwill invokeIpoptto solve it for you. This python file is self-documented and
can be used as a template for writing your own optimization problems.Hessian Estimation: since Hessian estimation is usually tedious,
Ipopt can solve problems without Hessian estimation.ipyoptalso
supports this feature. The fileexamples/hs071.pydemonstrates the idea. If you provide theipyopt.Problemconstructor
with aneval_hcallback function,Ipoptwill delegate the Hessian matrix calculation to your
function (otherwiseIpoptwill approximate Hessian for you).ContributingFork it.Create a branch (git checkout -b new_branch)Commit your changes (git commit -am "your awesome message")Push to the branch (git push origin new_branch)Create a merge requestCreditsModifications on logger made by OpenMDAO at NASA Glenn Research Center, 2010 and 2011Added "eval_intermediate_callback" by OpenMDAO at NASA Glenn Research Center, 2010 and 2011Modifications on the SAFE_FREE macro made by Guillaume Jacquenot, 2012Changed logger from code contributed by alanfalloonOriginally developed by Eric Xu when he was a PhD student atWashington Universityand issued under the BSD
license. Original repository:xuy/pyipopt.