Giter Club home page Giter Club logo

rbfopt's Introduction

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).

rbfopt's People

Contributors

gnannicini avatar kolanich avatar mishpat avatar sartorg avatar svigerske avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rbfopt's Issues

import rbfopt causes Excel to close

I know this is a really weird issue. I have been using Python on Windows for 6 years and never encountered something like this before.

I am running Python 3.6.7 on Windows 7 64bit and Microsoft Excel 2016 64bit. When I run import rbfopt, if I have Excel open, it triggers Excel to close. I get a popup asking if I want to save the file first, so it's not forcing Excel to exit. Is anyone else able to confirm if this is also happening to them?

All you need is a .py file with the line and a running instance of Excel. Or type it into a running Python console.
import rbfopt

Using the module after it has been imported doesn't affect Excel, just the import line.

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 81: character maps to <undefined>

When I run the minimum working example as shown 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(minlp_solver_path=r'C:\ProjTMS\MecosTools\mbtools4x\bin\bonmin.exe', nlp_solver_path=r'C:\ProjTMS\MecosTools\mbtools4x\bin\ipopt.exe',max_evaluations=50)
alg = rbfopt.RbfoptAlgorithm(settings, bb)
val, x, itercount, evalcount, fast_evalcount = alg.optimize()

then I get the following error

  Iter  Cycle  Action             Objective value      Time      Gap
  ----  -----  ------             ---------------      ----      ---
     0      0  Initialization           -0.782797      0.00   100.00 *
     0      0  Initialization           69.095477      0.01   100.00  
     0      0  Initialization           20.000000      0.01   100.00  
     0      0  GlobalStep               -9.829600      0.02   100.00 *
     1      0  GlobalStep               -9.946732      0.04   100.00 *
     2      0  GlobalStep               -0.133622      0.05   100.00  
     3      0  GlobalStep               -8.304083      0.07   100.00  
     4      0  GlobalStep               -9.999968      0.09   100.00 *
Exception in thread Thread-8:
Traceback (most recent call last):
  File "c:\users\c565785\appdata\local\programs\python\python39\lib\threading.py", line 950, in _bootstrap_inner
    self.run()
  File "c:\users\c565785\appdata\local\programs\python\python39\lib\threading.py", line 888, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\c565785\appdata\local\programs\python\python39\lib\subprocess.py", line 1475, in _readerthread
    buffer.append(fh.read())
  File "c:\users\c565785\appdata\local\programs\python\python39\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 81: character maps to <undefined>
