llamea-lite 1.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- llamea_lite-1.1.3/.gitignore +193 -0
- llamea_lite-1.1.3/LICENSE +21 -0
- llamea_lite-1.1.3/PKG-INFO +390 -0
- llamea_lite-1.1.3/README.md +373 -0
- llamea_lite-1.1.3/llamea/__init__.py +5 -0
- llamea_lite-1.1.3/llamea/bbobalgs/ERADS_QuantumFluxUltraRefined.py +86 -0
- llamea_lite-1.1.3/llamea/bbobalgs/__init__.py +0 -0
- llamea_lite-1.1.3/llamea/llamea.py +799 -0
- llamea_lite-1.1.3/llamea/llm.py +569 -0
- llamea_lite-1.1.3/llamea/loggers.py +141 -0
- llamea_lite-1.1.3/llamea/solution.py +174 -0
- llamea_lite-1.1.3/llamea/utils.py +161 -0
- llamea_lite-1.1.3/pyproject.toml +32 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
110
|
+
.pdm.toml
|
|
111
|
+
|
|
112
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
113
|
+
__pypackages__/
|
|
114
|
+
|
|
115
|
+
# Celery stuff
|
|
116
|
+
celerybeat-schedule
|
|
117
|
+
celerybeat.pid
|
|
118
|
+
|
|
119
|
+
# SageMath parsed files
|
|
120
|
+
*.sage.py
|
|
121
|
+
|
|
122
|
+
# Environments
|
|
123
|
+
.env
|
|
124
|
+
.venv
|
|
125
|
+
env/
|
|
126
|
+
venv/
|
|
127
|
+
ENV/
|
|
128
|
+
env.bak/
|
|
129
|
+
venv.bak/
|
|
130
|
+
|
|
131
|
+
# Spyder project settings
|
|
132
|
+
.spyderproject
|
|
133
|
+
.spyproject
|
|
134
|
+
|
|
135
|
+
# Rope project settings
|
|
136
|
+
.ropeproject
|
|
137
|
+
|
|
138
|
+
# mkdocs documentation
|
|
139
|
+
/site
|
|
140
|
+
|
|
141
|
+
# mypy
|
|
142
|
+
.mypy_cache/
|
|
143
|
+
.dmypy.json
|
|
144
|
+
dmypy.json
|
|
145
|
+
|
|
146
|
+
# Pyre type checker
|
|
147
|
+
.pyre/
|
|
148
|
+
|
|
149
|
+
# pytype static type analyzer
|
|
150
|
+
.pytype/
|
|
151
|
+
|
|
152
|
+
# Cython debug symbols
|
|
153
|
+
cython_debug/
|
|
154
|
+
|
|
155
|
+
# PyCharm
|
|
156
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
157
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
158
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
159
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
160
|
+
#.idea/
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
iohllm/alg-old.py
|
|
164
|
+
old-data/
|
|
165
|
+
runs/
|
|
166
|
+
ioh/
|
|
167
|
+
algorithms/
|
|
168
|
+
ioh2/
|
|
169
|
+
iohbest10/
|
|
170
|
+
user_tsp_gls/algs/
|
|
171
|
+
benchmarks/LLMdesignedEA/LLMdesignedEA-comp
|
|
172
|
+
benchmarks/user_tsp_gls/tsplib/
|
|
173
|
+
|
|
174
|
+
# snellius server sbatch jobs output
|
|
175
|
+
nohup.out
|
|
176
|
+
sbatch_jobs/
|
|
177
|
+
# exp-*
|
|
178
|
+
currentexp/
|
|
179
|
+
*.job
|
|
180
|
+
|
|
181
|
+
#AST img and alg folders
|
|
182
|
+
ast/fixed_mutation_experiments
|
|
183
|
+
ast/dynamic_mutation_experiments
|
|
184
|
+
ast/EoH_runs
|
|
185
|
+
ast/*output*
|
|
186
|
+
ast/img*
|
|
187
|
+
ast/graphstats*
|
|
188
|
+
|
|
189
|
+
logs/
|
|
190
|
+
benchmarks/ma_bbob/MABBOB_Baselines/
|
|
191
|
+
benchmarks/ma_bbob/ERADS*
|
|
192
|
+
benchmarks/ma_bbob/RS*
|
|
193
|
+
exp-*
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Niki van Stein
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llamea-lite
|
|
3
|
+
Version: 1.1.3
|
|
4
|
+
Summary: LLaMEA without bundled LLM or HPO dependencies
|
|
5
|
+
Project-URL: Homepage, https://github.com/XAI-liacs/LLaMEA
|
|
6
|
+
Project-URL: Repository, https://github.com/XAI-liacs/LLaMEA
|
|
7
|
+
Author-email: Niki van Stein <n.van.stein@liacs.leidenuniv.nl>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: <4,>=3.11
|
|
11
|
+
Requires-Dist: joblib<2,>=1.4.2
|
|
12
|
+
Requires-Dist: jsonlines<5,>=4.0.0
|
|
13
|
+
Requires-Dist: numpy<3,>=2
|
|
14
|
+
Requires-Dist: ollama<1,>=0.5.3
|
|
15
|
+
Requires-Dist: tqdm<5,>=4.66.4
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
<picture>
|
|
20
|
+
<source media="(prefers-color-scheme: dark)" srcset="logo-dark.png">
|
|
21
|
+
<source media="(prefers-color-scheme: light)" srcset="logo.png">
|
|
22
|
+
<img alt="Shows the LLaMEA logo." src="logo.png" width="200px">
|
|
23
|
+
</picture>
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
<h1 align="center">LLaMEA: Large Language Model Evolutionary Algorithm</h1>
|
|
27
|
+
|
|
28
|
+
> ⭐ If you like this, please give the repo a star – it helps!
|
|
29
|
+
|
|
30
|
+
<p align="center">
|
|
31
|
+
<a href="https://pypi.org/project/llamea/">
|
|
32
|
+
<img src="https://badge.fury.io/py/llamea.svg" alt="PyPI version" height="18">
|
|
33
|
+
</a>
|
|
34
|
+
<a target="_blank" href="https://pypi.org/project/llamea/">
|
|
35
|
+
<img src="https://img.shields.io/pypi/dm/llamea" alt="Downloads per month"/>
|
|
36
|
+
</a>
|
|
37
|
+
<img src="https://img.shields.io/badge/Maintained%3F-yes-brightgreen.svg" alt="Maintenance" height="18">
|
|
38
|
+
<img src="https://img.shields.io/badge/Python-3.10+-blue" alt="Python 3.10+" height="18">
|
|
39
|
+
<img src="https://github.com/XAI-liacs/LLaMEA/actions/workflows/test.yml/badge.svg" alt="Test"/>
|
|
40
|
+
<a href="https://codecov.io/gh/XAI-liacs/LLaMEA" >
|
|
41
|
+
<img src="https://codecov.io/gh/XAI-liacs/LLaMEA/graph/badge.svg?token=VKCNPWVBNM"/>
|
|
42
|
+
</a>
|
|
43
|
+
<a href="https://doi.org/10.5281/zenodo.13842144"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.13842144.svg" alt="DOI"></a>
|
|
44
|
+
<a target="_blank" href="https://colab.research.google.com/github/XAI-liacs/LLaMEA/blob/main/docs/notebooks/simple_example.ipynb">
|
|
45
|
+
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
|
|
46
|
+
</a>
|
|
47
|
+
|
|
48
|
+
<a target="_blank" href="https://xai-liacs.github.io/LLaMEA/">
|
|
49
|
+
<img src="https://img.shields.io/badge/docs-online-success" alt="Docs"/>
|
|
50
|
+
</a>
|
|
51
|
+
<br/>
|
|
52
|
+
<a href="https://colab.research.google.com/github/XAI-liacs/LLaMEA/blob/main/docs/notebooks/simple_example.ipynb" target="_blank">Check our demo on Colab</a>
|
|
53
|
+
</p>
|
|
54
|
+
|
|
55
|
+
> **The fully-open successor to Google DeepMind’s AlphaEvolve for automated algorithm discovery.**
|
|
56
|
+
> First released 📅 Nov 2024 • MIT License • 100 % reproducible.
|
|
57
|
+
> Also read the <a href="https://xai-liacs.github.io/LLaMEA/" target="_blank">Documentation</a>.
|
|
58
|
+
> 🥈 Winner of the Silver <a href="https://www.human-competitive.org/awards">Humies 2025</a> at GECCO!
|
|
59
|
+
|
|
60
|
+
LLaMEA couples large-language-model reasoning with an evolutionary loop to **invent, mutate and benchmark algorithms fully autonomously**.
|
|
61
|
+
|
|
62
|
+
## Table of Contents
|
|
63
|
+
- [Introduction](#introduction)
|
|
64
|
+
- [News](#-news)
|
|
65
|
+
- [Installation](#-installation)
|
|
66
|
+
- [Quick Start](#-quick-start)
|
|
67
|
+
- [Configuration](#-configuration)
|
|
68
|
+
- [Examples](#-examples)
|
|
69
|
+
- [Running `black-box-optimization.py`](#running-black-box-optimizationpy)
|
|
70
|
+
- [Running `black-box-opt-with-HPO.py` (LLaMEA-HPO)](#running-black-box-opt-with-hpopy-llamea-hpo)
|
|
71
|
+
- [Running `automl_example.py`](#running-automl_examplepy)
|
|
72
|
+
- [Contributing](#-contributing)
|
|
73
|
+
- [License](#-license)
|
|
74
|
+
- [Citation](#-citation)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## Introduction
|
|
78
|
+
|
|
79
|
+
**LLaMEA** (Large Language Model Evolutionary Algorithm) is an innovative framework that leverages the power of large language models (LLMs) such as GPT-4 for the automated generation and refinement of metaheuristic optimization algorithms. The framework utilizes a novel approach to evolve and optimize algorithms iteratively based on performance metrics and runtime evaluations without requiring extensive prior algorithmic knowledge. This makes LLaMEA an ideal tool for both research and practical applications in fields where optimization is crucial.
|
|
80
|
+
|
|
81
|
+
**Key Features:**
|
|
82
|
+
- **Automated Algorithm Generation**: Automatically generates and refines algorithms using GPT-based or similar LLM models.
|
|
83
|
+
- **Performance Evaluation**: Integrates seamlessly with the IOHexperimenter for real-time performance feedback, guiding the evolutionary process.
|
|
84
|
+
- **LLaMEA-HPO**: Provides an in-the-loop hyper-parameter optimization mechanism (via SMAC) to offload numerical tuning, so that LLM queries focus on novel structural improvements.
|
|
85
|
+
- **Extensible & Modular**: You can easily integrate additional models and evaluation tools.
|
|
86
|
+
- **Niching for Diversity**: Fitness sharing and clearing strategies maintain a diverse set of solutions.
|
|
87
|
+
- **Unified Diff Mode**: Evolve code through patch-based edits for efficient token usage.
|
|
88
|
+
- **Population Evaluation Mode**: Optionally evaluate whole populations in a single call to speed up expensive fitness functions.
|
|
89
|
+
|
|
90
|
+
<p align="center">
|
|
91
|
+
<img src="framework.png" alt="LLaMEA framework" style="width:100%;"/>
|
|
92
|
+
</p>
|
|
93
|
+
|
|
94
|
+
**Example use-cases:**
|
|
95
|
+
- **Problem specific optimization algorithms**: Easily generate and fine-tune optimization algorithms to work on **your specific** problem. By leveraging problem knowledge in the prompt the generated optimized algorithms can perform even better.
|
|
96
|
+
- **Efficient new Bayesian Optimization algorithms**: Generate optimized and novel Bayesian optimization algorithms, specifically for optimizing very expensive problems such as auto-motive crash worthiness or car shape design optimization tasks.
|
|
97
|
+
- **Machine Learning Pipelines**: Without any ML knowledge, you can use LLaMEA to generate optimized machine learning pipelines for any task. Just insert the task description and provide the dataset and evaluation metric and start LLaMEA.
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
## 🔥 News
|
|
101
|
+
|
|
102
|
+
+ 2025.07 🎉🎉 **"LLaMEA" won the Any-time Performancy on Many-Affine BBOB competition, and the Silver award at the [Humies @GECCO2025](https://www.human-competitive.org/awards)**!
|
|
103
|
+
|
|
104
|
+
+ 2025.06 🎉🎉 **["LLaMEA-BO: A Large Language Model Evolutionary Algorithm for Automatically Generating Bayesian Optimization Algorithms"](https://arxiv.org/abs/2505.21034) published on Arxiv**!
|
|
105
|
+
|
|
106
|
+
+ 2025.05 🎉🎉 **["Optimizing Photonic Structures with Large Language Model Driven Algorithm Discovery"](https://arxiv.org/abs/2503.19742) accepted as workshop paper at GECCO 2025**!
|
|
107
|
+
|
|
108
|
+
+ 2025.05 🎉🎉 **["BLADE: Benchmark Suite for LLM-Driven Automated Design and Evolution of iterative optimisation heuristics"](https://arxiv.org/abs/2504.20183) accepted as workshop paper at GECCO 2025**!
|
|
109
|
+
|
|
110
|
+
+ 2025.04 🎉🎉 **LLaMEA-HPO paper accepted in ACM TELO** [“In-the-loop Hyper-Parameter Optimization for LLM-Based Automated Design of Heuristics"](https://dl.acm.org/doi/abs/10.1145/3731567)!
|
|
111
|
+
|
|
112
|
+
+ 2025.04 🎉🎉 **["Code Evolution Graphs"](https://arxiv.org/abs/2503.16668) accepted as full paper at GECCO 2025**!
|
|
113
|
+
|
|
114
|
+
+ 2025.03 🎉🎉 **LLaMEA v1.0.0 released**!
|
|
115
|
+
|
|
116
|
+
+ 2025.01 🎉🎉 **LLaMEA paper accepted in IEEE TEVC** [“Llamea: A large language model evolutionary algorithm for automatically generating metaheuristics"](https://ieeexplore.ieee.org/abstract/document/10752628/)!
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
## 🎁 Installation
|
|
120
|
+
|
|
121
|
+
It is the easiest to use LLaMEA from the pypi package.
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
pip install llamea
|
|
125
|
+
```
|
|
126
|
+
> [!Important]
|
|
127
|
+
> The Python version **must** be larger or equal to 3.11.
|
|
128
|
+
> You need an OpenAI/Gemini/Ollama API key for using LLM models.
|
|
129
|
+
|
|
130
|
+
For a slimmed-down installation without bundled LLM or HPO dependencies, install
|
|
131
|
+
the lite package:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
pip install llamea-lite
|
|
135
|
+
```
|
|
136
|
+
HPO features in the lite package require installing `ConfigSpace` separately.
|
|
137
|
+
|
|
138
|
+
You can also install the package from source using <a href="https://docs.astral.sh/uv/" target="_blank">uv</a> (0.7.19).
|
|
139
|
+
make sure you have `uv` installed.
|
|
140
|
+
|
|
141
|
+
1. Clone the repository:
|
|
142
|
+
```bash
|
|
143
|
+
git clone https://github.com/XAI-liacs/LLaMEA.git
|
|
144
|
+
cd LLaMEA
|
|
145
|
+
```
|
|
146
|
+
2. Install the required dependencies via uv:
|
|
147
|
+
```bash
|
|
148
|
+
uv sync
|
|
149
|
+
```
|
|
150
|
+
3. Optional install dev or/and example dependencies:
|
|
151
|
+
```bash
|
|
152
|
+
uv sync --dev --group examples
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## 💻 Quick Start
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
> [!TIP]
|
|
159
|
+
> See also the getting started demo: <a target="_blank" href="https://colab.research.google.com/github/XAI-liacs/LLaMEA/blob/main/docs/notebooks/simple_example.ipynb">
|
|
160
|
+
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
|
|
161
|
+
</a>
|
|
162
|
+
|
|
163
|
+
1. Set up an OpenAI API key:
|
|
164
|
+
- Obtain an API key from [OpenAI](https://openai.com/).
|
|
165
|
+
- Set the API key in your environment variables:
|
|
166
|
+
```bash
|
|
167
|
+
export OPENAI_API_KEY='your_api_key_here'
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
2. Running an Experiment
|
|
171
|
+
|
|
172
|
+
To run an optimization experiment using LLaMEA:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from llamea import LLaMEA
|
|
176
|
+
|
|
177
|
+
# Define your evaluation function
|
|
178
|
+
def your_evaluation_function(solution):
|
|
179
|
+
# Implementation of your function
|
|
180
|
+
# return feedback, quality score, error information
|
|
181
|
+
return "feedback for LLM", 0.1, ""
|
|
182
|
+
|
|
183
|
+
# Initialize LLaMEA with your API key and other parameters
|
|
184
|
+
optimizer = LLaMEA(f=your_evaluation_function, api_key="your_api_key_here")
|
|
185
|
+
|
|
186
|
+
# Run the optimizer
|
|
187
|
+
best_solution, best_fitness = optimizer.run()
|
|
188
|
+
print(f"Best Solution: {best_solution}, Fitness: {best_fitness}")
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## ⚙️ Configuration
|
|
192
|
+
|
|
193
|
+
Key hyper-parameters of `LLaMEA`:
|
|
194
|
+
|
|
195
|
+
| Parameter | Description |
|
|
196
|
+
| --- | --- |
|
|
197
|
+
| `n_parents`, `n_offspring` | Population sizes controlling selection and mutation |
|
|
198
|
+
| `budget` | Number of generations to run |
|
|
199
|
+
| `niching` | Diversity management strategy (`None`, `"sharing"`, `"clearing"`) with `niche_radius` and related options |
|
|
200
|
+
| `evaluate_population` | If `True`, the evaluation function `f` operates on a list of solutions |
|
|
201
|
+
| `diff_mode` | Requests unified diff patches instead of full code for mutations |
|
|
202
|
+
| `HPO` | Enable in-the-loop hyper-parameter optimization |
|
|
203
|
+
| `eval_timeout`, `max_workers`, `parallel_backend` | Control evaluation time and parallelism |
|
|
204
|
+
| `adaptive_mutation`, `adaptive_prompt` | Adaptive control of mutation strength and task prompt |
|
|
205
|
+
|
|
206
|
+
See the [Documentation](https://xai-liacs.github.io/LLaMEA/) for a complete description of all parameters.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## 💻 Examples
|
|
211
|
+
|
|
212
|
+
Below are two example scripts from the `examples` directory demonstrating LLaMEA in action for black-box optimization with a BBOB (24 noiseless) function suite. One script (`examples/black-box-optimization.py`) runs basic LLaMEA, while the other (`examples/black-box-opt-with-HPO.py`) incorporates a **hyper-parameter optimization** pipeline—known as **LLaMEA-HPO**—that employs SMAC to tune the algorithm’s parameters in the loop.
|
|
213
|
+
|
|
214
|
+
### Running `black-box-optimization.py`
|
|
215
|
+
|
|
216
|
+
**`black-box-optimization.py`** showcases a straightforward use-case of LLaMEA. It:
|
|
217
|
+
- Defines an evaluation function `evaluateBBOB` that runs generated algorithms on a standard set of BBOB problems (24 functions).
|
|
218
|
+
- Initializes LLaMEA with a specific model (e.g., GPT-4, GPT-3.5) and prompts the LLM to generate metaheuristic code.
|
|
219
|
+
- Iterates over a `(1+1)`-style evolutionary loop, refining the code until a certain budget is reached.
|
|
220
|
+
|
|
221
|
+
**How to run:**
|
|
222
|
+
```bash
|
|
223
|
+
uv run python examples/black-box-optimization.py
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
The script will:
|
|
227
|
+
1. Query the specified LLM with a prompt describing the black-box optimization task.
|
|
228
|
+
2. Dynamically execute each generated algorithm on BBOB problems.
|
|
229
|
+
3. Log performance data such as AOCC (Area Over the Convergence Curve).
|
|
230
|
+
4. Iteratively refine the best-so-far algorithms.
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
### Running `black-box-opt-with-HPO.py` (LLaMEA-HPO)
|
|
234
|
+
|
|
235
|
+
**`black-box-opt-with-HPO.py`** extends LLaMEA with **in-the-loop hyper-parameter optimization**—termed **LLaMEA-HPO**. Instead of having the LLM guess or refine hyper-parameters directly, the code:
|
|
236
|
+
- Allows the LLM to generate a Python class representing the metaheuristic **plus** a ConfigSpace dictionary describing hyper-parameters.
|
|
237
|
+
- Passes these hyper-parameters to SMAC, which then searches for good parameter settings on a BBOB training set.
|
|
238
|
+
- Evaluates the best hyper-parameters found by SMAC on the full BBOB suite.
|
|
239
|
+
- Feeds back the final performance (and errors) to the LLM, prompting it to mutate the algorithm’s structure (rather than simply numeric settings).
|
|
240
|
+
|
|
241
|
+
**Why LLaMEA-HPO?**
|
|
242
|
+
Offloading hyper-parameter search to SMAC significantly reduces LLM query overhead and encourages the LLM to focus on novel structural improvements.
|
|
243
|
+
|
|
244
|
+
**How to run:**
|
|
245
|
+
```bash
|
|
246
|
+
uv run python examples/black-box-opt-with-HPO.py
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**Script outline:**
|
|
250
|
+
1. **Prompt & Generation**: Script sets up a role/task prompt, along with hyper-parameter config space templates.
|
|
251
|
+
2. **HPO Step**: For each newly generated algorithm, SMAC tries different parameter values within a budget.
|
|
252
|
+
3. **Evaluation**: The final best configuration from SMAC is tested across BBOB instances.
|
|
253
|
+
4. **Refinement**: The script returns the performance to LLaMEA, prompting the LLM to mutate the algorithm design.
|
|
254
|
+
|
|
255
|
+
> [!Note]
|
|
256
|
+
> Adjust the model name (`ai_model`) or API key as needed in the script.
|
|
257
|
+
> Changing `budget` or the HPO budget can drastically affect runtime and cost.
|
|
258
|
+
> Additional arguments (e.g., logging directories) can be set if desired.
|
|
259
|
+
|
|
260
|
+
### Running `automl_example.py`
|
|
261
|
+
|
|
262
|
+
**`automl_example.py`** uses LLaMEA to showcase that it can not only evolve and generate metaheuristics but also all kind of other algorithms, such as Machine Learning pipelines.
|
|
263
|
+
In this example, a basic classification task on the breast-cancer dataset from sklearn is solved by generating and evolving open-ended ML pipelines.
|
|
264
|
+
- We define the evaluate function (accuracy score on a hold-out test set)
|
|
265
|
+
- We provide a very basic example code to get the algorithm started.
|
|
266
|
+
- We run a few iterations and observe the excellent performance of our completely automatic ML pipeline.
|
|
267
|
+
|
|
268
|
+
**How to run:**
|
|
269
|
+
```bash
|
|
270
|
+
uv run python examples/automl_example.py
|
|
271
|
+
```
|
|
272
|
+
> [!Note]
|
|
273
|
+
> Adjust the model name (`ai_model`) or API key as needed in the script.
|
|
274
|
+
|
|
275
|
+
### Viewing conversation logs
|
|
276
|
+
|
|
277
|
+
The repository provides a minimal Flask app in `logreader/app.py` to explore
|
|
278
|
+
conversation logs stored as JSON Lines files. Start the server with a log file
|
|
279
|
+
path:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
uv run python logreader/app.py --logfile path/to/conversationlog.jsonl
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
You can also set the environment variable `CONVERSATION_LOG` instead of passing
|
|
286
|
+
`--logfile`. If neither is given, the app defaults to `conversationlog.jsonl` in
|
|
287
|
+
the current working directory. Navigate to `http://localhost:5001` to browse the
|
|
288
|
+
messages.
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## 🤖 Contributing
|
|
293
|
+
|
|
294
|
+
Contributions to LLaMEA are welcome! Here are a few ways you can help:
|
|
295
|
+
|
|
296
|
+
- **Report Bugs**: Use [GitHub Issues](https://github.com/XAI-liacs/LLaMEA/issues) to report bugs.
|
|
297
|
+
- **Feature Requests**: Suggest new features or improvements.
|
|
298
|
+
- **Pull Requests**: Submit PRs for bug fixes or feature additions.
|
|
299
|
+
|
|
300
|
+
Please refer to CONTRIBUTING.md for more details on contributing guidelines.
|
|
301
|
+
|
|
302
|
+
## 🪪 License
|
|
303
|
+
|
|
304
|
+
Distributed under the [MIT](https://choosealicense.com/licenses/mit/) License. See `LICENSE` for more information.
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
## 🤖 Reproducability
|
|
309
|
+
|
|
310
|
+
Each paper we published also has an accompanying Zenodo repository for full reproducability of all our results.
|
|
311
|
+
|
|
312
|
+
* van Stein, N. (2025). BLADE - Code and Results for the paper [Data set]. Zenodo. [https://doi.org/10.5281/zenodo.15119985](https://doi.org/10.5281/zenodo.15119985)
|
|
313
|
+
* van Stein, N., Vermetten, D., & Bäck, T. (2025). LLaMEA-HPO: code, generated algorithms and IOH logging data. [https://doi.org/10.5281/zenodo.14917719](https://doi.org/10.5281/zenodo.14917719)
|
|
314
|
+
* van Stein, N., Kononova, A. V., Kotthoff, L., & Bäck, T. (2025). Figures and code for Code Evolution Graphs. Zenodo. [https://doi.org/10.5281/zenodo.14770672](https://doi.org/10.5281/zenodo.14770672)
|
|
315
|
+
* van Stein, N., & Bäck, T. (2024). LLaMEA. Zenodo. [https://doi.org/10.5281/zenodo.13842144](https://doi.org/10.5281/zenodo.13842144)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
## ✨ Citation
|
|
319
|
+
|
|
320
|
+
If you use LLaMEA in your research, please consider citing the associated paper:
|
|
321
|
+
|
|
322
|
+
```bibtex
|
|
323
|
+
@ARTICLE{van2025llamea,
|
|
324
|
+
author={Stein, Niki van and Bäck, Thomas},
|
|
325
|
+
journal={IEEE Transactions on Evolutionary Computation},
|
|
326
|
+
title={LLaMEA: A Large Language Model Evolutionary Algorithm for Automatically Generating Metaheuristics},
|
|
327
|
+
year={2025},
|
|
328
|
+
volume={29},
|
|
329
|
+
number={2},
|
|
330
|
+
pages={331-345},
|
|
331
|
+
keywords={Benchmark testing;Evolutionary computation;Metaheuristics;Codes;Large language models;Closed box;Heuristic algorithms;Mathematical models;Vectors;Systematics;Automated code generation;evolutionary computation (EC);large language models (LLMs);metaheuristics;optimization},
|
|
332
|
+
doi={10.1109/TEVC.2024.3497793}
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
If you only want to cite the LLaMEA-HPO variant use the folllowing:
|
|
337
|
+
|
|
338
|
+
```bibtex
|
|
339
|
+
@article{van2024intheloop,
|
|
340
|
+
author = {van Stein, Niki and Vermetten, Diederick and B\"{a}ck, Thomas},
|
|
341
|
+
title = {In-the-loop Hyper-Parameter Optimization for LLM-Based Automated Design of Heuristics},
|
|
342
|
+
year = {2025},
|
|
343
|
+
publisher = {Association for Computing Machinery},
|
|
344
|
+
address = {New York, NY, USA},
|
|
345
|
+
url = {https://doi.org/10.1145/3731567},
|
|
346
|
+
doi = {10.1145/3731567},
|
|
347
|
+
note = {Just Accepted},
|
|
348
|
+
journal = {ACM Trans. Evol. Learn. Optim.},
|
|
349
|
+
month = apr,
|
|
350
|
+
keywords = {Code Generation, Heuristic Optimization, Large Language Models, Evolutionary Computation, Black-Box Optimization, Traveling Salesperson Problems}
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Other works about extensions or integrations of LLaMEA:
|
|
355
|
+
|
|
356
|
+
```bibtex
|
|
357
|
+
@InProceedings{yin2024controlling,
|
|
358
|
+
author="Yin, Haoran and Kononova, Anna V. and B{\"a}ck, Thomas and van Stein, Niki",
|
|
359
|
+
editor="Garc{\'i}a-S{\'a}nchez, Pablo and Hart, Emma and Thomson, Sarah L.",
|
|
360
|
+
title="Controlling the Mutation in Large Language Models for the Efficient Evolution of Algorithms",
|
|
361
|
+
booktitle="Applications of Evolutionary Computation",
|
|
362
|
+
year="2025",
|
|
363
|
+
publisher="Springer Nature Switzerland",
|
|
364
|
+
address="Cham",
|
|
365
|
+
pages="403--417",
|
|
366
|
+
isbn="978-3-031-90065-5"
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
---
|
|
371
|
+
|
|
372
|
+
For more details, please refer to the documentation and tutorials available in the repository.
|
|
373
|
+
|
|
374
|
+
```mermaid
|
|
375
|
+
flowchart LR
|
|
376
|
+
A[Initialization] -->|Starting prompt| B{Stop? fa:fa-hand}
|
|
377
|
+
B -->|No| C(Generate Algorithm - LLM )
|
|
378
|
+
B --> |Yes| G{{Return best so far fa:fa-code}}
|
|
379
|
+
C --> |fa:fa-code|D(Evaluate)
|
|
380
|
+
D -->|errors, scores| E[Store session history fa:fa-database]
|
|
381
|
+
E --> F(Construct Refinement Prompt)
|
|
382
|
+
F --> B
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
CodeCov test coverage
|
|
388
|
+
|
|
389
|
+
<img src="https://codecov.io/gh/XAI-liacs/LLaMEA/graphs/sunburst.svg?token=VKCNPWVBNM"/>
|
|
390
|
+
|