Metadata-Version: 2.5
Name: pygpumeta
Version: 0.1.0
Summary: GPU metaheuristics with warp-level selection operators for large-population optimisation
Project-URL: Repository, https://github.com/EmreCanKURAN/pygpumeta-dev
Project-URL: Issues, https://github.com/EmreCanKURAN/pygpumeta-dev/issues
Author: Emre Can Kuran, Umut Kuran, Ece Ecemiş
License: MIT
License-File: LICENSE
Keywords: cuda,gpu,metaheuristics,optimization,swarm intelligence
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: GPU :: NVIDIA CUDA
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: numpy>=1.23
Requires-Dist: pycuda>=2022.1
Provides-Extra: cupy12
Requires-Dist: cupy-cuda12x>=13; extra == 'cupy12'
Provides-Extra: cupy13
Requires-Dist: cupy-cuda13x>=14; extra == 'cupy13'
Provides-Extra: dev
Requires-Dist: build>=1.0; extra == 'dev'
Requires-Dist: hypothesis>=6.80; extra == 'dev'
Requires-Dist: mypy>=1.8; extra == 'dev'
Requires-Dist: pre-commit>=3.5; extra == 'dev'
Requires-Dist: pytest-cov>=4.1; extra == 'dev'
Requires-Dist: pytest>=7.4; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Provides-Extra: examples
Requires-Dist: scikit-learn>=1.3; extra == 'examples'
Requires-Dist: scipy>=1.10; extra == 'examples'
Provides-Extra: test
Requires-Dist: hypothesis>=6.80; extra == 'test'
Requires-Dist: pytest-cov>=4.1; extra == 'test'
Requires-Dist: pytest>=7.4; extra == 'test'
Description-Content-Type: text/markdown

# 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](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

```python
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:

```python
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)
```

## Documentation

- [Which objective mode should I use?](docs/objective_modes.md), with
  measured timings of one problem in each mode.
- [The selection operators](docs/selection.md): what they do and what they
  do not provide.
- [Adding an algorithm](docs/adding_an_algorithm.md).
- [Installation](docs/installation.md).
- [Examples](docs/examples.md) with their results: antenna array synthesis,
  solar cell parameter extraction, truss sizing, economic load dispatch,
  image thresholding, FIR filter design, SVM tuning and a custom algorithm.

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    # optional: the tests of the examples
```

```
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:

```bibtex
@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},
  note    = {In press}
}
```

## 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`.