Traceback (most recent call last):

  File "C:\ProjTMS\MecosTools\mbtools4x\scripts\untitled0.py", line 10, in <module>
    val, x, itercount, evalcount, fast_evalcount = alg.optimize()

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\rbfopt\rbfopt_algorithm.py", line 803, in optimize
    self.optimize_serial(pause_after_iters)

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\rbfopt\rbfopt_algorithm.py", line 1060, in optimize_serial
    (adj, next_p, ind) = local_step(

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\rbfopt\rbfopt_algorithm.py", line 2446, in local_step
    min_rbf = aux.minimize_rbf(

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\rbfopt\rbfopt_aux_problems.py", line 297, in minimize_rbf
    if (not opt.available()):

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\pyomo\solvers\plugins\solvers\ASL.py", line 115, in available
    return self.version() is not None

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\pyomo\opt\base\solvers.py", line 421, in version
    self._version = self._get_version()

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\pyomo\solvers\plugins\solvers\ASL.py", line 96, in _get_version
    results = subprocess.run([solver_exec, "-v"],

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\subprocess.py", line 503, in run
    stdout, stderr = process.communicate(input, timeout=timeout)

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\subprocess.py", line 1130, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\subprocess.py", line 1525, in _communicate
    stdout = stdout[0]

IndexError: list index out of range

I'm using Python 3.9.6 by the way.

Support Python 3 / NumPy 1.12

Hello,

I have been playing with rbfopt using recent Python and NumPy versions, and have attached a patch with a couple of suggested changes that make the tests usable (though by default the tests do not seem to find the optima; I do not know if that is a different bug, or expected, or somehow the result of using Python 3...). I would like to implore you to support recent versions of the software in this ecosystem: Python 3 is a very nice upgrade over 2.7, and time isn't going backwards!

rbfopt-py3-patch.txt

All the best, and thanks for the great software.

MWE does not work

The MWE included in the README does not work:

fuzz@UbuFuzz64:/data/uniqueness-scripts$ python mwe.py
Traceback (most recent call last):
  File "mwe.py", line 7, in <module>
    np.array(['R', 'I', 'R']), obj_funct)
TypeError: Can't instantiate abstract class RbfoptUserBlackBox with abstract methods evaluate_noisy, has_evaluate_noisy

Is there a way to exstract the rbf surrogate model?

I found that we can save the state of the optimization. We there all the points are stored. Is it possible to extract the surrogate model from the stored optimization?

I think we could fit the used rbf function using the data from the stored data and rbf shape. Is there some code that we can easily use already available in the rbfopt library? Would be great to see what are the sub-optimal solutions we missed, and explore these using the surrogate model.

Silencing printed output

When I run an optimization, a bunch of stuff gets printed out, e.g.

...
Iter   0 Initialization : obj~        -0.889346 time    3.26 gap   100.00  
Iter   0 Initialization : obj~        -0.952863 time    3.26 gap   100.00  
Iter   0 Initialization : obj~        -0.964704 time    3.26 gap   100.00  
Iter   0 Initialization : obj~        -0.902433 time    3.26 gap   100.00  
Iter   0 Initialization : obj~        -0.973815 time    3.26 gap   100.00  
Iter   0 Initialization : obj~        -0.832574 time    3.26 gap   100.00  
...

Is there an option to silence this?

Constraint handling

Hi,

I have a MINLP problem with constraints, and I want to solve my problem with rbfopt.
However, I can't find information about constraint handling in the documentation.
Does this library support constraint handling?

Best,
Adhe

The complexity of the rbfopt algorithm

Hi, I am recently using the library for a combinatorial optimization problem. The objective function is deterministic but non-differentiable and discontinuous, so I treated him as a black box. The original problem is NP-hard, and here I want to know the computational complexity of the algorithm using the RBFOPT solver since I don't see a description of the algorithm complexity in the relevant papers.

Error: "retrieving immutable Param value..." when calling .optimize()

Hi,

there seems to be an Issue in rbfopt_degree_models.py. See the attachment for the error message
errorMsg.txt

In this particular case, I was able to fix this error by following:

https://groups.google.com/forum/#!topic/pyomo-forum/woioGPhpCFs

And changing line 869 in rbfopt_degree_models.py from:

            for i in model.K) + model.lambda_h[model.k])

to:

            for i in model.K) + model.lambda_h[model.k.value])

I'm using rbfopt v 4.0.3.

Best wishes,
Peter

Refactor RbfoptAlgorithm the way to make it possible to a library user drive the get_point-evaluate_point-update_model loop himself

I am writing a metaoptimizer (known as UniOpt) and there are some issues in this lib causing problems.

The most severe one is that the loop is not decoupled enough.
1 one cannot easily inject points. It can be worked around, but I don't think I should do it
2 the stuff prints all the initialization points, which can be thousands and millions. It is SLOW.

The solution can be is to allow a user to drive the loop himself,

algo = RbfoptAlgorithm(...)
for i in range(countOfIters):
  point = algo.predict()
  result = f(point)
  algo[point] = result # updates the model
return algo.best

though this won't solve the multiprocessing issue (though for my case it is already broken because pickle, cloudpickle and dill refuse to serialize something in my program).

The solution is to allow the optimizer iterate the loop, but it contents is user-provided via a function too, and do it incrementally:

def myFunc(algo_):
  point = algo_.predict()
  result = f(point)
  algo_[point] = result
algo = RbfoptAlgorithm(...)

