MCPcopy Create free account
hub / github.com/algorithmicsuperintelligence/openevolve / run_evolution

Function run_evolution

openevolve/api.py:33–94  ·  view source on GitHub ↗

Run evolution with flexible inputs - the main library API Args: initial_program: Can be: - Path to a program file (str or Path) - Program code as a string - List of code lines evaluator: Can be: - Path to an evaluator file (st

(
    initial_program: Union[str, Path, List[str]],
    evaluator: Union[str, Path, Callable],
    config: Union[str, Path, Config, None] = None,
    iterations: Optional[int] = None,
    output_dir: Optional[str] = None,
    cleanup: bool = True,
)

Source from the content-addressed store, hash-verified

31
32
33def run_evolution(
34 initial_program: Union[str, Path, List[str]],
35 evaluator: Union[str, Path, Callable],
36 config: Union[str, Path, Config, None] = None,
37 iterations: Optional[int] = None,
38 output_dir: Optional[str] = None,
39 cleanup: bool = True,
40) -> EvolutionResult:
41 """
42 Run evolution with flexible inputs - the main library API
43
44 Args:
45 initial_program: Can be:
46 - Path to a program file (str or Path)
47 - Program code as a string
48 - List of code lines
49 evaluator: Can be:
50 - Path to an evaluator file (str or Path)
51 - Callable function that takes (program_path) and returns metrics dict
52 config: Can be:
53 - Path to config YAML file (str or Path)
54 - Config object
55 - None for defaults
56 iterations: Number of iterations (overrides config)
57 output_dir: Output directory (None for temp directory)
58 cleanup: If True, clean up temp files after evolution
59
60 Returns:
61 EvolutionResult with best program and metrics
62
63 Examples:
64 # Using file paths (original way)
65 result = run_evolution(
66 'program.py',
67 'evaluator.py'
68 )
69
70 # Using code strings
71 result = run_evolution(
72 initial_program='''
73 # EVOLVE-BLOCK-START
74 def solve(x):
75 return x * 2
76 # EVOLVE-BLOCK-END
77 ''',
78 evaluator=lambda path: {"score": evaluate_program(path)},
79 iterations=100
80 )
81
82 # Using a custom evaluator function
83 def my_evaluator(program_path):
84 # Run tests, benchmarks, etc.
85 return {"score": 0.95, "runtime": 1.2}
86
87 result = run_evolution(
88 initial_program=generate_initial_code(),
89 evaluator=my_evaluator
90 )

Calls 2

_run_evolution_asyncFunction · 0.85
runMethod · 0.45