Skip to content

Commit 7b673a7

Browse files
authored
Merge pull request #256 from codelion/fix-islands-map-conflict
Fix islands map conflict
2 parents 025f00b + 812cace commit 7b673a7

35 files changed

+4028
-252
lines changed

.github/workflows/python-test.yml

Lines changed: 89 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,96 @@
1-
name: Python Unit Tests
1+
name: Tests
22

33
on: [push, pull_request]
44

55
jobs:
6-
test:
6+
unit-tests:
77
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout code
10+
uses: actions/checkout@v3
11+
12+
- name: Set up Python
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: '3.10'
16+
17+
- name: Cache pip packages
18+
uses: actions/cache@v3
19+
with:
20+
path: ~/.cache/pip
21+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
22+
restore-keys: |
23+
${{ runner.os }}-pip-
824
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -e ".[dev]"
29+
30+
- name: Run unit tests
31+
env:
32+
OPENAI_API_KEY: test # Mock API key for unit tests
33+
run: |
34+
# Run unit tests (all tests except integration/)
35+
python -m unittest discover -s tests -p "test_*.py" -v
36+
37+
integration-tests:
38+
needs: unit-tests # Only run if unit tests pass
39+
runs-on: ubuntu-latest
40+
timeout-minutes: 30 # Limit integration tests to 30 minutes
941
steps:
10-
- name: Checkout code
11-
uses: actions/checkout@v3
12-
13-
- name: Set up Python
14-
uses: actions/setup-python@v4
15-
with:
16-
python-version: '3.9'
17-
18-
- name: Install dependencies
19-
run: |
20-
python -m pip install --upgrade pip
21-
pip install -e .
22-
# Install test dependencies
23-
pip install pytest numpy
24-
25-
- name: Run unit tests
26-
env:
27-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
28-
run: |
29-
python -m unittest discover -s tests -p "test_*.py" -v
42+
- name: Checkout code
43+
uses: actions/checkout@v3
44+
45+
- name: Set up Python
46+
uses: actions/setup-python@v4
47+
with:
48+
python-version: '3.10'
49+
50+
- name: Cache pip packages
51+
uses: actions/cache@v3
52+
with:
53+
path: ~/.cache/pip
54+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
55+
restore-keys: |
56+
${{ runner.os }}-pip-
57+
58+
- name: Install dependencies
59+
run: |
60+
python -m pip install --upgrade pip
61+
pip install -e ".[dev]"
62+
pip install optillm
63+
64+
- name: Start optillm server
65+
run: |
66+
echo "Starting optillm server for integration tests..."
67+
OPTILLM_API_KEY=optillm HF_TOKEN=${{ secrets.HF_TOKEN }} optillm --model google/gemma-3-270m-it --port 8000 &
68+
echo $! > server.pid
69+
70+
# Wait for server to be ready
71+
echo "Waiting for server to start..."
72+
sleep 15
73+
74+
# Test server health
75+
curl -s http://localhost:8000/health || echo "Server health check failed"
76+
env:
77+
OPTILLM_API_KEY: optillm
78+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
79+
80+
- name: Run integration tests (excluding slow tests)
81+
env:
82+
OPENAI_API_KEY: optillm
83+
OPTILLM_API_KEY: optillm
84+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
85+
run: |
86+
# Run only fast integration tests, skip slow tests that require real LLM
87+
pytest tests/integration -v --tb=short -m "not slow"
88+
89+
- name: Stop optillm server
90+
if: always()
91+
run: |
92+
if [ -f server.pid ]; then
93+
kill $(cat server.pid) || true
94+
rm server.pid
95+
fi
96+
pkill -f "optillm.*8000" || true

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ YAML-based configuration with hierarchical structure:
110110

111111
### Development Notes
112112

113-
- Python >=3.9 required
113+
- Python >=3.10 required
114114
- Uses OpenAI-compatible APIs for LLM integration
115115
- Tests use unittest framework
116116
- Black for code formatting

Makefile

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ PIP := $(VENV_DIR)/bin/pip
99
.PHONY: help
1010
help:
1111
@echo "Available targets:"
12-
@echo " all - Install dependencies and run tests"
13-
@echo " venv - Create a virtual environment"
14-
@echo " install - Install Python dependencies"
15-
@echo " lint - Run Black code formatting"
16-
@echo " test - Run tests"
17-
@echo " docker-build - Build the Docker image"
18-
@echo " docker-run - Run the Docker container with the example"
19-
@echo " visualizer - Run the visualization script"
12+
@echo " all - Install dependencies and run unit tests"
13+
@echo " venv - Create a virtual environment"
14+
@echo " install - Install Python dependencies"
15+
@echo " install-dev - Install development dependencies including optillm"
16+
@echo " lint - Run Black code formatting"
17+
@echo " test - Run unit tests only"
18+
@echo " test-unit - Run unit tests only (same as test)"
19+
@echo " test-integration - Run integration tests with local LLM"
20+
@echo " test-all - Run both unit and integration tests"
21+
@echo " docker-build - Build the Docker image"
22+
@echo " docker-run - Run the Docker container with the example"
23+
@echo " visualizer - Run the visualization script"
2024

