LLaMEA

LLaMEA - LLM powered Evolutionary Algorithm for code optimization This module integrates OpenAI’s language models to generate and evolve algorithms to automatically evaluate (for example metaheuristics evaluated on BBOB).

class llamea.llamea.LLaMEA(f, llm, n_parents=5, n_offspring=10, role_prompt='', task_prompt='', example_prompt=None, output_format_prompt=None, experiment_name='', elitism=False, HPO=False, mutation_prompts=None, adaptive_mutation=False, budget=100, eval_timeout=3600, max_workers=10, parallel_backend='loky', log=True, minimization=False, _random=False)

Bases: object

A class that represents the Language Model powered Evolutionary Algorithm (LLaMEA). This class handles the initialization, evolution, and interaction with a language model to generate and refine algorithms.

construct_prompt(individual)

Constructs a new session prompt for the language model based on a selected individual.

Args:

individual (dict): The individual to mutate.

Returns:

list: A list of dictionaries simulating a conversation with the language model for the next evolutionary step.

evaluate_fitness(individual)

Evaluates the fitness of the provided individual by invoking the evaluation function f. This method handles error reporting and logs the feedback, fitness, and errors encountered.

Args:

individual (Solution): The solution instance to evaluate.

Returns:

Solution: The updated solution with feedback, fitness and error information filled in.

evolve_solution(individual)

Evolves a single solution by constructing a new prompt, querying the LLM, and evaluating the fitness.

initialize()

Initializes the evolutionary process by generating the first parent population.

initialize_single()

Initializes a single solution.

logevent(event)
run()

Main loop to evolve the solutions until the evolutionary budget is exhausted. The method iteratively refines solutions through interaction with the language model, evaluates their fitness, and updates the best solution found.

Returns:

tuple: A tuple containing the best solution and its fitness at the end of the evolutionary process.

selection(parents, offspring)

Select the new population based on the parents and the offspring and the current strategy.

Args:

parents (list): List of solutions. offspring (list): List of new solutions.

Returns:

list: List of new selected population.

update_best()

Update the best individual in the new population