cmaes : A Simple yet Practical Python Library for CMA-ES

Masahiro Nomura, Masashi ShibataarXiv 2024 · DOI

Abstract

The cmaes library is a lightweight, high-readability Python implementation of the Covariance Matrix Adaptation Evolution Strategy (CMA-ES). It bridges the gap between educational simplicity and production-grade power by integrating cutting-edge research—such as automatic learning rate adaptation and mixed-variable optimization—into a user-friendly "ask-and-tell" interface. This paper details its design philosophy, core features, and performance on standard benchmarks.

Introduction

Black-box optimization is a cornerstone of modern engineering, essential for finding optimal parameters in systems where internal mechanics are too complex or noisy to differentiate. Applications range from hyperparameter tuning in neural networks to chemical reaction design.

While the CMA-ES algorithm is a gold standard for these problems, practitioners often face a dilemma: use the powerful but highly complex pycma library, or use simpler implementations that lack modern features. The cmaes library provides a "middle way"—a pure Python implementation depending only on NumPy that remains easy to read and integrate while supporting advanced optimization techniques.

Methods

The library implements the standard CMA-ES algorithm, which samples candidate solutions from a multivariate Gaussian distribution. As shown in the figure below, the distribution adapts its mean and covariance over successive generations to converge on the global optimum.

The evolution of the search distribution across generations in CMA-ES.

Beyond the standard algorithm, cmaes extends the framework with four key modern techniques:

  1. LRA-CMA (Learning Rate Adaptation): Automatically adjusts the learning rate instead of requiring manual population size increases, maximizing hardware utilization in parallel environments.
  2. WS-CMA (Warm Starting): Enables "transfer learning" for optimization. By using results from similar past problems, the library can estimate a promising starting distribution using Gaussian Mixture Models (GMM), as illustrated below.
  3. CatCMAwM (Mixed-Variable Optimization): A unified framework for handling continuous, integer, and categorical variables simultaneously without the stagnation issues typical of simple rounding.
  4. COMO-CatCMAwM: An extension for multi-objective optimization (e.g., maximizing accuracy while minimizing latency) using the "Sofomore" framework.
Visualization of warm starting (WS-CMA) using GMMs to identify promising search regions.

From a software engineering perspective, the library utilizes an ask-and-tell interface. This decouples the optimizer from the objective function, facilitating custom restart strategies and distributed evaluations.

Evaluation and Results

The library was validated using standard optimization benchmark functions, including the 40-D Rastrigin function (a highly multimodal "minefield"), the Noisy Sphere function, and custom benchmarks for mixed-variable and multi-objective optimization.

Key Findings

  • Robustness: LRA-CMA successfully identifies the global optimum on the 40-D Rastrigin function, whereas vanilla CMA-ES consistently becomes trapped in local optima.
  • Efficiency: The library maintains a significantly smaller serialization (pickle) size compared to pycma. This is critical for distributed hyperparameter optimization frameworks like Optuna, where optimizer states are frequently moved across networks.
  • Practicality: The authors argue that adjusting the learning rate ($\eta$) is often more practical than adjusting population size ($\lambda$), as the latter is frequently constrained by available hardware workers.

Discussion and Future Work

By maintaining a "pure Python" and NumPy-dependent codebase, cmaes has become a vital educational and reference resource, adopted by major libraries like evojax and evosax. It currently serves as the default CMA-ES backend for Optuna and Katib.

Despite its strengths, some advanced features found in pycma—such as non-linear constraints and surrogate-assisted methods—are not yet supported. Future development will focus on extending multi-objective capabilities beyond bi-objective scenarios to "many-objective" optimization tasks.

Summary updated

BibTeX
@misc{nomura2024cmaes,
  author = {Masahiro Nomura and Masashi Shibata},
  title = {{cmaes : A Simple yet Practical Python Library for CMA-ES}},
  year = {2024},
  eprint = {2402.01373},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.01373},
}
Figure