Skip to main content

blackbox: A Python module for parallel optimization of expensive black-box functions

What is this?

A minimalistic and easy-to-use Python module that efficiently searches for a global minimum of an expensive black-box function (e.g. optimal hyperparameters of simulation, neural network or anything that takes significant time to run). User needs to provide a function, a search domain (ranges of each input parameter) and a total number of function calls available. A code scales well on multicore CPUs and clusters: all function calls are divided into batches and each batch is evaluated in parallel.

A mathematical method behind the code is described in this arXiv note (there were few updates to the method recently): https://arxiv.org/pdf/1605.00998.pdf

Don't forget to cite this note if you are using method/code.

Demo

(a) - demo function (unknown to a method).

(b) - running a procedure using 15 evaluations.

(c) - running a procedure using 30 evaluations.

Installation

pip3 install black-box

Objective function

Simply needs to be wrapped into a Python function.

def fun(par):
    ...
    return output

par is a vector of input parameters (a Python list), output is a scalar value to be minimized.

Running the procedure

import black_box as bb


def fun(par):
    return par[0]**2 + par[1]**2  # dummy example


best_params = bb.search_min(f = fun,  # given function
                            domain = [  # ranges of each parameter
                                [-10., 10.],
                                [-10., 10.]
                                ],
                            budget = 40,  # total number of function calls available
                            batch = 4,  # number of calls that will be evaluated in parallel
                            resfile = 'output.csv')  # text file where results will be saved

Important:

  • All function calls are divided into batches and each batch is evaluated in parallel. Total number of batches is budget/batch. The value of batch should correspond to the number of available computational units.
  • An optional parameter executor = ... should be specified within bb.search_min() in case when custom parallel engine is used (ipyparallel, dask.distributed, pathos etc). executor should be an object that has a map method.

Intermediate results

In addition to search_min() returning list of optimal parameters, all trials are sorted by function value (best ones at the top) and saved in a text file with the following structure:

Parameter #1 Parameter #2 ... Parameter #n Function value
+1.6355e+01 -4.7364e+03 ... +6.4012e+00 +1.1937e-04
... ... ... ... ...

Author

Paul Knysh (paul.knysh@gmail.com)

Feel free to email me if you have any questions or comments.

Metadata

Release files for black-box 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for black-box 1.0.2
File Size Uploaded
black_box-1.0.2.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for black-box 1.0.2
File Interpreter ABI Platform
black_box-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / black_box-1.0.2.tar.gz

Download URL black_box-1.0.2.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4f5731ed685b89bae1fbc8c48f235c189fcc0d77facebe21ddc023411154ee9f
BLAKE2b-256 checksum
How to use checksums
0957dc2a232e349b8858e2254a7ff3f73e1475b033ead56ff89822e8fc09630f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.9

Release files / black_box-1.0.2-py3-none-any.whl

Download URL black_box-1.0.2-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ea513ec79391946a92eea4c0f20b076c022a8e820341163e445076e9fbfb675
BLAKE2b-256 checksum
How to use checksums
d9677ffa66f55ec9c0355ded65358f73e1658ed27465186ee536640789fad1bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.9

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page