Skip to content

Commit 37ba871

Browse files
committed
fxies
1 parent 3171fa0 commit 37ba871

File tree

4 files changed

+875
-1
lines changed

4 files changed

+875
-1
lines changed

README.md

Lines changed: 34 additions & 0 deletions
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

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+
]

0 commit comments

Comments
 (0)