2125
.PHONY: all
2226
all: install test
@@ -31,16 +35,55 @@ venv:
3135
install: venv
3236
$(PIP) install -e .
3337

38+
# Install development dependencies including optillm for integration tests
39+
.PHONY: install-dev
40+
install-dev: venv
41+
$(PIP) install -e .
42+
$(PIP) install pytest optillm
43+
3444
# Run Black code formatting
3545
.PHONY: lint
3646
lint: venv
3747
$(PYTHON) -m black openevolve examples tests scripts
3848

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

54+
# Alias for test
55+
.PHONY: test-unit
56+
test-unit: test
57+
58+
# Run integration tests with local LLM (requires optillm)
59+
.PHONY: test-integration
60+
test-integration: install-dev
61+
@echo "Starting optillm server for integration tests..."
62+
@OPTILLM_API_KEY=optillm $(VENV_DIR)/bin/optillm --model google/gemma-3-270m-it --port 8000 &
63+
@OPTILLM_PID=$$! && \
64+
echo $$OPTILLM_PID > /tmp/optillm.pid && \
65+
echo "Waiting for optillm server to start..." && \
66+
sleep 10 && \
67+
echo "Running integration tests..." && \
68+
OPENAI_API_KEY=optillm $(PYTHON) -m pytest tests/integration -v --tb=short; \
69+
TEST_EXIT_CODE=$$?; \
70+
echo "Stopping optillm server..."; \
71+
kill $$OPTILLM_PID 2>/dev/null || true; \
72+
pkill -f "optillm.*8000" 2>/dev/null || true; \
73+
rm -f /tmp/optillm.pid; \
74+
exit $$TEST_EXIT_CODE
75+
76+
# Run integration tests with existing optillm server (for development)
77+
.PHONY: test-integration-dev
78+
test-integration-dev: venv
79+
@echo "Using existing optillm server at localhost:8000"
80+
@curl -s http://localhost:8000/health > /dev/null || (echo "Error: optillm server not running at localhost:8000" && exit 1)
81+
OPENAI_API_KEY=optillm $(PYTHON) -m pytest tests/integration -v
82+
83+
# Run all tests (unit first, then integration)
84+
.PHONY: test-all
85+
test-all: test test-integration
86+
4487
# Build the Docker image
4588
.PHONY: docker-build
4689
docker-build:

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,40 @@ print(f'Best score: {result.best_score:.4f}')
9494
"
9595
```
9696

97+
### 📚 **Library Usage**
98+
99+
OpenEvolve can be used as a library without any external files:
100+
101+
```python
102+
from openevolve import run_evolution, evolve_function
103+
104+
# Evolution with inline code (no files needed!)
105+
result = run_evolution(
106+
initial_program='''
107+
def fibonacci(n):
108+
if n <= 1: return n
109+
return fibonacci(n-1) + fibonacci(n-2)
110+
''',
111+
evaluator=lambda path: {"score": benchmark_fib(path)},
112+
iterations=100
113+
)
114+
115+
# Evolve Python functions directly
116+
def bubble_sort(arr):
117+
for i in range(len(arr)):
118+
for j in range(len(arr)-1):
119+
if arr[j] > arr[j+1]:
120+
arr[j], arr[j+1] = arr[j+1], arr[j]
121+
return arr
122+
123+
result = evolve_function(
124+
bubble_sort,
125+
test_cases=[([3,1,2], [1,2,3]), ([5,2,8], [2,5,8])],
126+
iterations=50
127+
)
128+
print(f"Evolved sorting algorithm: {result.best_code}")
129+
```
130+
97131
**Want more control?** Use the full CLI:
98132

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

215249
### Requirements
216-
- **Python**: 3.9+
250+
- **Python**: 3.10+
217251
- **LLM Access**: Any OpenAI-compatible API
218252
- **Optional**: Docker for containerized runs
219253

openevolve/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,20 @@
44

55
from openevolve._version import __version__
66
from openevolve.controller import OpenEvolve
7+
from openevolve.api import (
8+
run_evolution,
9+
evolve_function,
10+
evolve_algorithm,
11+
evolve_code,
12+
EvolutionResult
13+
)
714

8-
__all__ = ["OpenEvolve", "__version__"]
15+
__all__ = [
16+
"OpenEvolve",
17+
"__version__",
18+
"run_evolution",
19+
"evolve_function",
20+
"evolve_algorithm",
21+
"evolve_code",
22+
"EvolutionResult"
23+
]

openevolve/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Version information for openevolve package."""
22

3-
__version__ = "0.2.11"
3+
__version__ = "0.2.12"

0 commit comments

Comments
 (0)