turboswarm
Particle Swarm Optimization with a compute core in Rust and an API in Python. Focused on visualization, variant comparison and clear code. Supports real, integer, binary, mixed and grey/interval variables, constraints and multi-objective optimization, with first-class integrations for the scientific-Python stack.
Installation
pip install turboswarm
Optional integration extras: turboswarm[scipy], [sklearn], [optuna],
[pandas], [parallel], [agents], or [all].
From source (development), with maturin:
python -m venv .venv && source .venv/bin/activate
pip install maturin
maturin develop --release # compiles the Rust core and installs it
Usage
import turboswarm as pso
# Native benchmark (fast, in Rust, without the GIL)
r = pso.minimize("rastrigin", bounds=(-5.12, 5.12), dim=2, seed=42)
# Your own function in Python
r = pso.minimize(lambda x: sum(xi**2 for xi in x), bounds=(-5, 5), dim=3)
# Integer variables
r = pso.minimize(f, bounds=(-10, 10), dim=2, integer=True)
# Variant and topology by name
r = pso.minimize("ackley", bounds=(-32.768, 32.768), dim=2,
velocity="fips", topology="ring", seed=1)
print(r.best_position, r.best_value)
Parameters of minimize
| Parameter | Default | Description |
|---|---|---|
objective |
— | callable f(list)->float, or name of a native benchmark |
bounds |
— | list of (min, max) per dimension |
integer / binary |
False |
optimize over integers / {0,1} |
var_types |
None |
per-dimension "real"/"integer"/"binary" (mixed) |
n_particles |
30 |
swarm size |
max_iter |
100 |
iterations |
w, c1, c2 |
0.729, 1.494, 1.494 |
inertia, cognitive, social |
velocity |
"inertia" |
"inertia", "constriction", "fips" |
topology |
"global" |
"global", "ring", "vonneumann", "random" |
bounds_handling |
"clamp" |
"clamp", "reflect", "wrap", "reinit" |
seed |
None |
seed (fix it for reproducibility) |
record_history |
True |
store the trace for visualization |
v_max |
None |
clamp each velocity component to [-v_max, v_max] |
patience / tol |
0 / 0.0 |
stop after patience iters without >tol improvement |
max_evals / target / max_time |
None |
stop on evaluation / value / time budget |
constraints / penalty |
None / 1e6 |
inequality constraints g(x)<=0 via penalty |
callback |
None |
callback(iteration, best_value); return False to stop |
vectorized |
False |
objective receives the whole swarm as a NumPy array |
Native benchmarks: sphere, rastrigin, rosenbrock, ackley,
griewank, schwefel. Their metadata (recommended bound and optimum) are in
pso.benchmark_info(name) -> (bound, optimum).
FIPS performs better with local topologies (
"ring","vonneumann"). The"constriction"and"fips"variants derive their factor fromc1 + c2.
Result (PsoResult)
best_position— list of floats (whole-valued for integer/binary dims)best_value— floatconvergence— best value per iteration (convergence curve)history—history[iter][particle][dim](empty ifrecord_history=False)evaluations— number of objective evaluations performedstop_reason—"max_iterations","target","max_evaluations","stagnation","max_time"or"callback"
Multi-objective (MOPSO)
minimize_multi returns a ParetoFront (.positions, .objectives):
front = pso.minimize_multi(
lambda x: [sum(xi**2 for xi in x), sum((xi - 2) ** 2 for xi in x)],
bounds=[(-5, 5)] * 2, seed=42,
)
print(len(front)) # non-dominated solutions
Visualization
import matplotlib.pyplot as plt
pso.viz.plot_convergence(r); plt.show()
pso.viz.compare({"inertia": rA, "fips": rB}); plt.show()
pso.viz.plot_pareto(front); plt.show() # objective space of a Pareto front
anim = pso.viz.animate_swarm(r, pso.benchmarks.rastrigin, [(-5.12, 5.12)] * 2)
# in a notebook: from IPython.display import HTML; HTML(anim.to_jshtml())
# 3D landscape + animated 3D swarm:
pso.viz.plot_surface(pso.benchmarks.rastrigin, [(-5.12, 5.12)] * 2,
points=r.history[-1]); plt.show()
anim3d = pso.viz.animate_swarm_3d(r, pso.benchmarks.rastrigin, [(-5.12, 5.12)] * 2)
animate_swarm / animate_swarm_3d support 2D problems and require
record_history=True. For a multi-objective run, animate the Pareto front's
evolution with pso.viz.plotly_pareto_evolution(front).
Dashboard
An interactive dashboard (control panel + live swarm/convergence plots) ships in two interchangeable front-ends:
pip install "turboswarm[gui]" # Streamlit
turboswarm-gui # or: turboswarm-gui --backend gradio
pip install "turboswarm[gui-gradio]" # Gradio
turboswarm-gui-gradio
Integrations
Optional, lazily-imported helpers under turboswarm.integrations (install the
matching extra):
# SciPy drop-in (scipy.optimize.minimize signature)
from turboswarm.integrations import scipy as ts_scipy
res = ts_scipy.minimize(fun, bounds=[(-5, 5)] * 3) # -> OptimizeResult
# scikit-learn hyperparameter search (like GridSearchCV)
from turboswarm.integrations.sklearn import PSOSearchCV
# PSO as an Optuna sampler
from turboswarm.integrations.optuna import TurboswarmSampler
# Optuna/pandas/Joblib-Dask/LangChain-agent tool also available
See the Integrations guide.
Documentation
A navigable documentation portal (narrative guide + API reference) is built with MkDocs Material:
pip install -e ".[docs]"
./scripts/build-docs.sh --serve # http://127.0.0.1:8000
License
MIT.
Metadata
Release files for turboswarm 0.8.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 |
|---|---|---|---|---|
| turboswarm-0.8.0.tar.gz | 88.1 kB | Without provenance | Details for turboswarm-0.8.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| turboswarm-0.8.0-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details for turboswarm-0.8.0-cp39-abi3-win_amd64.whl |
| turboswarm-0.8.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details for turboswarm-0.8.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| turboswarm-0.8.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ ARM64 | Details for turboswarm-0.8.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
| turboswarm-0.8.0-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details for turboswarm-0.8.0-cp39-abi3-macosx_11_0_arm64.whl |
| turboswarm-0.8.0-cp39-abi3-macosx_10_12_x86_64.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64 | Details for turboswarm-0.8.0-cp39-abi3-macosx_10_12_x86_64.whl |
Total release size: 2.3 MB
Release files / turboswarm-0.8.0.tar.gz
| Download URL | turboswarm-0.8.0.tar.gz |
|---|---|
| Size | 88.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c3fbaa198729847d5b71226a526409fa86bfd786013aaacf97cf7dd242c2087f
|
|
BLAKE2b-256 checksum How to use checksums |
2177635ae2e20439226752120dc79a5975431173eb67e45dcd81b3d77aa2b285
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / turboswarm-0.8.0-cp39-abi3-win_amd64.whl
| Download URL | turboswarm-0.8.0-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 352.0 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e83114a809879017117af8fe5ab02f6b1ccc13aef8de3d67cabfe9af27b7d766
|
|
BLAKE2b-256 checksum How to use checksums |
38907ea9b316e797f399b171144ad223e952ba4d77615a733a8900403f4d602c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / turboswarm-0.8.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | turboswarm-0.8.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 497.4 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
8921ccc6832a648b71dcafe424b42daa6717dd6af647b9900cc884378a73d72d
|
|
BLAKE2b-256 checksum How to use checksums |
786099db55ae173f1a5c5a64e5027463266e0e778eea6d0421d33650caef855b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / turboswarm-0.8.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | turboswarm-0.8.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 486.5 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
853423e2be857eb4966938d85f0a171e5a5e0b76bf05e3fc0bb7dda8cb59e177
|
|
BLAKE2b-256 checksum How to use checksums |
4b0bb1c18420cc2a0ce1f14cf627c1f41ed71af420e9e8d4a569b05eba5b9804
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / turboswarm-0.8.0-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | turboswarm-0.8.0-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 440.4 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
aa36fe636d7d49c985de044d2649cd0ad7ee6f5636472e7c0fd6b92defb2fe55
|
|
BLAKE2b-256 checksum How to use checksums |
2355aa033bfebbf7c6ca6f61ff92493f70061edc4fb88131f682c570a8cc3c3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / turboswarm-0.8.0-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | turboswarm-0.8.0-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 440.8 kB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
32be87fb9c033edf4e9a5329f1525361372f291872ffd6272dfcaa64f55d2514
|
|
BLAKE2b-256 checksum How to use checksums |
d7e23a602b22da32eb25dc620e41e6c507da7029cf6a34e968d6b2a207410919
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for turboswarm 0.8.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.
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.