for x, y in range(historicalPoints):
  algo[x] = y
algo.optimize(myFunc, count_of_iters)
... # inject points evaluated by other optimizers
algo.optimize(myFunc, count_of_iters)

Of course calling the funcs doesn;t mean anything should be printed.

Cannot import after pip install

After installing rbfopt with pip, I get the following error.

Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rbfopt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/civil/.local/lib/python3.6/site-packages/rbfopt/__init__.py", line 6, in <module>
    from .rbfopt_algorithm import RbfoptAlgorithm
  File "/home/civil/.local/lib/python3.6/site-packages/rbfopt/rbfopt_algorithm.py", line 27, in <module>
    import rbfopt.rbfopt_aux_problems as aux
  File "/home/civil/.local/lib/python3.6/site-packages/rbfopt/rbfopt_aux_problems.py", line 22, in <module>
    import pyomo.environ
ModuleNotFoundError: No module named 'pyomo'

Pyomo was already installed and rerunning the import yields:

>>> import rbfopt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/civil/.local/lib/python3.6/site-packages/rbfopt/__init__.py", line 6, in <module>
    from .rbfopt_algorithm import RbfoptAlgorithm
  File "/home/civil/.local/lib/python3.6/site-packages/rbfopt/rbfopt_algorithm.py", line 26, in <module>
    import rbfopt.rbfopt_utils as ru
AttributeError: module 'rbfopt' has no attribute 'rbfopt_utils'

These errors were directly one after the other in an interactive session.
I have verified that rbfot_utils.py is in ~/.local/lib/python3.6/site-packages/rbfopt

sample_size not being casted to integer

Hi, I have come across this problem while using the library.

Here, sample_size is not being casted to integer after round, resulting in sample_size being a float:

sample_size = max(2, round((len(var_lower) + 1) *
settings.init_sample_fraction))

