fastcma
Hyper-optimized CMA-ES in Rust with a first-class Python experience. SIMD, rayon, deterministic seeds, vectorized objectives, restarts, constraints, and a Rich-powered TUI — all while keeping the Rust core available for native use. Published to PyPI as fast-cmaes (module name: fastcma).
Table of contents
- Why CMA-ES
- Architecture (Mermaid)
- Features
- Installation (Python)
- Quickstart (Python)
- Vectorized & Constraints
- Rust usage
- Demos & TUI
- Baselines & Benchmarks
- Performance choices
- Feature flags
- Testing
- Contributing
- License
Why CMA-ES
- Derivative-free, handles noisy/non-convex landscapes.
- Adapts step size (sigma) and covariance to follow curved valleys.
- Parallel-friendly: candidate evaluations are embarrassingly parallel.
Architecture (Mermaid)
flowchart LR
subgraph Python API
A[fmin / fmin_vec / CMAES class]
B[Constraints & restarts]
C[Naive baseline (pure Python)]
end
subgraph Rust Core (src/lib.rs)
D[Ask/Tell loop]
E[Covariance update (full/diag)]
F[Sigma adaptation]
G[SIMD dot + rayon fitness]
H[Deterministic seeds]
end
subgraph Tests & Demos
I[Benchmarks: sphere, rosenbrock, rastrigin, ackley, schwefel, griewank]
J[Rich TUI demo]
K[Python smoke]
end
A --> D
A --> B
B --> D
D --> E --> F --> D
D --> G
D --> H
I --> D
J --> A
K --> A
C --> A
Features
- Python-first API:
fmin,fmin_vec, constrained, restart modes, and aCMAESclass. - SIMD + rayon: portable_simd accelerates dot products; rayon parallelizes fitness calls.
- Full/Diagonal covariance: switch via
covariance_mode. - Deterministic seeds:
new_with_seed+test_utilsfor reproducible runs and benchmarks. - Pure-Python baseline:
fastcma.cma_esfor speed comparisons. - Rich TUI: live, colorful CMA-ES progress view.
- Cross-platform wheels: CI builds for Linux/macOS/Windows, Python 3.12–3.14.
Installation (Python)
Fastest path (PyPI):
python -m pip install fast-cmaes # installs module `fastcma`
Build locally (needed only if hacking on Rust):
python -m pip install maturin
maturin develop --release
# Optional: NumPy fast paths
maturin develop --release --features numpy_support
# Optional: LAPACK eigen backend (requires a Fortran toolchain)
maturin develop --release --features eigen_lapack
# Demo extras (Rich TUI)
python -m pip install .[demo]
One-liner setup + Rich TUI demo (auto-installs nightly Rust, uv, venv, builds, runs):
./scripts/setup_and_demo.sh
Quickstart (Python)
from fastcma import fmin
from fastcma_baseline import benchmark_sphere
def sphere(x):
return sum(v*v for v in x)
xmin, es = fmin(sphere, [0.5, -0.2, 0.8], sigma=0.3, maxfevals=4000, ftarget=1e-12)
print("xmin", xmin)
# Pure-Python baseline
print(benchmark_sphere(dim=20, iters=120))
Vectorized & Constraints
from fastcma import fmin_vec
def sphere_vec(X):
return [sum(v*v for v in x) for x in X]
xmin, _ = fmin_vec(sphere_vec, [0.4, -0.1, 0.3], sigma=0.25, maxfevals=3000)
Constrained run:
from fastcma import fmin_constrained
def sphere(x): return sum(v*v for v in x)
constraints = {"lower_bounds": [-1,-1,-1], "upper_bounds": [1,1,1]}
xmin, _ = fmin_constrained(sphere, [0.5,0.5,0.5], 0.3, constraints)
Rust usage (library)
use fastcma::{optimize_rust, CovarianceModeKind};
let (xmin, _state) = optimize_rust(
vec![0.5, -0.2, 0.8],
0.3,
None,
Some(4000),
Some(1e-12),
CovarianceModeKind::Full,
|x| x.iter().map(|v| v*v).sum()
);
println!("xmin = {:?}", xmin);
Demos & visualization
examples/python_quickstart.py– minimal sphere + vectorized demo.examples/python_benchmarks.py– Rust vs naive Python on sphere; naive on Rastrigin.examples/rich_tui_demo.py– Rich TUI streaming sigma/fbest/evals while minimizing Rosenbrock.
One-shot setup + demo runner:
./scripts/setup_and_demo.sh
What it does: ensures nightly Rust, creates a uv venv on Python 3.13, installs maturin + demo extras, builds the extension, and launches the Rich TUI.
Run the TUI with uv + Python 3.13:
uv venv --python 3.13
uv pip install .[demo]
uv run python examples/rich_tui_demo.py
Baselines & benchmarks
- Pure Python baseline:
fastcma_baseline.cma_es,fastcma_baseline.benchmark_sphere(seepython/fastcma_baseline/naive_cma.py). - Integration benchmarks (fixed seeds): sphere, Rosenbrock, Rastrigin, Ackley, Schwefel, Griewank in
tests/benchmarks.rs. - Rich TUI demo for live insight.
Performance considerations
- SIMD for dot products; rayon for parallel ask/tell evaluations.
- Lazy eigensystem updates to reduce eigen decompositions.
- Diagonal covariance option for higher dimensions / speed.
- Determinism: seeded RNG to make tests non-flaky and benchmarks comparable.
- Restart helper (
test_utils::run_with_restarts) to escape local minima without huge budgets.
Feature flags
numpy_support: NumPy array support in vectorized objectives.eigen_lapack: LAPACK eigen backend.test_utils: expose deterministic helpers externally.demo: pulls inrichfor the TUI.
Testing
- Rust:
cargo test - Python smoke:
pytest tests/python_smoke.py - CI: GitHub Actions builds wheels on nightly Rust; runs smoke tests; can publish to PyPI when
PYPI_API_TOKENis set.
Contributing
- Nightly Rust required (see
rust-toolchain.toml). - Please include failing cases or perf comparisons in issues/PRs.
License
MIT (c) 2025 Jeffrey Emanuel
Metadata
Release files for fast-cmaes 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 2.3 MB
Release files / fast_cmaes-0.1.4-cp314-cp314-win_amd64.whl
| Download URL | fast_cmaes-0.1.4-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 199.4 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
b92c32bb4ecabee82cd46211261884d5ba1be8ee3036f09a15b39caa017e5ffe
|
|
BLAKE2b-256 checksum How to use checksums |
df138daf3d07aa646b48e73bba51f0b2230ffa01609235cc8ed2a6e347899559
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / fast_cmaes-0.1.4-cp314-cp314-manylinux_2_34_x86_64.whl
| Download URL | fast_cmaes-0.1.4-cp314-cp314-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 303.7 kB |
| Tags | CPython 3.14 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
c6b4dfe29b15b8d751171348072caf56a037cf041455ece1c59475de4e617675
|
|
BLAKE2b-256 checksum How to use checksums |
5df0b3bc91adfdcc0cb319cc932b00ae834f8733f98b1f4ac26bb92c10742ab5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / fast_cmaes-0.1.4-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | fast_cmaes-0.1.4-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 258.1 kB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5d07b65903c174ca89a1e6251630c378ce046345e37d89ae4a08fecf73cf7198
|
|
BLAKE2b-256 checksum How to use checksums |
6e3a6c31dbbf07886e9ace06ac9fc1a8e2f5ca0d5a9ac4361f59bb6a0f29be99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / fast_cmaes-0.1.4-cp313-cp313-win_amd64.whl
| Download URL | fast_cmaes-0.1.4-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 199.4 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
8e44f00723d364463aa09a2e3cf0709f0a645846e57bb92623c8e06bc1fb9e5b
|
|
BLAKE2b-256 checksum How to use checksums |
0a62526a294e420a66c00823cf08dce104431a3de4d11f4a74caa021e2a292dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / fast_cmaes-0.1.4-cp313-cp313-manylinux_2_34_x86_64.whl
| Download URL | fast_cmaes-0.1.4-cp313-cp313-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 303.7 kB |
| Tags | CPython 3.13 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
5ffa22caa57d96a7cbc92311f8d287ca25bd79449d7dd9b80221f38accf8b45f
|
|
BLAKE2b-256 checksum How to use checksums |
15a1d31a3b04150911bac588ac708d3a3a0d77285374fddbaa029f9c89580348
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / fast_cmaes-0.1.4-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | fast_cmaes-0.1.4-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 258.1 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e4520825d65da74821e847d76e17c8a9d343034d53543afe91252f1c50383dd5
|
|
BLAKE2b-256 checksum How to use checksums |
b48b485246cf16393d70b626ddb59f849b3ae005dfed6f0683eb2bec563072fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / fast_cmaes-0.1.4-cp312-cp312-win_amd64.whl
| Download URL | fast_cmaes-0.1.4-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 199.6 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
8ad2f3a78731a04b797d4a4652d604092787e28e9b1d871abb19204bf939b671
|
|
BLAKE2b-256 checksum How to use checksums |
83f633cb181e6397b211038104dbb55387a9deb3ea038fa13dafd6a68c0704c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / fast_cmaes-0.1.4-cp312-cp312-manylinux_2_34_x86_64.whl
| Download URL | fast_cmaes-0.1.4-cp312-cp312-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 303.8 kB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
1cc3d0f708ecbd9011d22847bc03525b8fdd415ddc3806da8380694251a62dce
|
|
BLAKE2b-256 checksum How to use checksums |
29fbc8b3aeee72cdd7cf691eeda944336a66b5d669575aafc3aa96278bee3980
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / fast_cmaes-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | fast_cmaes-0.1.4-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 258.1 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4d2969eca9052f39cd57bd3d39ee3082521bd33a8ec810e4b264d973cddcc824
|
|
BLAKE2b-256 checksum How to use checksums |
939978259a04733c0267bb574c7adf879cbcd31fb548453dfb241e69dd0b9b46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Security for fast-cmaes 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.