SwarmOpt
SwarmOpt is a library of swarm optimization algorithms implemented in Python.
Swarm intelligence leverages population-based search solutions to balance exploration and exploitation with respect to specified cost functions. The PSO lineage was sparked by Eberhart and Kennedy in their original paper on PSOs in 1995, and the intervening years have seen many variations spring from their central idea.
Installation
To install SwarmOpt, run this command in your terminal:
$ pip install swarmopt
Quick Start
from swarmopt import Swarm
from swarmopt.functions import sphere
# Basic usage
swarm = Swarm(
n_particles=30,
dims=2,
c1=2.0,
c2=2.0,
w=0.9,
epochs=100,
obj_func=sphere,
algo='global'
)
swarm.optimize()
print(f"Best cost: {swarm.best_cost}")
Reproducible runs
Pass seed to get the same result every time. SwarmOpt draws all randomness
from its own numpy.random.Generator and never touches NumPy's or Python's
global random state.
swarm = Swarm(n_particles=30, dims=2, c1=2.0, c2=2.0, w=0.9,
epochs=100, obj_func=sphere, seed=42)
Testing
Run the comprehensive test suite:
# Unit tests (what CI runs on every pull request)
python -m pytest
# Run all tests, including the slower integration scripts
python infra/run_tests.py
# Or run specific test categories
python infra/run_tests.py --unit # Fast unit tests only
python infra/run_tests.py --show # Show all available tests
python tests/index.py # Interactive test runner
Build, release, Docker, and dependency pin files live under infra/.
For local development from a clone:
pip install -e ".[dev]"
make -C infra init # optional extras (matplotlib, TDA examples, etc.)
Benchmarks
Stratified empirical comparisons (repeated trials, spread, ranks per function class) are in benchmarks/README.md. Run the driver from the repo root with python benchmarks/run_benchmarks.py (see that file for options and requirements).
Algorithms
Single-Objective
- Global Best PSO - Kennedy & Eberhart 1995
- Local Best PSO - Kennedy & Eberhart 1995
- Unified PSO - Parsopoulos & Vrahatis 2004
- Dynamic Multi-Swarm PSO - Liang & Suganthan 2005 (being reworked; not available in 0.3)
- Simulated Annealing PSO - Mu, Cao, & Wang 2009
- Cooperative PSO (CPSO) - Van den Bergh & Engelbrecht 2004
- Horse Herd Optimization Algorithm (HHOA) - Ibrahim et al. 2025
Multiobjective
- Multiobjective PSO - Handles multiple conflicting objectives simultaneously
Benchmark Functions
Single Objective
- Sphere Function
- Rosenbrock's Function
- Ackley's Function
- Griewank's Function
- Rastrigin's Function
- Weierstrass Function
Multiobjective
- ZDT1, ZDT2, ZDT3 - Zitzler-Deb-Thiele test functions
- DTLZ1, DTLZ2 - Deb-Thiele-Laumanns-Zitzler test functions
Implemented Features
Inertia Weight Variations
- Constant - Traditional fixed inertia weight
- Linear Decreasing - Classic linear decay (default)
- Chaotic - Chaotic inertia using logistic map
- Random - Random inertia between 0.5-1.0
- Adaptive - Adapts based on convergence progress
- Chaotic-Random - Combination of chaotic and random
- Exponential Decreasing - Exponential decay
- Sigmoid Decreasing - Sigmoid decay curve
Velocity Clamping Variations
- No Clamping - Particles can move freely
- Basic Clamping - Standard velocity bounds
- Adaptive Clamping - Decreases over time
- Exponential Clamping - Exponential decay
- Sigmoid Clamping - Sigmoid decay
- Random Clamping - Random bounds
- Chaotic Clamping - Chaotic bounds using logistic map
- Soft Clamping - Soft bounds using tanh
- Hybrid Clamping - Adaptive + exponential
- Convergence-Based - Based on optimization progress
Sample Applications
- Neural network number of layers and weight optimization
- Routing in communication networks
- Satellite repair helper-swarm standoff positioning
Security
See SECURITY.md to report a vulnerability privately or to verify a release's build provenance.
Citation
Siobhan K Cronin, SwarmOpt (2018), GitHub repository, https://github.com/SioKCronin/SwarmOpt
Metadata
Release files for swarmopt 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swarmopt-0.3.0.tar.gz | 61.2 kB | With provenance | Details for swarmopt-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swarmopt-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for swarmopt-0.3.0-py3-none-any.whl |
Total release size: 113.8 kB
Release files / swarmopt-0.3.0.tar.gz
| Download URL | swarmopt-0.3.0.tar.gz |
|---|---|
| Size | 61.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
162264038b60208a951c37b56d38b0476d6ee0e3f0ef42d555eb1883863559f9
|
|
BLAKE2b-256 checksum How to use checksums |
854bd0ac17d1e1f231d332c363ab4dfad21c17a15d751d109b226dfbd64c64a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 16, 2026.
Transparency logRelease files / swarmopt-0.3.0-py3-none-any.whl
| Download URL | swarmopt-0.3.0-py3-none-any.whl |
|---|---|
| Size | 52.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33f43bcdf8d358c61bdf4eab94ae606dc03e66765a0f6df86b04b6880838096c
|
|
BLAKE2b-256 checksum How to use checksums |
62f63fe2fee4c047c027637281f934b22c01c4f47ce2d4ba43ad6adf429b99cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 16, 2026.
Transparency logSecurity for swarmopt 0.3.0
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.
Attestation for swarmopt-0.3.0.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 16, 2026.
Transparency logA 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.