Skip to main content

Python interface to Ipopt

Project description

pipeline status python version latest version Checked with mypy Ruff DOI

ipyopt is a Python 🐍 C++ extension that allows you to use Ipopt in Python.

InstallUsageDocs

ipyopt

Ipopt solves general nonlinear programming problems of the form

min f(x)

under the constraints

g_l <= g(x) <= g_u,
x_l <= x <= x_u,

where x is n dimensional and g(x) is m dimensional.

Goal

Provide as much performance as possible. This is also reflected in the fact that the shipped scipy.optimize.minimize ipopt method deviates in some concerns from the usual methods in scipy. If you are interested in a more scipy like interface, have a look at cyipopt.

Installation

Note the pypi repository currently only provides 🐧 linux wheels.

pip install [--user] ipyopt

This 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:

pip install --no-binary ipyopt ipyopt

In this case, you also need Ipopt and Numpy. On a debian based system:

sudo apt-get install python3-numpy coinor-ipopt

If coinor-ipopt does not link correctly, you might have to compile ipopt yourself. See the section Build below or .ci/Dockerfile on how this can be done.

Usage

You can use ipyopt like this:

import ipyopt
# define your call back functions
nlp = ipyopt.Problem(...)
nlp.solve(...)

For an example, see examples/hs071.py.

Note that the ipyopt.Problem.solve(.) mutates some its arguments, including the initial guess for the variables, and the multipliers.

For maximal performance, there is also support for PyCapsules / scipy.LowLevelCallable. By using this approach, there will be no C++ <-> Python interactions during Ipopt optimization. Here is an example test/c_capsules/ (C code) and test/test_ipyopt.py (Python code using the PyCapsules provided by the C code).

For more details and hints, see the docs.

Build

ipyopt depends on the following packages:

  1. A compiler and a linker, e.g. gcc, ld
  2. Ipopt
  3. Numpy
  4. Python.h (part of the python source code, you can download it from Python.org)

To build from source, first, get the latest source code using:

git clone https://gitlab.com/ipyopt-devs/ipyopt.git

Check whether a file ipopt.pc was distributed with your Ipopt installation. If this is the case and ipopt.pc is in the search path of pkg-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 run

python setup.py build
sudo python setup.py install

If pkg-config is not available for your system, you will need to pass appropriate information to setup.py by setting the environment variable CFLAGS. Example:

CFLAGS="-I/usr/include/coin/ -l/usr/lib64 -lipopt -lmumps_common -ldmumps -lzmumps -lsmumps -lcmumps -llapack -lblas -lblas -lblas -lm  -ldl' ./setup.py build
sudo python setup.py install

If you have an ipopt.pc which is not in the pkg-config search path, specify the path via the PKG_CONFIG_PATH environment variable (see below). If you cannot find an ipopt.pc in your ipopt installation, there is an example pc file pkgconfig/ipopt.pc. Copy it to a location (best of all directly in a subfolder named pkgconfig of your Ipopt installation) and edit it to reflect the library and include paths of the dependencies.

Then do

PKG_CONFIG_PATH=<dir containing ipopt.pc> python setup.py build
sudo python setup.py install

Testing

Unit tests:

python -m unittest

Run examples:

Use the following command under the examples directory.

python hs071.py

The file examples/hs071.py contains a toy optimization problem. If everything is OK, ipyopt will invoke Ipopt to 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. ipyopt also supports this feature. The file examples/hs071.py demonstrates the idea. If you provide the ipyopt.Problem constructor with an eval_h callback function, Ipopt will delegate the Hessian matrix calculation to your function (otherwise Ipopt will approximate Hessian for you).

Contributing

  1. Fork it.
  2. Create a branch (git checkout -b new_branch)
  3. Commit your changes (git commit -am "your awesome message")
  4. Push to the branch (git push origin new_branch)
  5. Create a merge request

