Skip to main content

A modular framework for evolutionary strategies and neuroevolution.

Project description

EvoLib – A Modular Framework for Evolutionary Computation

Docs Status Code Quality & Tests License: MIT PyPI version Project Status: Beta

EvoLib Logo

EvoLib is a lightweight and transparent framework for evolutionary computation, focusing on simplicity, modularity, and clarity — aimed at experimentation, teaching, and small-scale research rather than industrial-scale applications.


Key Features

  • Transparent design: configuration via YAML, type-checked validation, and clear module boundaries.
  • Modularity: mutation, selection, crossover, and parameter representations can be freely combined.
  • Educational value: examples and a clean API make it practical for illustrating evolutionary concepts.
  • Neuroevolution support: structural mutations (adding/removing neurons and connections) and evolvable networks via EvoNet.
  • Type-checked: PEP8 compliant, and consistent code style.

EvoLib is currently in beta. The core API and configuration format are stable, but some features are still under development.


Sample Plot


Installation

pip install evolib

Requirements: Python 3.10+ and packages in requirements.txt.


Example Usage

from evolib import Pop

def my_fitness(indiv):
    # Custom fitness function (example: sum of vector)
    indiv.fitness = sum(indiv.para["main"].vector)

pop = Pop(config_path="config/my_experiment.yaml",
          fitness_function=my_fitness)

# Run the evolutionary process
pop.run()

For full examples, see 📁examples/ – including adaptive mutation, controller evolution, and network approximation.


Configuration Example (YAML)

A core idea of EvoLib is that experiments are defined entirely through YAML configuration files. This makes runs explicit, reproducible, and easy to adapt. The example below demonstrates different modules (vector + EvoNet) with mutation, structural growth, and stopping criteria.

parent_pool_size: 20
offspring_pool_size: 60
max_generations: 100
num_elites: 2
max_indiv_age: 0

stopping:
  target_fitness: 0.01
  patience: 20
  min_delta: 0.0001
  minimize: true

evolution:
  strategy: mu_comma_lambda

modules:
  controller:
    type: vector
    dim: 8
    initializer: normal_vector
    bounds: [-1.0, 1.0]
    mutation:
      strategy: adaptive_individual
      probability: 1.0
      strength: 0.1

  brain:
    type: evonet
    dim: [4, 6, 2]
    activation: [linear, tanh, tanh]
    initializer: normal_evonet
    mutation:
      strategy: constant
      probability: 1.0
      strength: 0.05

      # Optional fine-grained control
      activations:
        probability: 0.01
        allowed: [tanh, relu, sigmoid]

      structural:
        add_neuron: 0.01
        add_connection: 0.05
        remove_connection: 0.02
        recurrent: local  # none | direct | local | all
        keep_connected: true

ℹ️ Multiple parameter types (e.g. vector + evonet) can be combined in a single individual. Each component evolves independently, using its own configuration.


Documentation

Documentation for EvoLib is available at: 👉 https://evolib.readthedocs.io/en/latest/


Use Cases

EvoLib is developed for clarity, modularity, and exploration in evolutionary computation.
It can be applied to:

  • Illustrating concepts: simple, transparent examples for teaching and learning.
  • Neuroevolution: evolve weights and network structures using EvoNet.
  • Multi-module evolution: combine different parameter types (e.g. controller + brain).
  • Strategy comparison: benchmark and visualize mutation, selection, and crossover operators.
  • Function optimization: test behavior on benchmark functions (Sphere, Ackley, …).
  • Showcases: structural XOR, image approximation, and other demo tasks.
  • Rapid prototyping: experiment with new evolutionary ideas in a lightweight environment.

Preview: Pygame Integration

Early prototypes demonstrate how evolutionary algorithms can evolve both neural networks and sensor properties such as number, range, and orientation for agents in 2D worlds built with pygame. This illustrates how networks and sensors co-adapt to dynamic environments with collisions and feedback.

Ant/Food Prototype

In this video, agents use simple sensors to learn how to collect food while avoiding collisions with the environment.

Pygame Integration Preview

Flappy Bird–style Prototype

Another prototype uses a Flappy Bird–like 2D world, where agents must pass through moving gaps. Both the neural controller and the sensors (number, length, angle) are evolved, allowing perception and action to adapt together. This illustrates how EvoLib can be applied to simple game-like environments, making the joint evolution of sensing and control directly observable.

Pygame Integration Preview

This video shows the best agent from the final generation rather than the full evolutionary process.


Learn EvoLib in 5 Steps

EvoLib includes a small set of examples that illustrate the core concepts step by step:

  1. Hello Evolution – minimal run with a custom fitness function and visible improvement over generations.
  2. Strategies in Action – (μ + λ) evolution step by step.
  3. Function Approximation – evolve support points to match a sine curve.
  4. Evolution as Control – evolve a controller in an environment.
  5. Neuroevolution with Structural Growth – evolve networks with growing topology.

For deeper exploration, see the full examples directory


Roadmap

  • Adaptive Mutation (global, individual, per-parameter)
  • Flexible Crossover Strategies (BLX, intermediate, none)
  • Structured Neural Representations (EvoNet)
  • Composite Parameters (multi-module individuals)
  • Neuroevolution
  • Topological Evolution (neurons, edges)
  • Co-Evolution & Speciation Support
  • Advanced Visualization
  • Game Environment Integration (pygame, PettingZoo - early prototypes)
  • Ray Support for Parallel Evaluation (early prototypes)

License

MIT License – see MIT License.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

evolib-0.2.0b2.dev1.tar.gz (117.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

evolib-0.2.0b2.dev1-py3-none-any.whl (155.6 kB view details)

Uploaded Python 3

File details

Details for the file evolib-0.2.0b2.dev1.tar.gz.

File metadata

  • Download URL: evolib-0.2.0b2.dev1.tar.gz
  • Upload date:
  • Size: 117.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for evolib-0.2.0b2.dev1.tar.gz
Algorithm Hash digest
SHA256 d74fd5368ef8804550e3045c53985c9e9ac5ccd15ef4b62ae27d50e8f29cfeca
MD5 c6f1bea35c8834a511f6e44331991200
BLAKE2b-256 512c5d648395ca85678a341d51c376ef894213b31ff69c83c268b4cf02e83b6c

See more details on using hashes here.

File details

Details for the file evolib-0.2.0b2.dev1-py3-none-any.whl.

File metadata

  • Download URL: evolib-0.2.0b2.dev1-py3-none-any.whl
  • Upload date:
  • Size: 155.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for evolib-0.2.0b2.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 3a61aae788e48269ac009ca1394ab35cde5545419bf1c00a1a7517ebaa2cca89
MD5 f321a20def2b91fa0e42c93820a7ef9a
BLAKE2b-256 dfa12ae6c23eb2d22ef55c6a2e03a2712dc6a8da224be9e71b1a446d228596dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page