Registry / ai-ml / cmaes
library0.13.1pypypi✓ verified 24d ago

cmaes is a lightweight Python library providing an implementation of the Covariance Matrix Adaptation Evolution Strategy (CMA-ES) for numerical optimization. It offers a simple "ask-and-tell" interface and has expanded to include various advanced CMA-ES variants such as CatCMA, CMAwM, and COMO-CatCMAwM, catering to mixed-variable and multi-objective optimization problems. The library is actively maintained, currently at version 0.13.0, with frequent updates introducing new algorithms and features.

pip install cmaes
INSTALL
IMPORT
SIG · CMAES
C
cmaes
ai-mlpythonv0.13.1
Install
3.6s avg
Import
246ms
Disk
90MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.13.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.248s · 89.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.6s · import 0.244s · 86MB
90MB installed
● package 90MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CMA
from cmaes import CMA
from cmaes.core import CMA
The primary CMA-ES optimizer is directly available from the top-level package.
CatCMAwM
from cmaes import CatCMAwM
For mixed-variable (continuous, integer, categorical) optimization problems.
COMOCatCMAwM
from cmaes import COMOCatCMAwM
For multi-objective mixed-variable optimization problems, typically 2 objectives.

This example demonstrates the basic "ask-and-tell" interface of the `cmaes` library using the standard `CMA` optimizer to minimize a simple quadratic function. The optimizer generates candidate solutions (`ask`), these are evaluated by the objective function, and then the results (`tell`) are used to update the search distribution for the next generation.

import numpy as np from cmaes import CMA def quadratic(x1, x2): # Objective function to minimize return (x1 - 3) ** 2 + (10 * (x2 + 2)) ** 2 if __name__ == "__main__": # Initialize CMA optimizer with an initial mean and standard deviation optimizer = CMA(mean=np.zeros(2), sigma=1.3) print("Starting CMA-ES optimization...") for generation in range(50): solutions = [] # Ask for new candidate solutions for _ in range(optimizer.population_size): x = optimizer.ask() value = quadratic(x[0], x[1]) solutions.append((x, value)) # Print the best value found in the current generation # (Note: CMA-ES updates distribution based on all solutions, not just the best) print(f"Generation #{generation+1}: Best value = {min(s[1] for s in solutions):.4f}") # Tell the optimizer the evaluated solutions and their values optimizer.tell(solutions) print(f"\nOptimization finished. Final mean of the search distribution: {optimizer.mean}")
Debug
Known issues
breakingPython 3.6 support was dropped in `v0.9.1`.
fix
Upgrade Python environment to 3.8 or later. The current recommended version is >=3.9.
affects: >=0.9.1
gotchaThe library offers numerous specialized optimizers (e.g., `CatCMAwM`, `COMOCatCMAwM`, `CMAwM`) for specific problem types beyond continuous, single-objective optimization.
fix
Carefully select and import the appropriate optimizer class (e.g., `from cmaes import CatCMAwM`) based on your problem's characteristics (e.g., mixed-variables, multi-objective).
affects: >=0.9.0
gotchaThe core `CMA` class is designed for continuous optimization problems. Using it directly for problems involving integer, categorical, or mixed variables, or for multi-objective optimization, may lead to suboptimal performance or incorrect results.
fix
For mixed-variable problems, consider `CatCMAwM`. For multi-objective problems, `COMOCatCMAwM` is available.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'cmaes'
The 'cmaes' package is not installed in your Python environment.
fix
Install the library using pip: `pip install cmaes`
ValueError: mean must be a 1-D array
The 'mean' parameter, representing the initial solution vector for the CMA-ES optimizer, must be provided as a one-dimensional NumPy array.
fix
Ensure 'mean' is a NumPy array with a single dimension, e.g., `mean=np.array([0.0, 0.0])` or `mean=np.zeros(dimension)`.
ValueError: sigma must be a scalar
The 'sigma' parameter, which defines the initial step-size for the CMA-ES optimizer, expects a single floating-point number.
fix
Provide 'sigma' as a scalar value, e.g., `sigma=0.5` instead of a list or array.
Upgrade
Version history
0.13.1latest on PyPI · released Aug 21, 2026
Audit
Dependencies
numpyrequiredCore numerical operations; sole direct dependency.
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources
cmaes — pip install cmaes · libregistry