Credits

  • Modifications on logger made by OpenMDAO at NASA Glenn Research Center, 2010 and 2011
  • Added "eval_intermediate_callback" by OpenMDAO at NASA Glenn Research Center, 2010 and 2011
  • Modifications on the SAFE_FREE macro made by Guillaume Jacquenot, 2012
  • Changed logger from code contributed by alanfalloon
  • Originally developed by Eric Xu when he was a PhD student at Washington University and issued under the BSD license. Original repository: xuy/pyipopt.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipyopt-0.12.9.tar.gz (38.6 kB view details)

Uploaded Source

Built Distributions

ipyopt-0.12.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.0 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

ipyopt-0.12.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.0 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ipyopt-0.12.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.0 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ipyopt-0.12.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.0 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ipyopt-0.12.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.0 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

ipyopt-0.12.9-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.0 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

ipyopt-0.12.9-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.0 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

File details

Details for the file ipyopt-0.12.9.tar.gz.

File metadata

  • Download URL: ipyopt-0.12.9.tar.gz
  • Upload date:
  • Size: 38.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for ipyopt-0.12.9.tar.gz
Algorithm Hash digest
SHA256 39fb08eef27e86d3a9ff9d1af921a42f6acfe72c3fd965bca32cc3e3ceb2db64
MD5 9a360cbec9e4a404ab3d619533f1429d
BLAKE2b-256 98c732d629143daef77aa4623d09a3766f952c3caf5f48ff8b43ce66b2aacd6b

See more details on using hashes here.

File details

Details for the file ipyopt-0.12.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ipyopt-0.12.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a856733f40a4ea042e23f4863da4cc653128de0858ab3980205a8111635074a5
MD5 6b9f6682d93c172fa69b4a91a6ba6f9e
BLAKE2b-256 ee95aaab082c47efa07e4b3b3c455e0e9508a9a7e1d8c0c1beb0d0515c8744d6

See more details on using hashes here.

File details

Details for the file ipyopt-0.12.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ipyopt-0.12.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4ac081e6aba1255a2b68bd59c02adfb92d62de11cb7880796334fb367fc96de8
MD5 fc2fad5d735f19776fa8ee666967d167
BLAKE2b-256 4736b6cdebb2e6cfe058873fcf052f368183e36dce4bb234f4db31f0c267a6d9

See more details on using hashes here.

File details

Details for the file ipyopt-0.12.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ipyopt-0.12.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6b7700f28081113203bc1ef6dc715bad6a3c9034095c46d99c16e583632e93a8
MD5 c657129b981e338c3c10462cd33d1ebe
BLAKE2b-256 9b56f52e2462fb4ce6fa7eaca5de90244343f373eff877134b791efc3e6b2d5b

See more details on using hashes here.

File details

Details for the file ipyopt-0.12.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ipyopt-0.12.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0ffe4d2582e214b331c0d955032fe0aa1f295e785e43d06557f8fa0920416f6a
MD5 7be1698557ae7efdfc69b46c72412232
BLAKE2b-256 e4d525b117936523e55596de77eb1d326f6ac4957fe39bd15677e3779e3c9583

See more details on using hashes here.

File details

Details for the file ipyopt-0.12.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ipyopt-0.12.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 75ecd08511005ebe147ce6bb869c83a5a750aed33bd2268037931ebe394e87f5
MD5 82b88cd14b52c706506530f2496410e9
BLAKE2b-256 994875bed2441bfa9235498577a7c7f5f7e9bf0c5590b5890e6ce4620292c7cd

See more details on using hashes here.

File details

Details for the file ipyopt-0.12.9-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ipyopt-0.12.9-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d0bfe3f54eb73b578479e0d14be689f62b75f786132b4dfb963f3f09c54de6f6
MD5 a99b212b8f890c655241fffdc516c0f1
BLAKE2b-256 8d0e12288b6d1a03f210b25e0435a1141bd58464fd86b77f543a3de61ccad7b5

See more details on using hashes here.

File details

Details for the file ipyopt-0.12.9-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ipyopt-0.12.9-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 32fcbc18b94f2ea23e2974bf69fc10d8fb8d87c59da265e3c2b97bff42c41bd9
MD5 d4dca6e7d082529b54ade3272e7c75fc
BLAKE2b-256 d917259005b677c5c54e5a4efa5834440cef77c578b3a5ae7950d9042dd06815

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page