Skip to main content

FunMinks Logo

FunMinks: Genetic Algorithm Utilities for LLMs

FunMinks is a Python package for symbolic regression and genetic algorithm experimentation using Large Language Models (LLMs). It provides tools to define, mutate, and evolve code-based individuals ("minks") and manage populations, leveraging LLMs for code generation and mutation.

What is FunMinks?

FunMinks enables evolutionary computation on code snippets, using LLMs to mutate and optimize Python functions to fit target data. It is designed for symbolic regression, automated code improvement, and research in genetic programming with LLMs.

  • Mink: An individual represented by a genome (Python code), evaluated for fitness against datapoints.
  • Population: A collection of minks, managed for selection, mutation, and evolution.
  • LLM Endpoint: Utilities to load and interact with local LLM models for code generation.

Features

  • Symbolic regression using genetic algorithms and LLMs
  • Population management and selection
  • Code mutation via LLM prompts
  • Fitness evaluation against custom datapoints
  • Extensible for custom genetic operations

Installation

It is recommended to use a virtual environment for isolation:

# Create and activate a virtual environment
python -m venv .venv
.venv\Scripts\Activate.ps1

# Install FunMinks and dependencies
pip install -e .

Or install from source:

pip install git+https://github.com/UGarCil/GeneticAlgoLLM.git

Requirements

If you need GPU support, install the appropriate version of torch:

pip install torch --extra-index-url https://download.pytorch.org/whl/cu118

Usage

1. Prepare Data and Templates

  • Place your datapoints in templates/datapoints.csv (two columns: x, y)
  • Use or modify templates/prompt_template.txt for LLM mutation prompts
  • Use templates/seed_code_template.txt as the initial genome

2. Load LLM Endpoint

from FunMinks.llm_endpoint import load_llm
llm_params = load_llm('path/to/your/model')

3. Create a Population

from FunMinks.population import Population
from FunMinks.mink_llm_based import Mink

# Load templates and datapoints
with open('templates/prompt_template.txt') as f:
    prompt = f.read()
with open('templates/seed_code_template.txt') as f:
    seed_code = f.read()
with open('templates/datapoints.csv') as f:
    datapoints = f.read()

# Initialize population
pop = Population(
    pop_size=20,
    seed_code=seed_code,
    datapoints=datapoints,
    prompt=prompt,
    llm_params=llm_params
)

4. Run Evolution

for generation in range(10):
    pop.run_episode()
    print(f"Generation {generation}: Avg fitness = {pop.avg_fitness}")

Project Structure

FunMinks/
    mink_llm_based.py   # Mink class (individual)
    population.py       # Population management
    llm_endpoint.py     # LLM loading utilities
icons/
    main_logo.png       # Project logo
templates/
    datapoints.csv      # Example data
    prompt_template.txt # LLM prompt template
    seed_code_template.txt # Initial code genome

License

This project is licensed under the MIT License. See LICENSE for details.

Author

Uriel Garcilazo Cruz

Links

Release files for funminks 0.1.1

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

Source distribution (sdist)

Source distribution for funminks 0.1.1
File Size Uploaded
funminks-0.1.1.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for funminks 0.1.1
File Interpreter ABI Platform
funminks-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.8 kB

Release files / funminks-0.1.1.tar.gz

Download URL funminks-0.1.1.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9e02a6da6533910965b9b29b822b6316e8984b6faa3368a413070ea9a8b3dca7
BLAKE2b-256 checksum
How to use checksums
31eed0069b0395a45d173d97991d2ac56a0ec4d0f455ae905173956b1164e89c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Release files / funminks-0.1.1-py3-none-any.whl

Download URL funminks-0.1.1-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
435a508542fd1792bbfd03545ff61dc0f07c11c3d16d76424b1fe27f14cdde6e
BLAKE2b-256 checksum
How to use checksums
55798ccd7a96d71d3b0892f78689f3716cc0673d0d23e3e068aa2573a5c14cbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Release history Release notifications | RSS feed

This release

0.1.1 This release

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