Skip to main content

genoxide for Python

Evolutionary computation in Rust, for Python: genetic algorithms, local search, differential evolution, CMA-ES, particle swarm optimization, and NSGA-II, NSGA-III, SPEA2, MOEA/D and SMS-EMOA for several objectives, from genoxide, with fitness functions in Python and numpy.

import numpy as np
import genoxide as gx

# OneMax: the genome with the most ones
ga = gx.Ga(
    gx.Binary(100),
    population_size=100,
    select=gx.Tournament(3),
    crossover=gx.UniformCrossover(),
    mutation=gx.BitFlip(rate=0.01),
    seed=42,
)
result = ga.run(lambda bits: bits.sum(), target=100, generations=1_000)
print(result.best_fitness, result.generations)

# Rastrigin with CMA-ES and IPOP restarts, a generation per call
def rastrigin(x):  # x: a genome per row
    return 10 * x.shape[1] + np.sum(x**2 - 10 * np.cos(2 * np.pi * x), axis=1)

cmaes = gx.Cmaes(gx.Real((-5.12, 5.12), length=10), restarts="ipop", objective="minimize", seed=1)
result = cmaes.run(rastrigin, batch=True, target=1e-8, evaluations=500_000)
print(result.best_genome, result.best_fitness)

More in examples/: OneMax, a knapsack with a constraint, N-Queens with tabu search, Rastrigin with CMA-ES and L-SHADE, and ZDT1 with NSGA-II.

Install

pip install genoxide

The wheels are for Linux (x86_64 and aarch64, glibc and musl), macOS (Apple silicon and Intel) and Windows (x64), and CPython 3.10 or later, with numpy. To build it from the repository instead, with Rust and maturin:

cd python
pip install maturin
maturin develop --release

Fitness functions

A fitness function takes a genome as a numpy array:

Genome Array
Binary(length) bool
Integer(bounds, length) int64
Real(bounds, length) float64
Permutation(length) int64, an ordering of 0 .. length - 1

bounds is one pair (low, high) for every gene, with length, or a list of pairs, one per gene.

