Skip to content

Evolutionary-Intelligence/pypop

Repository files navigation

PyPop7 (a Pure-PYthon library of POPulation-based black-box OPtimization)

GNU General Public License v3.0 PyPI for pypop7 Documentation Status Downloads Python arxiv

PyPop7 is a Pure-PYthon library of POPulation-based OPtimization for single-objective, real-parameter, black-box problems (currently actively maintained). Its goal is to provide a unified interface and elegant implementations for Black-Box Optimization (BBO), particularly population-based optimizers, in order to facilitate research repeatability, benchmarking of BBO, and real-world applications.

drawing

More specifically, for alleviating their curse of dimensionality, the primary focus of PyPop7 is to cover their State Of The Art for Large-Scale Optimization (LSO), though many of their small/medium-scaled versions and variants are also included here (mainly for theoretical or benchmarking purposes).

How to Quickly Use

The following three steps are enough to utilize the optimization power of this library PyPop7:

  1. Use pip to install pypop7 on the Python3-based virtual environment via venv or conda (a strong suggestion):
$ pip install pypop7

For simplicity, all required library dependencies (except special cases) are automatically installed according to setup.cfg.

  1. Define the objective/cost function (called fitness function in this library) for the optimization problem at hand,

  2. Run one or more black-box optimizers on this optimization problem:

import numpy as np  # for numerical computation, which is also the computing engine of pypop7

# 2. Define your own objective/cost function for the optimization problem at hand:
#   the below example is Rosenbrock, the notorious test function from the optimization community
def rosenbrock(x):
    return 100.0*np.sum(np.power(x[1:] - np.power(x[:-1], 2), 2)) + np.sum(np.power(x[:-1] - 1, 2))

# define the fitness (cost) function and also its settings
ndim_problem = 1000
problem = {'fitness_function': rosenbrock,  # cost function
           'ndim_problem': ndim_problem,  # dimension
           'lower_boundary': -5.0*np.ones((ndim_problem,)),  # search boundary
           'upper_boundary': 5.0*np.ones((ndim_problem,))}

# 3. Run one or more black-box optimizers on the given optimization problem:
#   here we choose LM-MA-ES owing to its low complexity and metric-learning ability for LSO
#   https://pypop.readthedocs.io/en/latest/es/lmmaes.html
from pypop7.optimizers.es.lmmaes import LMMAES
# define all the necessary algorithm options (which differ among different optimizers)
options = {'fitness_threshold': 1e-10,  # terminate when the best-so-far fitness is lower than this threshold
           'max_runtime': 3600,  # 1 hours (terminate when the actual runtime exceeds it)
           'seed_rng': 0,  # seed of random number generation (which must be explicitly set for repeatability)
           'x': 4.0*np.ones((ndim_problem,)),  # initial mean of search (mutation/sampling) distribution
           'sigma': 3.0,  # initial global step-size of search distribution (not necessarily optimal)
           'verbose': 500}
lmmaes = LMMAES(problem, options)  # initialize the optimizer
results = lmmaes.optimize()  # run its (time-consuming) search process
print(results)

Note that for PyPop7, the number 7 is added just because pypop has been registered by other in PyPI. The icon butterfly for PyPop7 is used to respect to the book (a complete variorum edition) of Fisher, "the greatest of Darwin's successors": The Genetical Theory of Natural Selection (where four butterflies were drawn in its cover), which inspired the proposal of Genetic Algorithms (GA).

For a (growing) list of public use cases of PyPop7, see this online document for more details. For new/missed black-box optimizers, we provide a unified API to freely add them if they satisfy our design philosophy (see development-guide for details).

A Large Number of Black-Box Optimizers (BBO)

drawing

Note that Ant Colony Optimization (ACO) and Tabu Search (TS) are not covered in this open-source library, since they work mainly in discrete/combinatorial search spaces. Furthermore, brute-force search (exhaustive/grid search) is also excluded here, since it works only for very low (typically < 10) dimensions. In the near future version, we will consider adding Simultaneous Perturbation Stochastic Approximation (SPSA) into this open-source library.


  • large--scale--optimization: indicates the specific BBO version for LSO (dimension >= 1000).
  • competitor: indicates the competitive (or de facto) BBO version for small/medium-dimensional problems (though it may work well under certain LSO circumstances).
  • baseline: indicates the baseline BBO version mainly for theoretical interest, owing to its simplicity (relatively ease to mathematical analysis).

Note that this classification based on only the dimension of objective function is just a rough estimation for algorithm selection. In practice, perhaps the simplest way to algorithm selection is trial-and-error or to try more advanced Automated Algorithm Selection techniques.


Computational Efficiency

For LSO, computational efficiency is an indispensable performance criterion of BBO/DFO/ZOO in the post-Moore era. To obtain high-performance computation as much as possible, NumPy is heavily used in this library as the base of numerical computation along with SciPy. Sometimes Numba is also utilized, in order to further accelerate the wall-clock time.

References

For each algorithm family, we provide several representative applications published on some top-tier journals and conferences (such as, Nature, Science, PNAS, PRL, JACS, PIEEE, etc.).

Sponsor

From 2021 to 2023, this open-source Python library was supported by Shenzhen Fundamental Research Program under Grant No. JCYJ20200109141235597 (¥2,000,000).

Citation

If this open-source library is used in your paper/project, it is highly welcomed to cite the following arXiv preprint paper: Duan, Q., Zhou, G., Shao, C., Wang, Z., Feng, M., Yang, Y., Zhao, Q. and Shi, Y., 2022. PyPop7: A pure-Python library for population-based black-box optimization. arXiv preprint arXiv:2212.05652.