Skip to main content

Bindings to Ipopt C++ library.

Project description

Pypopt: Ipopt for Python

Pypopt is an Ipopt wrapper for Python. The aim is to expose the same API as Ipopt C++ interface.

Examples

You can find examples in the examples/ folder.

PythonJournal

In Pypopt you can use Python objects as targets for Ipopt journaling. The Python objects needs to implement two methods:

  • write(str): called to write str to the stream object

  • flush(): called to flush the stream

This means we can use Python3 io.StringIO to capture Ipopt output to string:

app = IpoptApplication()
f = io.StringIO()
j = PythonJournal(EJournalLevel.J_NONE, f)
jnlst = app.journalist()
jnlst.add_journal(j)

Requirements

  • A working C++ compiler

  • Cython

  • Ipopt

  • Pytest + pytest-runner + pytest-cov for testing

Ipopt Installation

We recommend installing Ipopt from source.

If you have Ipopt installed in a different location than /usr set the following environment variables before proceeding to the next section:

IPOPT_INCLUDE_DIR=/path/to/ipopt/include
IPOPT_LIBRARY_DIR=/path/to/ipopt/lib

Installation

Pypopt is available on Pypi:

pip install pypopt

Installation from Source

To install pypopt simply run:

python setup.py install

Troubleshooting

Pypopt is a Cython extension, this makes it sometimes tricky to install correctly.

Different toolchain for Ipopt and Pypopt

Ipopt and Pypopt need to be compiled with the same C++ toolchain. If that’s not the case, you will see an error like the following when loading Pypopt:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/python3.6/site-packages/pypopt/__init__.py", line 24, in <module>
  from pypopt._cython import (
ImportError: /lib/python3.6/site-packages/pypopt/_cython.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZN5Ipopt7Journal4NameB5cxx11Ev

This means Ipopt and Pypopt were compiled with different compilers/flags. To fix this issue install Ipopt from source and set the IPOPT_INCLUDE_DIR and IPOPT_LIBRARY_DIR environment variables to your Ipopt installation.

License

Copyright 2018 Francesco Ceccon

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Changelog

0.4.3 (2018-08-16)

  • Change finalize_solution callback to include SolverReturn status

0.4.2 (2018-07-05)

  • Documentation update

0.4.1 (2018-07-05)

  • Fix MANIFEST.in

0.4.0 (2018-07-05)

  • Changes to TNLP interface

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

pypopt-0.4.3.tar.gz (202.5 kB view details)

Uploaded Source

File details

Details for the file pypopt-0.4.3.tar.gz.

File metadata

  • Download URL: pypopt-0.4.3.tar.gz
  • Upload date:
  • Size: 202.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6

File hashes

Hashes for pypopt-0.4.3.tar.gz
Algorithm Hash digest
SHA256 b0a488707890cea8731af59844ab67965df2f2c523cf9de27be9061b82f66b6a
MD5 125dc440a105613e528d190d8caca786
BLAKE2b-256 3af3093c6b8f619e3be350f6200df9e42e20b4982f51b9cbf68d2915d215c91d

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