Skip to main content

pygpumeta logo

pygpumeta

GPU metaheuristics for continuous optimisation with large populations, built around selection operators that work at the level of GPU warps.

What it is for

Problems where a population of hundreds to tens of thousands of candidates is evaluated at once and the objective can be computed for the whole population on the GPU: fitting model parameters to data, synthesising antenna arrays and filters, sizing structures, dispatching generators, thresholding images. You describe the objective as a Python function on GPU arrays; you do not write CUDA code.

  • Eight algorithms: ABC, GWO, WOA, SCA, SSA and HHO as CUDA kernels, PSO and DE as array code.
  • Three warp-level selection operators (tournament, Ballot-Elite, migration), usable inside the algorithms or on their own.
  • Box bounds per variable, inequality and equality constraints, integer and categorical variables, minimisation or maximisation.
  • Reproducible runs for a given seed, step-wise control, callbacks and stopping rules.

What it is not for

  • Objectives that must run on the CPU. They are supported (mode="host"), but then only the bookkeeping runs on the GPU and there is no speedup to expect over a CPU optimizer.
  • Small populations. A GPU pays off when there is a lot to do in parallel.
  • Multi-objective optimisation, multiple GPUs and GPUs other than NVIDIA's are outside its scope.

Installation

An NVIDIA GPU, the CUDA toolkit, a C++ compiler and PyCUDA are required; CuPy is needed for objectives written as Python functions on GPU arrays. docs/installation.md has step-by-step instructions for Google Colab, Linux with conda-forge and Windows. Afterwards,

python -m pygpumeta.doctor

checks every component, says how to fix what is missing and finishes with a small optimisation run.

Quick start

import pygpumeta

def objective(x):                 # x: cupy.ndarray of shape (n, 30), on the GPU
    return ((x - 1.0) ** 2).sum(axis=1)

result = pygpumeta.minimize(
    objective, (-5.0, 5.0), dim=30, algorithm="gwo", pop_size=1024, max_iter=1000, seed=0,
)
print(result.fun, result.x, result.nfev, result.runtime, result.termination)

With constraints and mixed variables:

from pygpumeta import Constraint, minimize
from pygpumeta.space import Categorical, Integer, Real

result = minimize(
    objective,
    [Real(-1.0, 1.0), Integer(0, 10), Categorical(["a", "b", "c"])],
    constraints=[Constraint(lambda x: x[:, 0] + x[:, 1] - 5.0)],   # x0 + x1 <= 5
    constraint_handling="feasibility",
)
print(result.values, result.feasible)

Plotting

Plotting is optional and needs matplotlib:

pip install "pygpumeta[viz]"
import pygpumeta
from pygpumeta import viz

runs = [pygpumeta.minimize("rastrigin", dim=30, seed=s) for s in range(10)]
fig, ax = viz.plot_convergence({"GWO": runs}, log_scale=True)
fig.savefig("convergence.pdf")

A list of runs is drawn as the median with the range between the quartiles. viz.plot_comparison draws box plots of the final values and viz.plot_swarm_2d the contours of a two-dimensional objective with the population on it. Each function takes an optional ax, returns (fig, ax) and leaves showing or saving the figure to you.

Documentation

Every public function and class has a docstring; help(pygpumeta.minimize) is the reference for the main entry point.

Tests

Install the package together with its test dependencies (pytest, hypothesis, pytest-cov), which a plain pip install -e . leaves out:

pip install -e ".[test]"
pip install scipy scikit-learn matplotlib    # optional: tests of the examples and plots
python -m pytest -m "not gpu"     # CPU tier, anywhere
python -m pytest -m gpu           # GPU tier, on a machine with a CUDA device
python -m pytest                  # both; the GPU tier is skipped without CUDA

On a machine without the CUDA toolkit, PyCUDA cannot be built; use pip install --no-deps -e . followed by pip install numpy pytest hypothesis there. pip install -e ".[dev]" adds ruff, mypy and pre-commit.

notebooks/gpu_tests.ipynb runs the GPU tier on Google Colab.

Citation

If you use the library, please cite the paper that introduces the selection operators:

@article{kuran2026warpselection,
  author  = {Kuran, Emre Can and Kuran, Umut and Ecemi{\c{s}}, Ece},
  title   = {Register-Level Selection via Warp Primitives: Shuffle-Based Tournament and
             Ballot-Elite Mechanisms for {GPU}-Accelerated Metaheuristics},
  journal = {Swarm and Evolutionary Computation},
  year    = {2026},
  doi     = {10.1016/j.swevo.2026.102633}
}

Acknowledgement

This library extends the code of the paper into a general-purpose package. It was developed with the assistance of Claude Code (Anthropic); the authors have written the original code (paper), reviewed the design, ran the GPU test suite and are responsible for the released code.

License

MIT, see LICENSE.

Metadata

Release files for pygpumeta 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygpumeta 0.2.1
File Size Uploaded Provenance Actions
pygpumeta-0.2.1.tar.gz 123.1 kB With provenance Details for pygpumeta-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pygpumeta 0.2.1
File Interpreter ABI Platform Actions
pygpumeta-0.2.1-py3-none-any.whl Python 3 none any Details for pygpumeta-0.2.1-py3-none-any.whl

Total release size: 207.0 kB

Release files / pygpumeta-0.2.1.tar.gz

Download URL pygpumeta-0.2.1.tar.gz
Size 123.1 kB
Tags Source
SHA-256 checksum
How to use checksums
df39094e1cdfffc2d5c18f8d6caf214be93763087605f33185ebbe15d4d9e0b8
BLAKE2b-256 checksum
How to use checksums
0bf720b3f28964ceed38193ce402d6b2e94e0994e549672717c5560c30130955
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / pygpumeta-0.2.1-py3-none-any.whl

Download URL pygpumeta-0.2.1-py3-none-any.whl
Size 83.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
268e27e5fcd03f1729a3415af9409379368c96ec4f418c88e053b5527dffe26e
BLAKE2b-256 checksum
How to use checksums
984a682e3bcc3ce99cb99cca6fde12675058e8f72c29c73209c04541cdd804d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for pygpumeta 0.2.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pygpumeta-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page