It returns one of these:

  • a number
  • None or NaN, for a solution that can't be scored
  • (score, constraint_violation): infeasible solutions, with a positive violation, rank below feasible ones, and among themselves by violation (Deb's rules)

The fitness function must be deterministic: genoxide doesn't evaluate a child identical to one of its parents again.

With batch=True, the function takes a whole generation as a 2-D array, a genome per row, and returns an array of scores, or a tuple of scores and constraint violations. It's one call per generation (none for a generation whose children are all copies of their parents), so vectorized numpy, a GPU or a remote service pays its cost per call once per generation instead of once per genome.

With parallel=True, genoxide calls a function that isn't a batch function from several threads at once. It pays off when the function releases the GIL, e.g. in numpy on large arrays or waiting for I/O, or on free-threaded Python.

An exception in the fitness function stops the run and is raised by run, and so is Ctrl+C.

Algorithms

Algorithm Genomes Settings
Ga all population_size, select, crossover, mutation, crossover_rate (0.9), mutation_rate (1), scheme
LocalSearch all neighbor (a mutation), neighbors (1), acceptance, restart=(patience, kicks)
De real population_size (the number of genes + 10), l_shade (a budget of evaluations, for L-SHADE)
Cmaes real population_size, restarts ("ipop", "bipop"), initial_step
Pso real population_size (needed), ring (neighbors on each side)
Nsga2 all objectives, population_size, crossover, mutation, crossover_rate (0.9), mutation_rate (1)
Nsga3 all objectives, reference_directions, crossover, mutation, population_size (the number of reference directions), crossover_rate (1), mutation_rate (1)
Spea2 all objectives, population_size (the archive's), crossover, mutation, crossover_rate (0.9), mutation_rate (1)
Moead all objectives, weights (a subproblem each), crossover, mutation, decomposition (Tchebycheff()), neighbors (20), neighbor_mating (0.9), max_replacements (2), crossover_rate (1), mutation_rate (1)
SmsEmoa all objectives, population_size, crossover, mutation, offspring (population_size), crossover_rate (0.9), mutation_rate (1)

Single-objective algorithms maximize, or minimize with objective="minimize". The multi-objective algorithms take objectives=["minimize", "maximize", ...], 2 to 6 of them. Their fitness function returns a sequence of objective values, and their result is the final non-dominated front: front_genomes, front_objectives and front_violations.

  • Nsga2 spreads the front by crowding distance, which works poorly beyond 2 or 3 objectives.
  • Nsga3 spreads it along reference directions instead, and Moead solves a single-objective subproblem per weight vector. das_dennis(objectives, divisions) gives evenly spread directions or weights, a row each: 91 for 3 objectives and 12 divisions.
  • Spea2 keeps an archive of the best solutions, the non-dominated ones first, truncated by the distance to their nearest neighbors.
  • Nsga2, Nsga3, Spea2 and SmsEmoa drop a child that equals a member of the population or an earlier child, and breed another, as pymoo does: eliminate_duplicates=False keeps copies.
  • SmsEmoa removes, from the last front that fits partly, the solutions that contribute the least hypervolume. It costs more per generation than Nsga2: O(N log N) per removal for 2 objectives, O(N²) for 3, O(N³) for 4 and O(N⁴) for 5, where Nsga3 or Moead are better choices.

Every algorithm takes a seed: the same seed repeats a run exactly, with a genome at a time, in batches or in parallel.

Operators:

  • Selection: Tournament(size), Rank(pressure), Roulette(), StochasticUniversalSampling(), Truncation(fraction), RandomSelection()
  • Crossover:
    • any list genome: UniformCrossover(), PointCrossover(points), NoCrossover()
    • real genomes: SimulatedBinaryCrossover(eta), BlendCrossover(alpha), ArithmeticCrossover()
    • permutations: OrderCrossover(), PartiallyMappedCrossover(), CycleCrossover(), EdgeRecombinationCrossover()
  • Mutation:
    • binary genomes: BitFlip(rate=... | count=...)
    • integer and real genomes: UniformMutation(rate=... | count=...)
    • real genomes: GaussianMutation(sigma, rate=... | count=...), PolynomialMutation(eta, rate=... | count=...)
    • permutations: SwapMutation(count), InversionMutation(), InsertionMutation(), ScrambleMutation()
  • Genetic algorithm schemes: Generational(elitism) (the default, with 1), SteadyState(replacements), MuPlusLambda(offspring), MuCommaLambda(offspring)
  • Local search acceptance: NotWorse() (the default), Improving(), Annealing(initial_temperature, cooling), Tabu(tenure)
  • MOEA/D decomposition: Tchebycheff() (the default), Pbi(theta) (penalty-based boundary intersection, theta 5 by default), which spreads fronts of 3 or more objectives well

Stopping

run stops at the first of its stop conditions, and needs at least one:

  • generations
  • evaluations
  • target: a score at least as good (single objective)
  • time: seconds
  • stagnation: generations without improvement

The result says which one stopped it, in stop_reason, with the numbers of generations and evaluations and the seconds it took.

Progress

run(..., on_generation=callback) calls callback after every generation, the initial population (generation 0) included, on the thread that called run. It gets a read-only Progress with the generation, the evaluations and the seconds so far, and the best_fitness so far (None before a valid solution); for a multi-objective algorithm, a MultiProgress with the front_size (the number of non-dominated individuals in the population) instead.

If callback returns False, the run stops with the stop reason "aborted". If it raises an exception, the run stops and run raises it.

def report(progress):
    if progress.generation % 100 == 0:
        print(progress.generation, progress.evaluations, progress.best_fitness)

result = ga.run(lambda bits: bits.sum(), generations=1_000, on_generation=report)

Release files for genoxide 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for genoxide 0.6.0
File Size Uploaded
genoxide-0.6.0.tar.gz 337.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for genoxide 0.6.0
File
genoxide-0.6.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
genoxide-0.6.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
genoxide-0.6.0-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
genoxide-0.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
genoxide-0.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
genoxide-0.6.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
genoxide-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 16.1 MB

Release files / genoxide-0.6.0.tar.gz

Download URL genoxide-0.6.0.tar.gz
Size 337.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fddf7a561e653bee719d3e77f9b5bef0829df1735f8ebaf0eddab3235f36c3aa
BLAKE2b-256 checksum
How to use checksums
b5254c396df6cd3fff3e1def3b58cf8baa5aeeceee653f59a7ec379d3400433f
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 Sep 25, 2026.

Transparency log

Release files / genoxide-0.6.0-cp310-abi3-win_amd64.whl

Download URL genoxide-0.6.0-cp310-abi3-win_amd64.whl
Size 2.4 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
778daa477abb28c6b228f14028fd8d510b8322e99fdc92c15812002b0d26ce2a
BLAKE2b-256 checksum
How to use checksums
4e17b069eb4757033c207a988e111287036cbfd653b33b62dcad7f929c3f51fc
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 Sep 25, 2026.

Transparency log

Release files / genoxide-0.6.0-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL genoxide-0.6.0-cp310-abi3-musllinux_1_2_x86_64.whl
Size 2.6 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
29ecbb07167b2938afb70027397bc8d8228c1bac180178e19074a0ea21699ee8
BLAKE2b-256 checksum
How to use checksums
fbc3dd09517c699f30db14ec482ef33d39c91957eea4c87be67ab03a09c669f1
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 Sep 25, 2026.

Transparency log

Release files / genoxide-0.6.0-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL genoxide-0.6.0-cp310-abi3-musllinux_1_2_aarch64.whl
Size 2.2 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
da75926cf0bfd6845014a50cb1eacb3e03162ce3fde38554dec28e8e713bc76b
BLAKE2b-256 checksum
How to use checksums
fb02edabdc6ee4aebee84d11c4cd7b76bdc48e6ca9fe48e361054e8db4685d2b
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 Sep 25, 2026.

Transparency log

Release files / genoxide-0.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL genoxide-0.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.4 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
a2026c5a8c1af96fb2f536dea32553affa4bf2614518b79cfc71049db731dc53
BLAKE2b-256 checksum
How to use checksums
fbd7200f5c6a6e70ec21ffd13e451f6b267d44434b58b3f580f3ea57a934b4b7
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 Sep 25, 2026.

Transparency log

Release files / genoxide-0.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL genoxide-0.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.0 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
8763bef3beb34012712e726b4740f1524df34af4a8a62fb4fc78d99485f84691
BLAKE2b-256 checksum
How to use checksums
2b1e631dd1cb9f71f95040dcd48483cab694d48bb34a654069584634a396f671
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 Sep 25, 2026.

Transparency log

Release files / genoxide-0.6.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL genoxide-0.6.0-cp310-abi3-macosx_11_0_arm64.whl
Size 2.0 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
90c61870c3775bc451b07063949c9673a18507d42ff5ebee60f19016881be9bd
BLAKE2b-256 checksum
How to use checksums
b58fc23c64b01896e1f0e7e335ab316cf9e5b7ab5a36ba10b3e3a1227b542936
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 Sep 25, 2026.

Transparency log

Release files / genoxide-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL genoxide-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 2.3 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
251e0375a805303cb866a51d81293090aeb54216f5272dfe77b2a60d52245698
BLAKE2b-256 checksum
How to use checksums
b230787bdc2b0bf6ef769819564739f9d813ee3294865fa004f8609cbb115b32
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 Sep 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.6.0 This release

8 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page