Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 89 additions & 22 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,96 @@
name: Python Unit Tests
name: Tests

on: [push, pull_request]

jobs:
test:
unit-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Cache pip packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"

- name: Run unit tests
env:
OPENAI_API_KEY: test # Mock API key for unit tests
run: |
# Run unit tests (all tests except integration/)
python -m unittest discover -s tests -p "test_*.py" -v

integration-tests:
needs: unit-tests # Only run if unit tests pass
runs-on: ubuntu-latest
timeout-minutes: 30 # Limit integration tests to 30 minutes
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
# Install test dependencies
pip install pytest numpy

- name: Run unit tests
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
python -m unittest discover -s tests -p "test_*.py" -v
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Cache pip packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
pip install optillm

- name: Start optillm server
run: |
echo "Starting optillm server for integration tests..."
OPTILLM_API_KEY=optillm HF_TOKEN=${{ secrets.HF_TOKEN }} optillm --model google/gemma-3-270m-it --port 8000 &
echo $! > server.pid

# Wait for server to be ready
echo "Waiting for server to start..."
sleep 15

# Test server health
curl -s http://localhost:8000/health || echo "Server health check failed"
env:
OPTILLM_API_KEY: optillm
HF_TOKEN: ${{ secrets.HF_TOKEN }}

- name: Run integration tests (excluding slow tests)
env:
OPENAI_API_KEY: optillm
OPTILLM_API_KEY: optillm
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
# Run only fast integration tests, skip slow tests that require real LLM
pytest tests/integration -v --tb=short -m "not slow"

- name: Stop optillm server
if: always()
run: |
if [ -f server.pid ]; then
kill $(cat server.pid) || true
rm server.pid
fi
pkill -f "optillm.*8000" || true
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ YAML-based configuration with hierarchical structure:

### Development Notes

- Python >=3.9 required
- Python >=3.10 required
- Uses OpenAI-compatible APIs for LLM integration
- Tests use unittest framework
- Black for code formatting
Expand Down
61 changes: 52 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ PIP := $(VENV_DIR)/bin/pip
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Install dependencies and run tests"
@echo " venv - Create a virtual environment"
@echo " install - Install Python dependencies"
@echo " lint - Run Black code formatting"
@echo " test - Run tests"
@echo " docker-build - Build the Docker image"
@echo " docker-run - Run the Docker container with the example"
@echo " visualizer - Run the visualization script"
@echo " all - Install dependencies and run unit tests"
@echo " venv - Create a virtual environment"
@echo " install - Install Python dependencies"
@echo " install-dev - Install development dependencies including optillm"
@echo " lint - Run Black code formatting"
@echo " test - Run unit tests only"
@echo " test-unit - Run unit tests only (same as test)"
@echo " test-integration - Run integration tests with local LLM"
@echo " test-all - Run both unit and integration tests"
@echo " docker-build - Build the Docker image"
@echo " docker-run - Run the Docker container with the example"
@echo " visualizer - Run the visualization script"

.PHONY: all
all: install test
Expand All @@ -31,16 +35,55 @@ venv:
install: venv
$(PIP) install -e .

# Install development dependencies including optillm for integration tests
.PHONY: install-dev
install-dev: venv
$(PIP) install -e .
$(PIP) install pytest optillm

# Run Black code formatting
.PHONY: lint
lint: venv
$(PYTHON) -m black openevolve examples tests scripts

# Run tests using the virtual environment
# Run unit tests only (fast, no LLM required)
.PHONY: test
test: venv
$(PYTHON) -m unittest discover -s tests -p "test_*.py"

# Alias for test
.PHONY: test-unit
test-unit: test

# Run integration tests with local LLM (requires optillm)
.PHONY: test-integration
test-integration: install-dev
@echo "Starting optillm server for integration tests..."
@OPTILLM_API_KEY=optillm $(VENV_DIR)/bin/optillm --model google/gemma-3-270m-it --port 8000 &
@OPTILLM_PID=$$! && \
echo $$OPTILLM_PID > /tmp/optillm.pid && \
echo "Waiting for optillm server to start..." && \
sleep 10 && \
echo "Running integration tests..." && \
OPENAI_API_KEY=optillm $(PYTHON) -m pytest tests/integration -v --tb=short; \
TEST_EXIT_CODE=$$?; \
echo "Stopping optillm server..."; \
kill $$OPTILLM_PID 2>/dev/null || true; \
pkill -f "optillm.*8000" 2>/dev/null || true; \
rm -f /tmp/optillm.pid; \
exit $$TEST_EXIT_CODE

# Run integration tests with existing optillm server (for development)
.PHONY: test-integration-dev
test-integration-dev: venv
@echo "Using existing optillm server at localhost:8000"
@curl -s http://localhost:8000/health > /dev/null || (echo "Error: optillm server not running at localhost:8000" && exit 1)
OPENAI_API_KEY=optillm $(PYTHON) -m pytest tests/integration -v

# Run all tests (unit first, then integration)
.PHONY: test-all
test-all: test test-integration

# Build the Docker image
.PHONY: docker-build
docker-build:
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,40 @@ print(f'Best score: {result.best_score:.4f}')
"
```

### 📚 **Library Usage**

OpenEvolve can be used as a library without any external files:

```python
from openevolve import run_evolution, evolve_function

# Evolution with inline code (no files needed!)
result = run_evolution(
initial_program='''
def fibonacci(n):
if n <= 1: return n
return fibonacci(n-1) + fibonacci(n-2)
''',
evaluator=lambda path: {"score": benchmark_fib(path)},
iterations=100
)

# Evolve Python functions directly
def bubble_sort(arr):
for i in range(len(arr)):
for j in range(len(arr)-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr

result = evolve_function(
bubble_sort,
test_cases=[([3,1,2], [1,2,3]), ([5,2,8], [2,5,8])],
iterations=50
)
print(f"Evolved sorting algorithm: {result.best_code}")
```

**Want more control?** Use the full CLI:

```bash
Expand Down Expand Up @@ -213,7 +247,7 @@ OpenEvolve implements a sophisticated **evolutionary coding pipeline** that goes
## 🛠 Installation & Setup

### Requirements
- **Python**: 3.9+
- **Python**: 3.10+
- **LLM Access**: Any OpenAI-compatible API
- **Optional**: Docker for containerized runs

Expand Down
17 changes: 16 additions & 1 deletion openevolve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,20 @@

from openevolve._version import __version__
from openevolve.controller import OpenEvolve
from openevolve.api import (
run_evolution,
evolve_function,
evolve_algorithm,
evolve_code,
EvolutionResult
)

__all__ = ["OpenEvolve", "__version__"]
__all__ = [
"OpenEvolve",
"__version__",
"run_evolution",
"evolve_function",
"evolve_algorithm",
"evolve_code",
"EvolutionResult"
]
2 changes: 1 addition & 1 deletion openevolve/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version information for openevolve package."""

__version__ = "0.2.11"
__version__ = "0.2.12"
Loading