This causes trouble down the line as np.random.permutationrequires an integer (it raises IndexError: tuple index out of range when it's a float):

int_lh = np.array([np.random.permutation(num_samples)
for i in range(n)], np.float_).T

Here is a minimal code example that triggers an error due to sample_size being float.

import rbfopt
import numpy as np

def obj_funct(x):
    return x[0]*x[1] - np.sum(x[2:])

types = np.array(['R', 'R', 'I', 'I'])
dim = len(types)
lB = np.array([0] * dim)
uB = np.array([10] * dim)

bb = rbfopt.RbfoptUserBlackBox(dim, lB, uB, types, obj_funct)
settings = rbfopt.RbfoptSettings(max_evaluations=50)
alg = rbfopt.RbfoptAlgorithm(settings, bb)
val, x, itercount, evalcount, fast_evalcount = alg.optimize()

I hope that this helps to replicate the error (I'm using Python 2.7 and rbfopt installed through pip).

Regards,
Javier.

Addition of kwargs to RbfoptUserBlackBox

The library is really useful, really appreciate the work.

It would be really helpful if it were possible to pass additional arguments to the black box function.
Correct me if I'm wrong, but it doesn't appear that this is currently possible.
I could add a kwargs parameter to the RbfoptUserBlackBox class init and propogate the values through.

Unexpected error: "IndexError: index 160 is out of bounds for axis 0 with size 158"

Dear RBFOpt team,

I am experiencing an unexpected problem with RBFOpt. After having prepared a fast or noisy function (expected to be 5 times faster than the accurate one), all my experiments seem to fail prematurely. Namely, I have launched 20 experiments and 4 of them have already failed with the following message:

Traceback (most recent call last):
File "PySlim1.py", line 20, in
val, x, itercount, evalcount, fast_evalcount = alg.optimize()
File "./venv/lib/python3.8/site-packages/rbfopt/rbfopt_algorithm.py", line 805, in optimize
self.optimize_parallel(pause_after_iters)
File "./venv/lib/python3.8/site-packages/rbfopt/rbfopt_algorithm.py", line 1384, in optimize_parallel
if (not np.array_equal(self.node_pos[ind], next_p)):
IndexError: index 145 is out of bounds for axis 0 with size 145

For the rest, the last part varies as follows:

  • IndexError: index 160 is out of bounds for axis 0 with size 158
  • IndexError: index 153 is out of bounds for axis 0 with size 146
  • IndexError: index 133 is out of bounds for axis 0 with size 109

And so on... Do you know the reason?

This is my code:

import rbfopt
import numpy as np
import NC_NormObjFunc
import NC_SlimNormObjFunc

def obj_funct(x):
        return (-1.0)*NC_NormObjFunc.NC_NormObjFunc(x)

def fast_funct(x):
        return np.array( [ (-1.0)*NC_SlimNormObjFunc.NC_SlimNormObjFunc(x), -0.10, 0.10 ] )

nvars = 13
bb = rbfopt.RbfoptUserBlackBox(nvars, np.array([0] * nvars), np.array([1] * nvars), np.array(['R'] * nvars), obj_funct, fast_funct)

settings = rbfopt.RbfoptSettings(num_cpus = 96, rand_seed = 3001, max_evaluations = 200, max_noisy_evaluations = 500, \
                        minlp_solver_path = './SOFTWARE/OPTIMIZERS/bonmin/bonmin', nlp_solver_path = './SOFTWARE/OPTIMIZERS/ipopt/ipopt')

alg = rbfopt.RbfoptAlgorithm(settings, bb)

val, x, itercount, evalcount, fast_evalcount = alg.optimize()

Finally, this is my former version that does not use a fast version of the objective function (and which has worked flawlessly):

import rbfopt
import numpy as np
import NC_NormObjFunc

def obj_funct(x):
        return (-1.0)*NC_NormObjFunc.NC_NormObjFunc(x)

nvars = 13
bb = rbfopt.RbfoptUserBlackBox(nvars, np.array([0] * nvars), np.array([1] * nvars), np.array(['R'] * nvars), obj_funct)

settings = rbfopt.RbfoptSettings(num_cpus = 96, rand_seed = 3001, max_evaluations = 300, \
                        minlp_solver_path = './SOFTWARE/OPTIMIZERS/bonmin/bonmin', nlp_solver_path = './SOFTWARE/OPTIMIZERS/ipopt/ipopt')

alg = rbfopt.RbfoptAlgorithm(settings, bb)

val, x, itercount, evalcount, fast_evalcount = alg.optimize()

What do you think the problem is? Is this a bug maybe or a mistake in my configuration?

Kind regards and thank you in advance.

Is there a way to skip an output value?

I've been playing around with the following scenario:

import rbfopt
import numpy as np
def obj_funct(x):
    sol=x[0]*x[1] - x[2]
    #print(type(sol))
    #print(sol)
    check = (np.greater(np.mod(sol,20),19))
    #print(check)
    
    if check:
        val= None
    else:
        val= sol
    #print(val)
    return val
    
    
bb = rbfopt.RbfoptUserBlackBox(3, np.array([0] * 3), np.array([10] * 3),np.array(['R', 'I', 'R']), obj_funct_noisy=obj_funct)

settings = rbfopt.RbfoptSettings(max_evaluations=50)
alg = rbfopt.RbfoptAlgorithm(settings, bb)
val, x, itercount, evalcount, fast_evalcount = alg.optimize()

At some points my model will spit out a None value. Is there a way to make sure the optimizer ignores these spots in the solution space when we obtain this None value? There seems to be an automated clipping flag, but I'm unsure how this works.

Problem using optimize_parallel (idle/freeze after a few seconds)

Hello,

I am using RBFopt to optimize a blackbox function with expensive evaluations. It also has a large response surface so i need a lot of evaluations. I have implemented the optimization using the regular 'optimize' function and it works without problems.

Now i am trying to use the 'parallel_optimization' function to speed up my optimization by using 4 cores.

I tried it like this :

bb = rbfopt.RbfoptUserBlackBox(33, lb, ub, np.array(types), obj_funct)

#all types are Integer

settings = rbfopt.RbfoptSettings(max_evaluations=1000, algorithm='MSRSM', do_infstep=False,
                 num_global_searches=15, global_search_method='genetic', rand_seed=seed, num_cpus=4,
                 parallel_wakeup_time=1)

alg = rbfopt.RbfoptAlgorithm(settings, bb)
val, x, itercount, evalcount, fast_evalcount = alg.optimize_parallel()

I also set : os.environ['OMP_NUM_THREADS'] = '1'

Starting the optimization i see the CPU usage spike for a few seconds, then it falls down to 3-5% and the programm seems to idle/freeze but i get no error message.

Any ideas what i do wrong ? Appreciate any help.

Add optional arguments to UserBlackBox function

The library is really useful, really appreciate the work.

It would be really helpful if it were possible to pass additional arguments to the black box function.
Correct me if I'm wrong, but it doesn't appear that this is currently possible.
I could add a kwargs parameter to the RbfoptUserBlackBox class init and propogate the values through.

Example to visualize the interpolant

I would like to visualize the surrogate model. But I can't figure out how to call evaluate_rbf or bulk_evaluate_rbf.

Is it possible to extend the following code example to plot the surrogate model after alg.optimize has finished?

import rbfopt
import numpy as np
import pandas as pd
import xarray.plot as xrp
import matplotlib.pyplot as plt
plt.ion()
import subprocess
import re


def fun(x):
    a = x[0]
    b = x[1]
    return np.sin(a) + np.cos(b)


t_clad = eval('np.linspace({})'.format('.15,.4,7'))
n_core = eval('np.linspace({})'.format('3.3,3.5,9'))

xas = []
for tc in t_clad:
    for nq in n_core:
        xas.append(dict(tc=tc, nq=nq, f=fun([tc, nq])))
df = pd.DataFrame(xas)
df2 = df.set_index(['tc', 'nq'])
ds = df2.to_xarray()
xrp.plot(ds.f)
xrp.contour(ds.f, colors='k')
plt.title('original merrit function')

bb = rbfopt.RbfoptUserBlackBox(2,
                               np.array([.15, 3.3]),
                               np.array([.4, 3.5]),
                               np.array(['R', 'R']), fun)

settings = rbfopt.RbfoptSettings(max_evaluations=50)
alg = rbfopt.RbfoptAlgorithm(settings, bb)
val, x, itercount, evalcount, fast_evalcount = alg.optimize()

import rbfopt.rbfopt_utils

rbfopt.rbfopt_utils.evaluate_rbf(settings, np.array([.14,3.3]), # what arguments to put here?

2018-08-27-141036_1020x522_scrot

RuntimeError: Solver bonmin not found

Hello,

I appreciate if you please help through the installation. I attached the images how I downloaded and added bonmin, however, it can't find the solver.

Thanks in advance
Yours sincerely
2
1

TypeError at end of iterations

First thank you for providing this package to solve these difficult optimization problems!
I get the following error message at the end (I think) of iterations:

Traceback (most recent call last):
  File "HTC_Steady.py", line 1733, in <module>
    objval, x, itercount, evalcount, fast_evalcount = alg.optimize()
  File "/home/chbrago/.conda/envs/cadquery/lib/python3.7/site-packages/rbfopt/rbfopt_algorithm.py", line 808, in optimize
    self.optimize_serial(pause_after_iters)
  File "/home/chbrago/.conda/envs/cadquery/lib/python3.7/site-packages/rbfopt/rbfopt_algorithm.py", line 862, in optimize_serial
    self.restart()
  File "/home/chbrago/.conda/envs/cadquery/lib/python3.7/site-packages/rbfopt/rbfopt_algorithm.py", line 1977, in restart
    self.update_log('Initialization', self.node_is_noisy[i], val, gap)
  File "/home/chbrago/.conda/envs/cadquery/lib/python3.7/site-packages/rbfopt/rbfopt_algorithm.py", line 537, in update_log
    ' {:8.2f}'.format(gap*100) +
TypeError: unsupported format string passed to numpy.ndarray.__format__

Any idea what may cause it?
I printed the values of the variables involved in this line:

gap =  [1.]
self.best_gap_shown =  inf
obj_value =  [74.12607681]
self.fbest =  [23.86276007]

Might it come from the inf?

No attribute RbfoptBlackBox

Solver quits with following error for the Minimal Working Example code in the README.

$ rbfopt_cl_interface.py mwe.py
    41      6  GlobalStep               -7.527563      7.54   100.00
    42      6  GlobalStep               -9.879860      7.57   100.00
    43      6  GlobalStep               -8.362085      7.61   100.00
    44      6  GlobalStep               -9.995397      7.65   100.00
    45      6  AdjLocalStep             -9.976929     10.08   100.00
    46      7  Discarded                              10.08
    47      7  GlobalStep                1.360124     10.21   100.00
    48      7  GlobalStep               -3.075917     10.25   100.00
    49      7  GlobalStep               -8.136047     10.29   100.00
Summary: iters  50 evals  50 noisy_evals   0 cycles   7 opt_time   10.29 tot_time   10.29 obj       -10.000000 gap 100.00
Traceback (most recent call last):
  File "/usr/local/bin/rbfopt_cl_interface.py", line 228, in <module>
    rbfopt_cl_interface(vars(args), bb.RbfoptBlackBox())
AttributeError: 'module' object has no attribute 'RbfoptBlackBox'

Here mwe.py is the following:

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()

I'm running this on Mac OSX and have installed ipopt and bonmin.

Tests never finish, stuck on "Solving hartman6 with random seed 512319876"

I have successfully compiled rbfopt for my GNU/Linux distro. When I attempt to run the tests they never finish, always getting stuck here:

Solving hartman6 with random seed 512319876
  Iter  Cycle  Action             Objective value      Time      Gap
  ----  -----  ------             ---------------      ----      ---
     0      0  Initialization           -0.001120      0.02    84.79  
     0      0  Initialization           -0.481835      0.02    84.79  
     0      0  Initialization           -0.129858      0.02    84.79  
     0      0  Initialization           -0.013445      0.02    84.79  
     0      0  Initialization           -0.505315      0.02    84.79 *
     0      0  RefinementStep           -0.130395      0.23    84.79

I tried the Minimal working example and it runs without issue so I'm not sure what the problem is.

Any help is greatly appreciated.

Problem with restarting pool while running optimize_parallel

Traceback (most recent call last):
  File "test_rbfopt.py", line 9, in <module>
    m.run_rbfopt()
  File "strat_rbfopt.py", line 116, in run_rbfopt
    val, x, itercount, evalcount, fast_evalcount = alg.optimize_parallel()
  File "python-env/lib64/python3.6/site-packages/rbfopt/rbfopt_algorithm.py", line 1185, in optimize_parallel
    self.restart(pool=pool)
  File "python-env/lib64/python3.6/site-packages/rbfopt/rbfopt_algorithm.py", line 1849, in restart
    self.update_log('Initialization', self.node_is_noisy[i], val, gap)
  File "python-env/lib64/python3.6/site-packages/rbfopt/rbfopt_algorithm.py", line 484, in update_log
    ' {:8.2f}'.format(gap*100) +
AttributeError: 'RbfoptAlgorithm' object has no attribute 'start_time'

Since self.start_time isn't getting set on optimise_parallel restarting pool throws this error. I think adding self.start_time = start_time at line 1135 corrects this problem

ImportError: Import by filename is not supported.

Traceback (most recent call last):
File "src/rbfopt_cl_interface.py", line 211, in
bb = importlib.import_module(args.black_box_module)
File "/Users/tuan.nguyen/anaconda/lib/python2.7/importlib/init.py", line 37, in import_module
__ import __(name)
ImportError: Import by filename is not supported.

I'm using Python 2.7.13 |Anaconda 4.4.0 (x86_64)|, is there something wrong with my setup?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.