Skip to main content

SimEvo: A Simple Python Library for Simulations of Natural Selection

CI GitHub repo size GitHub code size PyPI - Implementation CodeFactor GitHub

2024 Spring NSD - Final Project - SimEvo: A Simple Python Library for Simulations of Natural Selection

Overview

Demo

Project Overview: Simulating Natural Selection in Ecosystems using C++ and Python

SimEvo leverages the computational efficiency of C++ for the core simulation engine and offers an intuitive Python interface for ease of use and accessibility. It models ecosystems composed of organisms with genetically determined traits, interacting within an environment that includes resources like food. The simulation observes the principles of natural selection, with organism survival and reproduction influenced by their traits and environmental factors.

How to use

Install directly from PyPI

!!!This feature is only support Linux and MacOS currently.

pip install simevopy

Build from scratch

Build for testing

mkdir build; cd build
cmake -S .. -B . -DBUILD_TESTS=true
make
ctest -V

Build for python package

python setup.py install

or

pip install .

Components:

SimEvo integrates a high-performance C++ simulation engine with Python bindings for ease of use. Key architectural components include:

  • Core Simulation Engine (C++): Manages the dynamics of natural selection and organism interactions.
  • Python API (C++/Python via pybind11): Allows users to define and manipulate the simulation parameters easily.
  • Spatial Indexing (Quadtree): Optimizes computational tasks related to spatial relationships and interactions among entities.

Python Script Examples

The script sets up a SimSel simulation in a 500x500 space, initializing 10 "ABCD" gene organisms and distributing food to model resource scarcity. Operating in an "optimize" mode for efficiency, it cycles through 100 generations, each time scattering food and advancing the simulation to observe natural selection as organisms interact, feed, and reproduce based on genetic traits. You can find more examples in examples.

from simevopy import Environment, Organism, Genes
import random

# Setup base organisms in the environment
def setup_base_organism(env, count=10):
    for _ in range(count):
        x = random.randint(0, env.width - 1)
        y = random.randint(0, env.height - 1)
        env.add_organism(Organism(Genes("ABCD")), x, y)

# Distribute food randomly within the environment
def distribute_food_randomly(env, food_count=50):
    for _ in range(food_count):
        x = random.randint(0, env.width - 1)
        y = random.randint(0, env.height - 1)
        env.add_food(x, y)

# Create an optimized environment
env = Environment(500, 500, type="optimize")

# Initialize organisms
setup_base_organism(env)

# Run the simulation over 100 generations
for i in range(100):
    print(f"Gen {i} th")
    distribute_food_randomly(env, 100)
    env.simulate_iteration(50)

Metadata

Release files for simevopy 0.2.26

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

Source distribution (sdist)

Source distribution for simevopy 0.2.26
File Size Uploaded
simevopy-0.2.26.tar.gz 28.4 kB Details

Release files / simevopy-0.2.26.tar.gz

Download URL simevopy-0.2.26.tar.gz
Size 28.4 kB
Tags Source
SHA-256 checksum
How to use checksums
88bb43f0191df49c1fe09098fadbf48ec429fc259b165984a6864881279c7088
BLAKE2b-256 checksum
How to use checksums
4b8aaa801dfb2694242b1442f15952391c67099770490d64a32e96d628fbd935
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.2.26 This release

1 release file

0.2.25

1 release file

0.2.24

1 release file

0.2.23

1 release file

0.2.22

1 release file

0.2.21

1 release file

0.2.20

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.1.17

1 release file

0.1.16

1 release file

0.1.15

1 release file

0.1.14

1 release file

0.1.13

1 release file

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

2 release files

0.1.0

2 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