**Release Date:** January 2, 2025
Overview
We are excited to announce the **initial release** of **HeuristAI**, a powerful Python package that leverages Large Language Models (LLMs) to enhance Genetic Programming (GP) for evolving heuristics. **HeuristAI** integrates cutting-edge models with robust evolutionary algorithms, providing users with a flexible and efficient tool for automatic algorithm design.
Key Features
- **LLM-Driven Genetic Programming:** Utilize LLMs like GPT-4 to guide mutations and crossover operations, ensuring more informed and efficient heuristic evolution.
- **Implemented Models:**
- **FunSearch:** An island-model evolutionary approach with multi-parent crossover and population resets to maintain diversity.
- **ReEvo:** Incorporates short-term and long-term considerations with elitist mutations for iterative heuristic improvement.
- **Evolution of Heuristics (EoH):** Standard GP enhanced with LLM-guided mutation and crossover prompts.
- **Ease of Integration with Various LLMs:** Seamlessly switch between different language models (e.g., GPT-3.5, GPT-4, Hugging Face transformers) with minimal configuration changes.
- **Parallelization & Concurrency:**
- **Ray:** Parallel fitness evaluations to accelerate the evolutionary process.
- **LangChain & Asyncio:** Asynchronous LLM interactions for faster heuristic generation.
- **Structured LLM Outputs:** Ensures clean and error-free code generation by enforcing structured responses from LLMs.
- **Population Tracking:** Detailed logging of each generation’s population and fitness scores in a JSON file (`evolution_log.json`) for analysis and reproducibility.
Installation
bash
pip install HeuristAI
Getting Started
1. **Clone the Repository:**
bash
git clone https://github.com/m229abd/HeuristAI.git
cd HeuristAI
2. **Install Dependencies:**
bash
pip install -e .
3. **Run an Example:**
bash
python examples/example_ReEvo.py
You will be prompted to enter your OpenAI API key or set it as an environment variable.
Configuration
- **Using Different LLMs:**
HeuristAI supports various LLMs. To switch models, adjust the LLM initialization in your scripts. For example, to use a Hugging Face model:
python
from transformers import pipeline
from HeuristAI.models.ReEvo import ReEvo
class HuggingFaceLLM:
def __init__(self, model_name: str, temperature: float = 0.7):
self.generator = pipeline('text-generation', model=model_name)
self.temperature = temperature
async def ainvoke(self, prompt: str):
result = self.generator(prompt, max_length=150, temperature=self.temperature)
return {"text": result[0]['generated_text']}
hf_llm = HuggingFaceLLM(model_name="gpt2", temperature=0.7)
re_evo = ReEvo(
population_size=5,
max_iterations=3,
test_cases=SEARCH_TEST_CASES,
llm=hf_llm,
fitness_function=custom_fitness_function.remote,
num_retries=3
)
License
This project is licensed under the **MIT License**. See the [LICENSE](./LICENSE) file for details.
Acknowledgements
- Inspired by research from **DeepMind**, **NeurIPS 2024**, and **ICML 2024**.
- Powered by [Ray](https://github.com/ray-project/ray), [LangChain](https://github.com/hwchase17/langchain), and [Pydantic](https://github.com/samuelcolvin/pydantic).
---
**Happy Evolving!**
For questions, suggestions, or contributions, please visit our [GitHub repository](https://github.com/m229abd/HeuristAI) or contact Mostafa Abdolmaleki at [m229abdgmail.com](mailto:m229abdgmail.com).