#ipopt #optimization #non-linear #constrained #unsafe

sys ipopt-sys

Raw unsafe Rust bindings to the Ipopt non-linear optimization library

13 releases

new 0.6.0 Dec 14, 2024
0.5.5 Nov 26, 2020
0.5.4 Mar 8, 2020
0.5.1 Apr 23, 2019
0.1.0 Mar 1, 2018

#5 in #ipopt

Download history 47/week @ 2024-08-26 34/week @ 2024-09-02 27/week @ 2024-09-09 11/week @ 2024-09-16 38/week @ 2024-09-23 154/week @ 2024-12-09

154 downloads per month
Used in 2 crates (via ipopt)

MIT/Apache

86KB
2K SLoC

Rust 1K SLoC // 0.1% comments C++ 411 SLoC // 0.0% comments C 261 SLoC // 0.0% comments

ipopt-sys

This package provides unsafe Rust bindings to the Ipopt non-linear optimization library. Unlike most other wrappers for Ipopt, we link against a custom C interface called CNLP, which mimics Ipopt's own C++ TNLP interface. This serves two purposes:

  1. It helps users who are already familiar with Ipopt's C++ interface to transition into Rust.
  2. It persists the Ipopt solver instance between subsequent solves, which eliminates unnecessary additional allocations for initial data and bounds.

This also means that you will need a working C++ compiler and a C++ standard library implementation available since the CNLP shim currently uses it in the implementation.

Contributions are welcome!

Building

We provide a number of options for building Ipopt from source as well as different methods for retrieving binaries. Building also requires the openssl and libclang system libraries. Currently supported methods for getting the Ipopt library:

  1. Using pkg-config to find a system installed static or dynamic library.

  2. Manually check system lib directories for a dynamic library.

  3. Build Ipopt from source. You will need fortran compiler libs installed (e.g. libgfortran) and one of the following options for linear solvers:

    a. Linking against MKL. (set MKLROOT environment variable to specify a custom MKL installation path or if the system path is not found.)

    b. Building with MUMPS/METIS and linking against a system installed OpenBLAS library (Linux) or Accelerate framework (macOS). If no system BLAS/LAPACK libraries are found, then the default netlib implementations will be pulled and built.

  4. Download a prebuilt dynamic Ipopt library from JuliaOpt.

Each of these steps are at various levels of polish and currently tested on Linux and macOS systems only.

MacOS

Since macOS doesn't ship with the fortran library, you would need to install it manually. Using homebrew you may either install gcc or gfortran directly with

$ brew install gcc

or

$ brew cask install gfortran

respectively. Since homebrew doesn't link these automatically from /usr/local/lib, you will have to create the symlink manually with

$ ln -s /usr/local/Cellar/gcc/8.3.0_2/lib/gcc/8/libgfortran.dylib /usr/local/lib/libgfortran.dylib

if you have libgfortran from the gcc set (mind the gcc version). Otherwise create the symlink with

$ ln -s /usr/local/gfortran/lib/libgfortran.dylib /usr/local/lib/libgfortran.dylib

if you installed gfortran directly.

Ultimately, no matter which method you choose, libgfortran.dylib must be available through the linker search paths.

Troubleshooting

  • Error compiling Mumps:

  • If you see an error message when trying to build ipopt-sys like the following:

    = note: ld.lld: error: undefined symbol: MKLMPI_Get_wrappers
            >>> referenced by mkl_get_mpi_wrappers.c
            >>>               mkl_get_mpi_wrappers_static.o:(mkl_serv_get_mpi_wrappers) in archive
            >>>               <mkl_root>/lib/libmkl_core.a
            clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    It is most likely that downstream builds will succeed if they don't use that symbol. To test if that is the case try to build ipopt-rs directly.

License

This repository is licensed under either of

at your option.

No runtime deps

~0–4.5MB
~83K SLoC