• Stars
    star
    181
  • Rank 212,110 (Top 5 %)
  • Language
    Python
  • License
    Other
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RBFOpt library for black-box optimization

Table of contents

This software is released under the Revised BSD License. By using this software, you are implicitly accepting the terms of the license.

RBFOpt is a Python library for black-box optimization (also known as derivative-free optimization). It is developed for Python 3 but currently runs on Python 2.7 as well. This README contains installation instructions and a brief overview. More details can be found in the user manual.

Contents of this directory:

  • AUTHORS: Authors of the library.
  • CHANGELOG: Changelog.
  • LICENSE: Licensing information.
  • MANIFEST.in: List of additional files to be included in archives.
  • README.rst: This file.
  • VERSION: Version of the library.
  • manual.pdf: User manual.
  • requirements.txt: List of dependencies for this project.
  • setup.cfg: Configuration file for setup.py.
  • setup.py: Setup file.
  • tox.ini: Configuration file for tox.
  • bin/
    • rbfopt_cl_interface.py: Script for the command-line interface, to run the library on a user-defined black-box function implemented in a user-specified file.
    • rbfopt_test_interface.py: Script to test the library on a global optimization test set.
  • src/
    • rbfopt/
      • rbfopt_black_box.py: Description of an abstract black-box function.
      • rbfopt_algorithm.py: Main optimization algorithm, both serial and parallel.
      • rbfopt_aux_problems.py: Interface for the auxiliary problems solved during the optimization process.
      • rbfopt_degreeX_models.py: PyOmo models for the auxiliary problems necessary for RBF functions with minimum required polynomial degree X.
      • rbfopt_refinement: Routines for refinement phase.
      • rbfopt_settings.py: Global and algorithmic settings.
      • rbfopt_test_functions.py: Mathematical test functions.
      • rbfopt_user_black_box.py: A black-box class constructed from user data.
      • rbfopt_utils.py: Utility routines.
      • doc/
        • conf.py: Configuration file for Sphinx.
        • Makefile: Makefile (for Linux/Mac) to build the documentation.
        • make.bat: Batch file (for Windows) to build the documentation.
        • *.rst: ReStructured Text files for the documentation.
      • examples/
        • rbfopt_black_box_example.py: Example of an implementation of a simple black-box function.
  • tests/
    • context.py: Configuration file for nose.
    • test_functions.py: Global optimization test functions.
    • test_rbfopt_algorithm.py: Testing module for rbfopt_algorithm.py (regular unit tests).
    • slow_test_rbfopt_algorithm.py: Testing module for rbfopt_algorithm.py (additional, slow tests).
    • test_rbfopt_aux_problems.py: Testing module for rbfopt_aux_problems.py.
    • test_rbfopt_degreeX_models.py: Testing module for rbfopt_degreeX_models.py.
    • test_rbfopt_env.py: Environment variables for testing environment.
    • test_rbfopt_mwe.py: Test the minimal working example given in the documentation.
    • test_rbfopt_refinement: Testing module for rbfopt_refinement.py
    • test_rbfopt_settings.py: Testing module for rbfopt_settings.py.
    • test_rbfopt_utils.py: Testing module for rbfopt_utils.py.

Installation requirements

This package requires the following software:

  • Python version >= 3.7
  • NumPy version >= 1.11.0
  • SciPy version >= 0.17.0
  • Pyomo version >= 5.1.1

The software has been tested with the versions indicated above. It may work with earlier version and should work with subsequent version, if they are backward compatible. In particular, the software is known to work with Pyomo version 4 and earlier versions of Scipy.

The code is developed for Python 3.7, but it currently also runs on Python 2.7. Since Python 2.7 has reached end-of-life in January 2020, we recommend using Python 3.7 or higher.

The easiest, and recommended, way to install the package is via the Python module manager pip. The code is on PyPI, therefore it can be installed from PyPI using:

pip install rbfopt

You can install from source, downloading an archive or cloning from git (for example if you want to use a development version that is not released on PyPI yet), using the command:

pip install .

You may need the -e switch to install in a virtual environment. To build the documentation, you also need numpydoc:

pip install numpydoc

On Windows systems, we recommend WinPython, which comes with NumPy, SciPy and pip already installed. After installing WinPython, it is typically necessary to update the PATH environment variable. The above command using pip to install missing libraries has been successfully tested on a fresh WinPython installation.

