library for nonlinear optimization, wrapping many algorithms for global and local, constrained or unconstrained, optimization

Related tags

Deep Learning nlopt
Overview

Latest Docs Build Status Build Status

NLopt is a library for nonlinear local and global optimization, for functions with and without gradient information. It is designed as a simple, unified interface and packaging of several free/open-source nonlinear optimization libraries.

The latest release can be downloaded from the NLopt releases page on Github, and the NLopt manual is hosted on readthedocs.

NLopt is compiled and installed with the CMake build system (see CMakeLists.txt file for available options):

git clone git://github.com/stevengj/nlopt
cd nlopt
mkdir build
cd build
cmake ..
make
sudo make install

(To build the latest development sources from git, you will need SWIG to generate the Python and Guile bindings.)

Once it is installed, #include <nlopt.h> in your C/C++ programs and link it with -lnlopt -lm. You may need to use a C++ compiler to link in order to include the C++ libraries (which are used internally by NLopt, even though it exports a C API). See the C reference manual.

There are also interfaces for C++, Fortran, Python, Matlab or GNU Octave, OCaml, GNU Guile, GNU R, Lua, Rust, and Julia. Interfaces for other languages may be added in the future.

Comments
  • nlopt compilation failed at

    nlopt compilation failed at "make" step on AIX7.2

    I am trying to compile nlopt on AIX7.2. The 1st "cmake" step finished successfully. However, the 2nd "make" step failed with the ERROR: Undefined symbol: __tls_get_addr. Can you help me to figure out the issue? Thanks.

    [ 66%] Building CXX object CMakeFiles/nlopt.dir/src/algs/stogo/global.cc.o
    [ 68%] Building CXX object CMakeFiles/nlopt.dir/src/algs/stogo/linalg.cc.o
    [ 70%] Building CXX object CMakeFiles/nlopt.dir/src/algs/stogo/local.cc.o
    [ 71%] Building CXX object CMakeFiles/nlopt.dir/src/algs/stogo/stogo.cc.o
    [ 73%] Building CXX object CMakeFiles/nlopt.dir/src/algs/stogo/tools.cc.o
    [ 75%] Building CXX object CMakeFiles/nlopt.dir/src/algs/ags/evolvent.cc.o
    [ 76%] Building CXX object CMakeFiles/nlopt.dir/src/algs/ags/solver.cc.o
    [ 78%] Building CXX object CMakeFiles/nlopt.dir/src/algs/ags/local_optimizer.cc.o
    [ 80%] Building CXX object CMakeFiles/nlopt.dir/src/algs/ags/ags.cc.o
    [ 81%] Linking CXX shared library libnlopt
    ld: 0711-317 ERROR: Undefined symbol: __tls_get_addr
    ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
    collect2: error: ld returned 8 exit status
    make[2]: *** [CMakeFiles/nlopt.dir/build.make:767: libnlopt.a] Error 1
    make[2]: Leaving directory '/software/thirdparty/nlopt-master/build'
    make[1]: *** [CMakeFiles/Makefile2:179: CMakeFiles/nlopt.dir/all] Error 2
    make[1]: Leaving directory '/software/thirdparty/nlopt-master/build'
    make: *** [Makefile:163: all] Error 2
    
    opened by bergen288 29
  • Prefer target_include_directories in CMake build script

    Prefer target_include_directories in CMake build script

    This PR facilitates the inclusion of nlopt into other CMake projects.

    • The "private" include directories are defined in a per-target basis via target_include_directories instead of include_directories. This has the advantage that it doesn't "pollute" parent projects.
    • Public include directories are set via the INTERFACE argument in target_include_directories. To keep it simple the original header nlopt.h is simply copied in the ${PROJECT_BINARY_DIR}/api folder, which is used as the interface include directory for nlopt. Unfortunatelly, absolute paths cannot be given as interface include directories for installed targets, hence the need for the trick with $<BUILD_INTERFACE:...>. However this generator expression has been introduced in cmake 3.0, so the minimum required version is bumped to 3.0, but maybe you don't want that?
    • Similarly, use target_compile_definitions instead of a global add_definitions.
    • I couldn't make per-target include directories work with SWIG, so there is still a include_directories appearing in the swig/CMakeLists.txt. This is not ideal, but if you have any idea to improve this I'm all ears.

    Now, building nlopt as part of other projects is as simple as

    add_subdirectory(ext/nlopt)
    target_link_libraries(my_program nlopt)
    
    opened by jdumas 15
  • Implement C++ style functors as targets for objectives

    Implement C++ style functors as targets for objectives

    This PR implements a wrapper nlopt::functor_wrapper for C++ style functors via std::function, and two new overloads of nlopt::set_min_objective, nlopt::set_max_objective.

    In order to allow that, a new member field in the myfunc_data struct is added: functor_type functor;, where functor_type is defined as

    typedef std::function<double(unsigned, const double*, double*)> functor_type;
    

    This is not introduced as a pointer (like the other function-pointers are) because std::function is already a container that stores a pointer, and abstracts it away.

    Important: note that the signature for the functor does not include void* data unlike all other function-pointers. That is because it is assumed that the functor already has all the data it needs.

    This PR allows now to write the following:

    class UserDefinedObjective {
      private:
        ImportantData data;
      public:
        UserDefinedObjective() = delete;
        UserDefinedObjective(ImportantData data) :
          data(std::move(data)) {}
        double operator()(unsigned n, const double* x, double* grad) const
        {
          // compute objective(x) and ∇objective(x) using this->data
        }
    };
    
    int main()
    {
      ImportantData data;
      UserDefinedObjective objective(std::move(data));
    
      nlopt::opt optimizer;
      // other nlopt settings
      optimizer.set_max_objective(std::move(objective));
    
      optimizer.optimize(...);
    
      return 0;
    }
    

    Same with C++ lambdas, regular functions and even class member functions (check out std::function).

    This PR also introduces a CMake macro NLOPT_add_cpp_test to quickly add cpp tests, and creates a test cpp_functor.cxx to actually test the new functionality.

    Closes #219 .

    opened by dburov190 14
  • Added example of automatic tests

    Added example of automatic tests

    • Added new_test target to generate test executable
    • Updated CMakeLists.txt to add test as subfolder
    • Added two test using executable new_test
    • Now you can run test suite by just typing either "make test" or "ctest" in the build directory
    opened by boris-il-forte 14
  • C++11 idiom

    C++11 idiom

    I found nlopt a great library, but using it through the C++ is really frustrating. You need to provide a void* for passing data to the objective/constraint functions, with all the problemas that may have.

    Also, you need to pass a function pointer, so you cant use lambda functions with captures (that would avoid passing the void*).

    Ive written a thin wrapper on top of NLopt which tries to offer a more modern c++ API, enabling the use of lambdas and hiding from the API the use of void*.

    Would you be interested in this to be merge?

    opened by jjcasmar 13
  • DIRECT takes impossibly long to reach xtol

    DIRECT takes impossibly long to reach xtol

    Unless I'm mistaken, the XTOL stopping criterion for DIRECT (the cdirect version) can't be used when searching large multi-dimensional spaces, because it requires all hyper-rectangles everywhere to be divided down to below the x-tolerances before stopping. This will take an impossibly long time.

    Wouldn't it make more sense to stop as soon as one (or a few) of the rectangles is small? This could be done by inverting some of the logic for the xtol_reached variable within the cdirect.c function divide_good_rects().

    I can attach some test code here or work towards a pull request if that would be helpful.

    Cheers, Joel

    opened by jcottrell-ellex 11
  • Website & download URLs down

    Website & download URLs down

    I get the following while trying to install:

    configure: Need to download and build NLopt
    trying URL 'http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz'
    Warning in download.file(url = "http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz",  :
      unable to connect to 'ab-initio.mit.edu' on port 80.
    Error in download.file(url = "http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz",  : 
      cannot open URL 'http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz'
    Execution halted
    /bin/tar: This does not look like a tar archive
    
    gzip: stdin: unexpected end of file
    /bin/tar: Child returned status 1
    /bin/tar: Error is not recoverable: exiting now
    

    The website, http://ab-initio.mit.edu/nlopt/, also does not display in my browser (ERR_CONNECTION_TIMED_OUT)

    opened by IljaKroonen 11
  • Prevent a conditional jump based on uninitialized value in nlopt_create.

    Prevent a conditional jump based on uninitialized value in nlopt_create.

    nlopt_set_lower_bounds1 reads from opt->ub before it has ever been written.

    We caught this in our nightly memcheck CI build for RobotLocomotion/drake: https://drake-cdash.csail.mit.edu/viewDynamicAnalysisFile.php?id=14355

    Contributes to RobotLocomotion/drake#3873


    This change is Reviewable

    opened by david-german-tri 11
  • New release

    New release

    I'm running into issue https://github.com/stevengj/nlopt/issues/33. Could you make a new release that includes that fix, please? It would fix dozens of R packages on NixOS.

    Looks like the last one was in 2014!

    opened by langston-barrett 11
  • Generate missing nlopt.hpp and nlopt.f (CMake), use GNUInstallDirs (CMake), fix for MSVC 2015

    Generate missing nlopt.hpp and nlopt.f (CMake), use GNUInstallDirs (CMake), fix for MSVC 2015

    Create missing nlopt.hpp and nlopt.f when building with CMake Use CMake's GNUInstallDIrs (e.g, ${CMAKE_INSTALL_LIBDIR} instead of lib) depending on platform Fix for MSVC 2015 compiler

    opened by rickertm 11
  • Running tests with CTest is broken

    Running tests with CTest is broken

    If I check out NLopt, build it, and try to run the tests with ctest, it fails horribly because testopt was not built.

    The way this works is a non-standard workflow and prevents running the tests e.g. when NLopt is built as a CMake external project.

    Please, either just build testopt by default (i.e. remove EXCLUDE_FROM_ALL), or else add an option (e.g. NLOPT_ENABLE_TESTS) that controls whether testopt is built by default and whether any add_test are invoked.

    opened by mwoehlke-kitware 10
  • Error installing `nloptr` from source on CentOS cluster

    Error installing `nloptr` from source on CentOS cluster

    I am trying to install nloptr from source in R version 4.1.3 on a cluster (CentOS). However I receive the following error:

    /cvmfs/argon.hpc.uiowa.edu/2022.1/prefix/usr/lib/gcc/x86_64-pc-linux-gnu/9.4.0/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lnlopt
    collect2: error: ld returned 1 exit status
    make: *** [/cvmfs/argon.hpc.uiowa.edu/2022.1/apps/linux-centos7-broadwell/gcc-9.4.0/r-4.1.3-ljofaul/rlib/R/share/make/shlib.mk:10: nloptr.so] Error 1
    ERROR: compilation failed for package ‘nloptr’
    

    I am on a university cluster and cannot run sudo commands. After encouragement from @eddelbuettel to contact my sys admin, he figured out the issue. Here's what he wrote:


    The build environment for nloptr uses pkg-config to get information about nlopt. It turns out that the pkg-config file has an error. It has

    libdir=${exec_prefix}/lib

    but the library is actually located in

    libdir=${exec_prefix}/lib64

    That does not show up in the packaging environment because LIBRARY_PATH is set for the dependency chain. I will need to fix the pkg-config file in the package recipe, but you can work around it as follows:

    1. load environment modules:
    module load stack/2022.1
    module load nlopt
    
    1. set LIBRARY_PATH so linker can find library while launching R session (single line below):
    LIBRARY_PATH=$ROOT_NLOPT/lib64:$LIBRARY_PATH R
    
    1. install nloptr in the R console (single line below):
    install.packages(verbose=1,'nloptr')
    

    I originally posted this issue in the nloptr repo: https://github.com/astamm/nloptr/issues/123. However, @eddelbuettel encouraged me to post an issue here because we suspect that the issue may be the pkg-config file created by nlopt.

    Here's the output of some of my commands in CentOS:

    [[email protected] ~]$ module load stack/2022.1
    
    The following have been reloaded with a version change:
      1) stack/2020.1 => stack/2022.1
    
    [[email protected] ~]$ module load r/4.1.3_gcc-9.4.0
    [[email protected] ~]$ module load nlopt
    [[email protected] ~]$ R CMD config --all | grep lib64
    LIBnn = lib64
    [[email protected] ~]$ pkg-config --libs nlopt
    -L/cvmfs/argon.hpc.uiowa.edu/2022.1/apps/linux-centos7-broadwell/gcc-9.4.0/nlopt-2.7.0-u5x4377/lib -lnlopt
    

    We think we would want that to be (https://github.com/astamm/nloptr/issues/123#issuecomment-1317199965_):

    -L/cvmfs/argon.hpc.uiowa.edu/2022.1/apps/linux-centos7-broadwell/gcc-9.4.0/nlopt-2.7.0-u5x4377/lib64 -lnlopt
    

    That is, /lib64 in my case instead of /lib. @eddelbuettel, please clarify if I missed anything or got anything wrong!

    opened by isaactpetersen 4
  • Nonlineay constraints get violated in the result.

    Nonlineay constraints get violated in the result.

    Hi there: During my optimization, I applied LN_COBYLA since it supports arbitrary nonlinear constraint. My "constraint function" is actually a collision avoidance function. The function returns 10.0 when collision hits, so that the constraint should be view as unsatisfied. However, the result in experiment shows the constraint is not satisfied, and the algorithm can still get finished and converge. Can anyone give me some advice? Thanks sincerely! Screenshot from 2022-10-29 21-14-44

    opened by Lbaron980810 2
  • C++ debugging nlopt

    C++ debugging nlopt

    Hi, I am sorry for maybe a vague question but is there a way to find out (debug/verbose/...) why nlopt fails? I am using C++ API and the only exception is that the nlopt returns nlopt failure after a few iterations and from that, I cannot find any clue. The numeric code of the result is a weird number (99968768). Therefore I would like to ask what can someone do in order to debug nlopt?

    opened by TomasMerva 3
  • Add vcpkg installation instructions

    Add vcpkg installation instructions

    NLopt is available as a port in vcpkg, a C++ library manager that simplifies installation for NLopt and other project dependencies. Documenting the install process here will help users get started by providing a single set of commands to build NLopt, ready to be included in their projects.

    We also test whether our library ports build in various configurations (dynamic, static) on various platforms (OSX, Linux, Windows: x86, x64) to keep a wide coverage for users.

    I'm a maintainer for vcpkg, and here is what the port script looks like. We try to keep the library maintained as close as possible to the original library.

    opened by FrankXie05 0
  • NLopt roundoff-limited error from simple example

    NLopt roundoff-limited error from simple example

    I saw https://www.reddit.com/r/cpp_questions/comments/k6743d/nlopt_round_off_error/ and translated it to Python.

    import nlopt
    
    def obj_fn(x,grad):
        print("%.16f,%.16f"%(x[0],x[1]))
        print("%.16f"%(-x[0]+x[1]))
        return -x[0]+x[1]
    
    opt = nlopt.opt(nlopt.LN_COBYLA,2)
    opt.set_lower_bounds([-3.0,-3.0])
    opt.set_upper_bounds([3.0,3.0])
    opt.set_min_objective(obj_fn)
    opt.set_ftol_abs(1)
    opt.optimize([-1.5,-1.5])
    print(opt.last_optimize_result())
    

    The python version also always throws an nlopt roundoff-limited error. Do you think there is a bug causing this? More generally, what should we do to avoid hitting nlopt roundoff-limited errors? Thanks!

    opened by imbacalvin 0
Releases(v2.7.1)
Owner
Steven G. Johnson
Steven G. Johnson
Cross Quality LFW: A database for Analyzing Cross-Resolution Image Face Recognition in Unconstrained Environments

Cross-Quality Labeled Faces in the Wild (XQLFW) Here, we release the database, evaluation protocol and code for the following paper: Cross Quality LFW

Martin Knoche 11 Nov 2, 2022
Official Pytorch implementation of 6DRepNet: 6D Rotation representation for unconstrained head pose estimation.

6D Rotation Representation for Unconstrained Head Pose Estimation (Pytorch) Paper Thorsten Hempel and Ahmed A. Abdelrahman and Ayoub Al-Hamadi, "6D Ro

Thorsten Hempel 263 Nov 21, 2022
Official implementation of the MM'21 paper Constrained Graphic Layout Generation via Latent Optimization

[MM'21] Constrained Graphic Layout Generation via Latent Optimization This repository provides the official code for the paper "Constrained Graphic La

Kotaro Kikuchi 65 Nov 17, 2022
PyTorch implementation of Constrained Policy Optimization

PyTorch implementation of Constrained Policy Optimization (CPO) This repository has a simple to understand and use implementation of CPO in PyTorch. A

Sapana Chaudhary 24 Oct 31, 2022
A semismooth Newton method for elliptic PDE-constrained optimization

sNewton4PDEOpt The Python module implements a semismooth Newton method for solving finite-element discretizations of the strongly convex, linear ellip

null 1 Oct 9, 2022
Learning nonlinear operators via DeepONet

DeepONet: Learning nonlinear operators The source code for the paper Learning nonlinear operators via DeepONet based on the universal approximation th

Lu Lu 226 Nov 15, 2022
DeepLM: Large-scale Nonlinear Least Squares on Deep Learning Frameworks using Stochastic Domain Decomposition (CVPR 2021)

DeepLM DeepLM: Large-scale Nonlinear Least Squares on Deep Learning Frameworks using Stochastic Domain Decomposition (CVPR 2021) Run Please install th

Jingwei Huang 128 Nov 17, 2022
A python implementation of Physics-informed Spline Learning for nonlinear dynamics discovery

PiSL A python implementation of Physics-informed Spline Learning for nonlinear dynamics discovery. Sun, F., Liu, Y. and Sun, H., 2021. Physics-informe

Fangzheng (Andy) Sun 8 Jul 13, 2022
Contrastive Learning for Many-to-many Multilingual Neural Machine Translation(mCOLT/mRASP2), ACL2021

Contrastive Learning for Many-to-many Multilingual Neural Machine Translation(mCOLT/mRASP2), ACL2021 The code for training mCOLT/mRASP2, a multilingua

null 100 Nov 23, 2022
M2MRF: Many-to-Many Reassembly of Features for Tiny Lesion Segmentation in Fundus Images

M2MRF: Many-to-Many Reassembly of Features for Tiny Lesion Segmentation in Fundus Images This repo is the official implementation of paper "M2MRF: Man

null 10 Sep 10, 2022
Neon-erc20-example - Example of creating SPL token and wrapping it with ERC20 interface in Neon EVM

Example of wrapping SPL token by ERC2-20 interface in Neon Requirements Install

null 7 Mar 28, 2022
API for RL algorithm design & testing of BCA (Building Control Agent) HVAC on EnergyPlus building energy simulator by wrapping their EMS Python API

RL - EmsPy (work In Progress...) The EmsPy Python package was made to facilitate Reinforcement Learning (RL) algorithm research for developing and tes

null 17 Nov 20, 2022
Implementation of Self-supervised Graph-level Representation Learning with Local and Global Structure (ICML 2021).

Self-supervised Graph-level Representation Learning with Local and Global Structure Introduction This project is an implementation of ``Self-supervise

MilaGraph 49 Oct 31, 2022
Conformer: Local Features Coupling Global Representations for Visual Recognition

Conformer: Local Features Coupling Global Representations for Visual Recognition (arxiv) This repository is built upon DeiT and timm Usage First, inst

Zhiliang Peng 364 Nov 14, 2022
Official code for "Focal Self-attention for Local-Global Interactions in Vision Transformers"

Focal Transformer This is the official implementation of our Focal Transformer -- "Focal Self-attention for Local-Global Interactions in Vision Transf

Microsoft 481 Nov 22, 2022
Decentralized Reinforcment Learning: Global Decision-Making via Local Economic Transactions (ICML 2020)

Decentralized Reinforcement Learning This is the code complementing the paper Decentralized Reinforcment Learning: Global Decision-Making via Local Ec

null 40 Oct 30, 2022
Pytorch implementation of 'Fingerprint Presentation Attack Detector Using Global-Local Model'

RTK-PAD This is an official pytorch implementation of 'Fingerprint Presentation Attack Detector Using Global-Local Model', which is accepted by IEEE T

null 6 Aug 1, 2022
Losslandscapetaxonomy - Taxonomizing local versus global structure in neural network loss landscapes

Taxonomizing local versus global structure in neural network loss landscapes Int

Yaoqing Yang 6 Aug 23, 2022