Skip to main content

pypop7 (Pure-PYthon library of POPulation-based OPtimization)

Project description

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 PyPop7

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 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 interface to freely add them if they satisfy the following 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.


Design Philosophy

Given a large number of (black-box) optimizers which keep increasing almost every day, we need some (possibly) widely acceptable criteria to select from them, as presented below in details:

  • Respect for Beauty (Elegance)

    From the problem-solving perspective, we empirically prefer to choose the best optimizer for the black-box optimization problem at hand. For the new problem, however, the best optimizer is often unknown in advance (when without a prior knowledge). As a rule of thumb, we need to compare a (often small) set of available/well-known optimizers and finally choose the best one according to some predefined performance criteria. From the academic research perspective, however, we prefer so-called beautiful optimizers, though always keeping the No Free Lunch Theorems in mind. Typically, the beauty of one optimizer comes from the following attractive features: model novelty, competitive performance on at least one class of real-world problems, theoretical insights (e.g., convergence), clarity/simplicity for understanding and implementation, and repeatability.

    If you find any to meet the above standard, welcome to launch issues or pulls or discussions. We will consider it to be included in the pypop7 library as soon as possible, if possible. Note that any superficial imitation to well-established optimizers (i.e. Old Wine in a New Bottle) will be NOT considered here. Sometimes, several very complex optimizers could obtain the top rank on some competitions consisting of only artificially-constructed benchmark functions. However, these optimizers may become over-skilled on these artifacts. In our opinions, a good optimizer should be elegant and generalizable. If there is no persuasive real-world application reported for it, we will not consider any very complex optimizer in this library, in order to avoid the possible repeatability and overfitting issues.

  • Respect for Diversity

    Given the universality of black-box optimization (BBO) in science and engineering, different research communities have designed different optimizers/methods. The type and number of optimizers are continuing to increase as the more powerful optimizers are always desirable for new and more challenging applications. On the one hand, some of these methods may share more or less similarities. On the other hand, they may also show significant differences (w.r.t. motivations / objectives / implementations / communities / practitioners). Therefore, we hope to cover such a diversity from different research communities such as artificial intelligence (particularly machine learning evolutionary computation and zeroth-order optimization), mathematical optimization/programming (particularly global optimization), operations research / management science, automatic control, electronic engineering, open-source software, physics, chemistry, and others.

  • Respect for Originality

    For each optimizer included in PyPop7, we expect to give its original/representative reference (sometimes also including its good implementations/improvements). If you find some important references missed, please do NOT hesitate to contact us (and we will be happy to add it if necessary).

  • Respect for Repeatability

    For randomized search, properly controlling randomness is very crucial to repeat numerical experiments. Here we follow the Random Sampling suggestions from NumPy. In other worlds, you must explicitly set the random seed for each optimizer. For more discussions about repeatability from machine learning, evolutionary computation, and metaheuristics communities, refer to the following papers, to name a few:

    • Swan, J., Adriaensen, S., Brownlee, A.E., Hammond, K., Johnson, C.G., Kheiri, A., Krawiec, F., Merelo, J.J., Minku, L.L., Özcan, E., Pappa, G.L., et al., 2022. Metaheuristics “in the large”. European Journal of Operational Research, 297(2), pp.393-406.
    • López-Ibáñez, M., Branke, J. and Paquete, L., 2021. Reproducibility in evolutionary computation. ACM Transactions on Evolutionary Learning and Optimization, 1(4), pp.1-21.
    • Sonnenburg, S., Braun, M.L., Ong, C.S., Bengio, S., Bottou, L., Holmes, G., LeCunn, Y., Muller, K.R., Pereira, F., Rasmussen, C.E., Ratsch, G., et al., 2007. The need for open source software in machine learning. Journal of Machine Learning Research, 8, pp.2443-2466.

Computational Efficiency

For LSO, computational efficiency is an indispensable performance criterion of DFO 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 for PyPop7

This open-source Python library for black-box optimization is now supported by Shenzhen Fundamental Research Program under Grant No. JCYJ20200109141235597 (¥2,000,000 from 2021 to 2023), granted to Prof. Shi (CSE, SUSTech @ Shenzhen, China), and actively developed by three of his group members (e.g., Q.Q. Duan, C. Shao, G.C. Zhou).

Citation for PyPop7

If this open-source pure-Python library is used in your paper or 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.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypop7-0.0.78.tar.gz (325.0 kB view hashes)

Uploaded Source

Built Distribution

pypop7-0.0.78-py3-none-any.whl (479.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page