RBFOpt requires the solution of convex and nonconvex nonlinear programs (NLPs), as well as nonconvex mixed-integer nonlinear programs (MINLPs) if some of the decision variables (design parameters) are constrained to be integer. Solution of these subproblems is performed through Pyomo, which in principle supports any solver with an AMPL interface (.nl file format). The code is setup to employ Bonmin and Ipopt, that are open-source, with a permissive license, and available through the COIN-OR repository. The end-users are responsible for checking that they have the right to use these solvers. To use different solvers, a few lines of the source code have to be modified: ask for help on GitHub or on the mailing list, see below.

To obtain pre-compiled binaries for Bonmin and Ipopt for several platforms, we suggest having a look at the AMPL opensource solvers (also here) for static binaries. Note: These binaries might be outdated: better performance can sometimes be obtained compiling Bonmin from scratch (Bonmin contains Ipopt as well), especially if compiling with a different solver for linear systems rather than the default Mumps, e.g., ma27. Bonmin and Ipopt must be compiled with ASL support.

In case any of the packages indicated above is missing, some features may be disabled, not function properly, or the software may not run at all.

Installation instructions and getting started

  1. Install the package with pip as indicated above. This will install the two executable Python scripts rbfopt_cl_interface.py and rbfopt_test_interface.py in your bin/ directory (whatever is used by pip for this purpose), as well as the module files in your site-packages directory.

  2. Make sure Bonmin and Ipopt are in your path; otherwise, use the options minlp_solver_path and nlp_solver_path in RbfoptSettings to indicate the full path to the solvers. If you use RBFOpt as a library and create your own RbfoptSettings object, these options can be given as:

    import rbfopt
    settings = rbfopt.RbfoptSettings(minlp_solver_path='full/path/to/bonmin', nlp_solver_path='full/path/to/ipopt')
    

    If you use the command-line tools, you can simply provide the option preceded by double hyphen, as in:

    rbfopt_test_interface.py --minlp_solver_path='full/path/to/bonmin' branin
    
  3. Enjoy!

  4. You can test the installation by running:

    rbfopt_test_interface.py branin
    

    See:

    rbfopt_test_interface.py --help
    

    for more details on command-line options for the testing tool.

    Many more test functions, with different characteristics, are implemented in the file rbfopt_test_functions.py. They can all be used for testing.

  5. Unit tests for the library can be executed by running:

    nose2
    

    or:

    python setup.py test
    

    from the current (main) directory. If some of the tests fail, the library may or may not work correctly. Some of the test failures are relatively harmless. You are advised to contact the mailing list (see below) if you are unsure about some test failure.

    Additional slow tests, that check if various parametrizations of the optimization algorithm can solve some global optimization problems, are found in the file slow_test_rbfopt_algorithm.py, which is ignored by nose by default. To execute these tests, run:

    nose2 tests.slow_test_rbfopt_algorithm
    

Minimal working example

After installation, the easiest way to optimize a function is to use the RbfoptUserBlackBox class to define a black-box, and execute RbfoptAlgorithm on it. This is a minimal example to optimize the 3-dimensional function defined below:

import rbfopt
import numpy as np
def obj_funct(x):
  return x[0]*x[1] - x[2]

bb = rbfopt.RbfoptUserBlackBox(3, np.array([0] * 3), np.array([10] * 3),
                               np.array(['R', 'I', 'R']), obj_funct)
settings = rbfopt.RbfoptSettings(max_evaluations=50)
alg = rbfopt.RbfoptAlgorithm(settings, bb)
val, x, itercount, evalcount, fast_evalcount = alg.optimize()

Another possibility is to define your own class derived from RbfoptBlackBox in a separate file, and execute the command-line interface on the file. An example is provided under src/rbfopt/examples, in the file rbfopt_black_box_example.py. This can be executed with:

rbfopt_cl_interface.py src/rbfopt/examples/rbfopt_black_box_example.py

Parallel optimization

RBFOpt supports asynchronous parallel optimization using Python's multiprocessing library. This mode is enabled whenever the parameter num_cpus is set to a value greater than 1. Black-box function evaluations as well as some of the heaviest computatations carried out by the algorithm will then be executed in parallel. Since the parallel computations are asynchronous, determinism cannot be guaranteed: in other words, if you execute the parallel optimizer twice in a row, you may (and often will) get different results, even if you provide the same random seed. This is because the order in which the computations will be completed may change, and this may impact the course of the algorithm.

The default parameters of the algorithm are optimized for the serial optimization mode. For recommendations on what parameters to use with the parallel optimizer, feel free to ask on the mailing list.

Note that the parallel optimizer is oblivious of the system-wide settings for executing linear algebra routines (BLAS) in parallel. We recommend setting the number of threads for BLAS to 1 when using the parallel optimizer, see the next section.

Known issues with OpenBLAS

