Optiverse
A Python library for evolving code and algorithms using Large Language Models (LLMs)
Install / Use
/learn @larose/OptiverseREADME
Optiverse
Optiverse is a Python library designed for evolving code and algorithms using Large Language Models (LLMs). Inspired by Deepmind's AlphaEvolve, it provides a flexible framework to iteratively improve programs, from code snippets to full files, in any programming language.
With Optiverse, you define a problem and provide an evaluator. The system then generates and evolves candidate solutions over multiple iterations, learning which approaches yield better results.
📖 Read the announcement post: Optiverse: Evolving Code with LLMs
Table of Contents
Why Optiverse?
Optiverse helps developers and researchers automate code improvement by generating, refining, and optimizing entire programs using LLMs. Its design enables broad experimentation and fast iteration across diverse problem domains. Key capabilities include:
- Whole-file optimization: Unlike other implementations that operate on isolated functions or code blocks, Optiverse edits entire source files.
- Modular architecture: Swap or customize search strategies easily to experiment with different optimization approaches.
- Multi-language support: As long as an evaluator is provided, Optiverse can optimize code in any programming language.
- Flexible LLM integration: Compatible with any model that follows the OpenAI API standard, including OpenAI, Google Gemini, NVIDIA, and others.
Use Cases
These examples showcase Optiverse's ability to generate and refine code for a wide range of programming tasks, regardless of domain or language.
Traveling Salesman Problem
The TSP example evolved an advanced Iterated Local Search algorithm with 2-opt improvements, achieving near-optimal results on benchmark instances. The evolved solution includes sophisticated perturbation operators and performance optimizations.
Integer Compression
The integer compression example evolved a Go implementation with performance comparable to established C implementations. The evolved algorithm uses block-based delta encoding with binary packing, achieving competitive decompression speeds.
View detailed integer compression results →
Quick Start
Follow these steps to set up Optiverse and run an example.
1. Set Up Environment
First, create a virtual environment and install dependencies:
make init
Then, activate the virtual environment:
source venv/bin/activate
2. Run the Traveling Salesman Problem example:
This example uses Optiverse to solve the Traveling Salesman Problem (TSP). The code is in the examples/tsp directory.
The example supports multiple LLM providers through environment variables:
LLM_API_KEY: Your API key for the chosen providerLLM_MODEL: The model name to useLLM_PROVIDER: The provider name (openai,google, ornvidia)
Example with Google Gemini:
LLM_API_KEY="your-gemini-api-key" LLM_MODEL="gemini-2.0-flash" LLM_PROVIDER="google" make run.tsp
Note: Optiverse uses the OpenAI package under the hood, so it supports any LLM provider that follows the OpenAI API standard.
Sample Output:
When you run it, you'll see output like this:
2025-07-17 09:35:47 - optiverse.optimizer - INFO - Evaluating and saving initial solution...
2025-07-17 09:35:47 - examples.tsp.evaluator - INFO - Score 1: 33800.20318013358
2025-07-17 09:35:47 - examples.tsp.evaluator - INFO - Score 2: 32719.233809839046
2025-07-17 09:35:48 - examples.tsp.evaluator - INFO - Score 3: 35557.94658416552
2025-07-17 09:35:48 - optiverse.optimizer - INFO - Initial solution saved with ID: d3c1a4eb294e469593b52ee805d7028b, score: 34025.79452471271
2025-07-17 09:35:48 - optiverse.optimizer - INFO - Starting iteration 1/100
2025-07-17 09:35:50 - httpx - INFO - HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/openai/chat/completions "HTTP/1.1 200 OK"
2025-07-17 09:35:51 - optiverse.solution_generator - INFO - No code blocks found in LLM response
2025-07-17 09:35:51 - optiverse.optimizer - INFO - No code generated by solution generator
2025-07-17 09:35:51 - optiverse.optimizer - INFO - Starting iteration 2/100
2025-07-17 09:35:52 - httpx - INFO - HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/openai/chat/completions "HTTP/1.1 200 OK"
2025-07-17 09:35:58 - optiverse.optimizer - INFO - Evaluating solution
2025-07-17 09:36:09 - examples.tsp.evaluator - INFO - Score 1: 3149.0239046268334
2025-07-17 09:36:21 - examples.tsp.evaluator - INFO - Score 2: 3200.6735649311436
2025-07-17 09:36:30 - examples.tsp.evaluator - INFO - Score 3: 3089.4221942253616
2025-07-17 09:36:30 - optiverse.optimizer - INFO - Evaluation result: 3146.3732212611126
2025-07-17 09:36:30 - optiverse.optimizer - INFO - Saved solution with ID: 564d577d222a42ba8e1defb0dd2870e3
...
Understanding the Results
During optimization, Optiverse saves results in directories named tmp/YYYYMMDD_HHMM, indicating the date and time of each run.
solutions.csv
Inside each run directory, solutions.csv provides a high-level overview of all solutions explored:
| id | score | t_group | t_move | t_parent_id_1 | ... | |------------------------------------|-----------------|---------|-------------|-------------------------------|-----| | 0d8c5789dde24a94901871c18d6d9854 | 2817.0555492637 | 1 | exploitation| 034afd2da8894ab6838efb17bc28f201 | ... | | a42574709f27484fade7adc76683b2cf | 2828.6215589938 | 6 | exploitation| 96c7140054154a20a4b67fd986658dd4 | ... | | 883f6de275c14b32822feb5cdaaba55d | 2837.3500311898 | 6 | exploitation| a42574709f27484fade7adc76683b2cf | ... |
Individual Solution Directories
Each solution has a dedicated directory named after its ID, containing:
prompt.md: The prompt sent to the LLM.solution.txt: The code generated by the LLM.description.txt: The LLM's own explanation of the changes it made.metadata.json: Metadata including ID and score.*_stdout.txtand*_stderr.txt: Program logs for debugging.
License
Optiverse is open source and licensed under the GNU General Public License v3.0 (GPLv3).
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
