ParGA 0.2.0: Reproducible, Parallel, Installable
ParGA started as a MATLAB parallel genetic algorithm framework I wrote a long time ago and revived in Rust. It has been a working library for a while and has never been installable. 0.2.0 fixes that, and it is a good moment to say what the thing actually does now.
What it is
A genetic algorithm library with a Rust core and Python bindings through PyO3, packaged with maturin. The Python side is the interface you use; the Rust side runs the population, and with rayon it runs the islands genuinely in parallel.
from parga import minimize, MigrationTopology
result = minimize(
objective,
genome_length=16,
bounds=(0.0, 1.0),
population_size=800,
generations=250,
islands=8,
migration_topology=MigrationTopology.fully_connected(),
seed=42,
)
The facade picks an execution strategy for you and tells you which one it used. A fast objective runs entirely in Rust; an expensive Python objective gets a process pool, because handing a genome to another process costs more than a millisecond of work is worth.
What is in 0.2.0
Seeded runs reproduce exactly, including in parallel. One RNG threaded through initialization, selection, crossover, mutation, restarts, immigrants and local search, with each island deriving its seed structurally from the master rather than sharing a generator. Same seed, same answer to twelve decimal places on the genome, at one island or eight. That is an architectural property rather than a feature, and it is the thing every benchmark in this series depends on.
Free-threaded Python is a supported target. CI builds and tests against 3.13t and asserts the interpreter really is free-threaded rather than silently falling back to the GIL build. That is where a rayon-backed extension stops fighting the interpreter for parallelism.
The operators do what their papers say. Deb’s polynomial mutation uses the distance to the bound it is moving toward on both branches, PMX crossover no longer inverts its mapping, stochastic universal sampling walks at the correct stride, non-uniform mutation anneals as specified, and real-valued offspring are clamped to their bounds as an invariant.
Configurations are validated before execution, and the facade warns when a chosen strategy cannot honour an option rather than accepting and ignoring it. An accepted-and-ignored setting is worse than a rejected one, because it looks like it worked.
Errors surface. An exception in your Python fitness function propagates instead of being scored as negative infinity, which is the difference between a typo and a very hard optimization problem.
Migration topology is selectable from the facade, which matters more than it sounds: on the standard multimodal benchmarks a fully connected topology reaches a better optimum than the ring default, and on Lennard-Jones clusters islands beat a single population outright.
Plus an installable viz extra, so matplotlib stays out of the core install.
What 115 iterations of tuning found
The repository has an autoresearch/ directory: a loop where an agent reads the current state, forms a hypothesis about improving the framework, implements it, rebuilds, runs a composite benchmark, and keeps the change only if the score improved. Every iteration is logged.
115 iterations, four 30-dimensional benchmarks, one composite score combining accuracy, speed and memory:
composite (lower is better)
first observed 1.1753
best observed -4.2090 at iteration 68
Per benchmark, the mean error at the first iteration against the best run:
| benchmark | first | best |
|---|---|---|
| Sphere-30D | 0.00022 | 0.00000 |
| Rastrigin-30D | 0.02760 | 0.00000 |
| Ackley-30D | 0.07236 | 0.00000 |
| Rosenbrock-30D | 61.607 | 43.392 |
Three of the four driven to zero error in thirty dimensions. Rosenbrock, whose optimum sits in a long curved valley that is exactly what a GA is worst at, improved by 30% and remains the hard one.
The number I find most instructive is a different one:
8 of 114 iterations improved the running best. The other 106 were reverted.
A 7% hit rate is what directed search actually looks like when you keep an honest log of it. The published story of any optimization effort is the eight, and the work is the hundred and six. It is worth knowing that ratio before starting one, and worth keeping the log so you can compute it afterwards.
One caveat on those numbers: the composite is measured from stochastic runs, so it carries noise, and the final iteration scores worse than the best observed one rather than equal to it. The improvements above are real and the exact figures should be read as measurements rather than constants.
Installing
pip install parga
Rust users can take the crate directly:
[dependencies]
parga = "0.2"
The examples directory has the full set: Lennard-Jones clusters, HP lattice protein folding, solid rocket motor grain design, and multi-component alloy composition, each of which has its own post in this series.
Stay in the loop
Get notified when I publish new posts. No spam, unsubscribe anytime.