We are aware of an issue when launching multiple distinct processes that use RBFOpt and the NumPy implementation is configured to use OpenBLAS in parallel: in this case, on rare occasions we have observed that some processes may get stuck forever when computing matrix-vector multiplications. The problem can be fixed by setting the number of threads for OpenBLAS to 1. We do not know if the same issue occurs with other parallel implementations of BLAS.

For this reason, and because parallel BLAS uses resources suboptimally when used in conjunction with the parallel optimizer of RBFOpt (if BLAS runs in parallel, each thread of the parallel optimizer would spawn multiple threads to run BLAS, therefore disregarding the option num_cpus), RBFOpt attempts to set the number of BLAS threads to 1 at run time.

All scripts (rbfopt_cl_interface.py and rbfopt_test_interface.py) set the environment variables OMP_NUM_THREADS to 1. Furthermore, the rbfopt module does the same when imported for the first time.

Note that these settings are only effective if the environment variable is set before NumPy is imported; otherwise, they are ignored. If you are facing the same issue, we recommend setting environment variable OMP_NUM_THREADS to 1. In Python, this can be done with:

import os
os.environ['OMP_NUM_THREADS'] = '1'

Documentation

The documentation for the code can be built using Sphinx with the numpydoc extension. numpydoc can be installed with pip:

pip install numpydoc

After that, the directory src/rbfopt/doc/ contains a Makefile (on Windows, use make.bat) and the Sphinx configuration file conf.py.

You can build the HTML documentation (recommended) with:

make html

The output will be located in _build/html/ and the index can be found in _build/html/index.html.

A PDF version of the documentation (much less readable than the HTML version) can be built using the command:

make latexpdf

An online version of the documentation for the latest master branch of the code, and for the latest stable release, are available on ReadTheDocs for the latest and stable version.

Citing RBFOpt

If you use RBFOpt in one of your projects or papers, please cite the following papers (this is the only way in which the authors get credit):

  • A. Costa and G. Nannicini. RBFOpt: an open-source library for black-box optimization with costly function evaluations. Mathematical Programming Computation, 10(4):597–629, 2018. (The paper can be downloaded as: Optimization Online paper 4538)
  • G. Nannicini. On the implementation of a global optimization method for mixed-variable problems. Open Journal of Mathematical Optimization, 2(1), 2021. (Download link: OJMO)

RBFOpt for hyperparameter optimization

RBFOpt is used in IBM Watson Studio AutoAI. For a discussion on the application of RBFOpt to hyperparameter optimization in machine learning, besides the aforementioned paper published in OJMO, see the paper:

  • G. I. Diaz, A. Fokoue-Nkoutche, G. Nannicini and H. Samulowitz. An effective algorithm for hyperparameter optimization of neural networks. IBM Journal of Research and Development 61, no. 4/5 (2017): 9-1. (Download link: IBM Journal of R&D)

Support

If you believe there is a bug or an issue, please open an issue on GitHub. If you have a general question, please use GitHub's "Discussions" feature (the tab can be opened at the top of the page).

More Repositories

1

pulp

A python Linear Programming API
Python
2,058
star
2

Ipopt

COIN-OR Interior Point Optimizer IPOPT
C++
1,082
star
3

Cbc

COIN-OR Branch-and-Cut solver
C++
620
star
4

python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Python
520
star
5

CppAD

A C++ Algorithmic Differentiation Package: Home Page
C++
375
star
6

Clp

COIN-OR Linear Programming Solver
C++
321
star
7

qpOASES

Open-source C++ implementation of the recently proposed online active set strategy
C++
261
star
8

CyLP

A Python interface to CLP, CBC, and CGL to solve LPs and MIPs.
JetBrains MPS
175
star
9

Gravity

Mathematical Modeling for Optimization and Machine Learning
C++
149
star
10

SHOT

A solver for mixed-integer nonlinear optimization problems
C++
118
star
11

COIN-OR-OptimizationSuite

A harness for building the bundled suite of interoperable optimization tools available in the COIN-OR repository.
Shell
105
star
12

Bonmin

Basic Open-source Nonlinear Mixed INteger programming
C++
103
star
13

ADOL-C

A Package for Automatic Differentiation of Algorithms Written in C/C++
C++
94
star
14

Cbc.old

This is a mirror of the subversion repository on COIN-OR
C++
88
star
15

minotaur

Minotaur Toolkit for Mixed-Integer Nonlinear Optimization
C++
68
star
16

GrUMPy

A Python library for visualizing algorithms for solving mathematical optimization problems.
Shell
60
star
17

SYMPHONY

SYMPHONY is an open-source solver, callable library, and development framework for mixed-integer linear programs (MILPs) written in C with a number of unique features
C
59
star
18

