Skip to content

PyPop7: A Pure-Python Library for POPulation-based Black-Box Optimization (BBO), especially their *Large-Scale* versions/variants (evolutionary algorithms/swarm-based optimizers/pattern search/...). [https://pypop.rtfd.io/]

License

Notifications You must be signed in to change notification settings

Evolutionary-Intelligence/pypop

Repository files navigation

PyPop7: a Pure-PYthon open-source library of POPulation-based (evolution/swarm/pattern search) black-box OPtimization

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

PyPop7 is a Pure-PYthon open-source 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 a set of elegant algorithmic implementations (e.g., evolutionary algorithms, swarm-based optimizers, pattern search, etc.) for Black-Box Optimization (BBO), particularly population-based optimizers, in order to facilitate research repeatability, benchmarking of BBO, and especially real-world applications.

More specifically, for alleviating their curse of dimensionality, the 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 or educational purposes). For a list of public use cases of PyPop7, please refer to this online document for details. Although we have chosen GPL-3.0 license, anyone could use, modify, and improve this open-source Python library entirely freely for any (no matter open-source or closed-source) purpose.

How to Quickly Use

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

  1. Use pip to install pypop7 on the Python3-based virtual environment via venv or conda:
$ pip install pypop7
  1. Define the objective/cost/fitness function to be minimized for the optimization problem at hand,
import numpy as np  # for numerical computation, which is also the *computing engine* of pypop7

# the below example is Rosenbrock, one notorious test function from the optimization community
def rosenbrock(x):
    return 100.0*np.sum(np.square(x[1:] - np.square(x[:-1]))) + np.sum(np.square(x[:-1] - 1.0))

# define the fitness (cost) function to be minimized 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,)),  # lower search boundary
           'upper_boundary': 5.0*np.ones((ndim_problem,))}  # lower search boundary

Note that without loss of generality, only the minimization process is considered in this library, since maximization can be easily transferred to minimization by negating it.

  1. Run one or more black-box optimizers on this 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 may 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). Please refer to https://pypop.rtfd.io/ for the online documentation of this seemingly well-designed (self-boasted) pure-Python library (several praises from others).

A (Still Growing) Number of Black-Box Optimizers (BBO)

For new/missed BBO, we provide a unified API to freely add them if they satisfy our design philosophy (see development-guide for details). Note that Ant Colony Optimization (ACO) and Tabu Search (TS) are not covered in this open-source Python library, since they work well mainly in discrete/combinatorial search spaces in many cases. Furthermore, brute-force search (exhaustive/grid search) is also excluded here, since it works only for very low (typically << 10) dimensions. In the future version, we will consider adding Simultaneous Perturbation Stochastic Approximation (SPSA) into this open-source Python library.


  • lso: indicates the specific BBO version for LSO (dimension >> 1000).
  • c: indicates the competitive (or de facto) BBO version for small/medium-dimensional problems (though it may work well under certain LSO circumstances).
  • b: indicates the baseline BBO version mainly for theoretical/educational interest, owing to its simplicity (relative 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 try to provide several representative applications published on some top-tier journals and conferences (such as, Nature, Science, PNAS, PRL, JACS, JACM, PIEEE, JMLR, etc.), systematically reported in the paper list called DistributedEvolutionaryComputation openly accessible via GitHub.

Sponsor

From 2021 to 2023, this open-source pure-Python library was supported by Shenzhen Fundamental Research Program under Grant No. JCYJ20200109141235597 (¥2,000,000). Now Qiqi Duan is seeking new sponsors (e.g., from any enterprises).

Citation

If this open-source Python 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.

Star History

PyPop7-Star-Data