Profile
Back to NewsBack
GitHub Trending 1 min
Reader Mode
eggzec/pyswarm: Particle Swarm Optimization (PSO) for Python

eggzec/pyswarm: Particle Swarm Optimization (PSO) for Python

11 hours ago

!PySwarm

PySwarm

Particle Swarm Optimization (PSO) for Python

Tests</a> Documentation</a> Ruff</a>

codecov</a> Quality Gate Status</a> License: BSD-3</a>

PyPI Downloads</a> Python versions</a>

pyswarm is a gradient-free, evolutionary optimization library for Python that implements Particle Swarm Optimization (PSO) with built-in support for constraints. It is lightweight, easy to use, and suitable for a wide range of optimization problems where gradient information is unavailable or impractical to compute.

Quick example

from pyswarm import pso

def objective(x): x1, x2 = x return x14 - 2 x2 x12 + x22 + x12 - 2 * x1 + 5

lb = [-3, -1] ub = [2, 6]

result = pso(objective, lb, ub)

print("Optimal solution:", result.x) # → [1.0, 1.0] print("Function value:", result.fun) # → 4.0 print("Converged:", result.success) print("Reason:", result.message) print("Iterations:", result.nit) print("Evaluations:", result.nfev)

pso returns an OptimizeResult — a dict subclass with attribute access, compatible with scipy.optimize.OptimizeResult.

Installation

pip install pyswarm

Requires Python 3.10+ and NumPy. See the full installation guide for uv, poetry, and source builds.

Documentation

License

BSD-3-Clause — see LICENSE.

Chat with me