Couenne

Convex Over and Under Envelopes for Nonlinear Estimation
C++
55
star
19

jorlib

Java Operations Research Library
Java
54
star
20

Csdp

This is the working repository for the CSDP project. CSDP is a solver for semidefinite programming problems. It is a COIN-OR project.
C
52
star
21

MibS

A solver for mixed integer bilevel programs
JetBrains MPS
50
star
22

Osi

Open Solver Interface
C++
48
star
23

CoinUtils

COIN-OR Utilities
C++
44
star
24

Rehearse

Algebraic modeling library in C++ for linear optimization solvers
M4
42
star
25

prtpy

Number partitioning in Python
Python
42
star
26

Clp.old

This a mirror of the subversion repository on COIN-OR.
C++
36
star
27

GiMPy

A graph library containing pure Python implementations of a variety of graph algorithms
Python
33
star
28

coinbrew

COIN-OR build and installation script
Shell
26
star
29

metslib

An Open Source Tabu Search Metaheuristic framework in C++
C++
25
star
30

Bcp

Branch-Cut-Price Framework
C++
24
star
31

Cgl

Cut Generator Library
C++
21
star
32

VRPH

VRPH is an open source library of heuristics for the capacitated Vehicle Routing Problem (VRP).
C++
19
star
33

SYMPHONY.old

This a mirror of the subversion repository on COIN-OR.
C
16
star
34

Dip

DIP is a decomposition-based solver framework for mixed integer linear programs.
C++
15
star
35

Osi.old

This a mirror of the subversion repository on COIN-OR.
C++
11
star
36

Sonnet

A wrapper for COIN-OR mixed integer linear programming via OSI to Microsoft .NET
C#
10
star
37

Dip.old

This a mirror of the subversion repository on COIN-OR.
C++
10
star
38

CoinMP

C-API library for CLP, CBC, and CGL
Shell
9
star
39

Cmpl

<Coliop|Coin> Mathematical Programming Language
C++
9
star
40

CHiPPS-ALPS

This is the Abstract Library for Parallel Search (ALPS), the abstract base layer of the COIN-OR High Performance Parallel Search framework.
C++
8
star
41

FlopCpp

An open source algebraic modelling language implemented as a C++ class library
Shell
8
star
42

oBB

Overlapping Branch and Bound Algorithm
C++
8
star
43

GAMSlinks

Links between GAMS (General Algebraic Modeling System) and solvers
C++
8
star
44

DisCO

Discrete Conic Optimization Solver
C++
7
star
45

filterSD

a library for nonlinear optimization written in Fortran
Fortran
7
star
46

CoinUtils.old

This a mirror of the subversion repository on COIN-OR.
C++
7
star
47

Paver

Python scripts to do comparisons on solver performance
Python
7
star
48

Vol

A C++ implementation of the volume algorithm for linear programming
Shell
7
star
49

Couenne.old

This a mirror of the subversion repository on COIN-OR. For bugtracking and wiki, see website.
C++
7
star
50

CHiPPS-BLIS

This is the BiCePS Linear Integer Solver (BLIS), a parallel solver for mixed integer linear programs that is implemented on top of the BiCePS layer of the CHiPPS framework.
C++
6
star
51

jMarkov

Java framework for Markov-chain (MC) modelling
Java
5
star
52

yaposib

Python binding to coin-osi
C++
5
star
53

Cgl.old

This a mirror of the subversion repository on COIN-OR.
C++
4
star
54

metslib-examples

Examples for METSLib
C++
4
star
55

ROSE

Reformulation-Optimization Software Engine
C++
3
star
56

Smi

An API for stochastic programming problems.
Shell
3
star
57

DyLP

Dynamic Simplex solver
C
2
star
58

CoinMP.old

Mirror of the CoinMP project from https://projects.coin-or.org/svn/CoinMP
Shell
2
star
59

coin-or.github.io

COIN-OR General Documentation
HTML
2
star
60

Osi2

Open Solver Interface Version 2
C++
1
star
61

MOCHA

Algorithms and heuristics to solve multicriteria matroid optimization problems
M4
1
star
62

Cgc

Cgc is a collection of network representations to facilitate the development and implementation of network algorithms.
C++
1
star
63

OS

Optimization Services
C++
1
star
64

PFunc

Generic task-parallel library for C/C++
C++
1
star
65

NLPAPI

NLPAPI is a set of subroutines and data structures for defining nonlinear programming problems. It includes an interface to call LANCELOT to solve the problem (you need to get your own copy of LANCELOT), and an interface to IPOPT.
C
1
star