Run evolution with flexible inputs - this is the main library API. Args: initial_program: Can be a path to a program file, the program code as a string, or a list of code lines. evaluator: Can be a path to an evaluator file or a Python callable that takes a program_path and
(
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,
)
| 34 | |
| 35 | |
| 36 | def run_evolution( |
| 37 | initial_program: Union[str, Path, List[str]], |
| 38 | evaluator: Union[str, Path, Callable], |
| 39 | config: Union[str, Path, Config, None] = None, |
| 40 | iterations: Optional[int] = None, |
| 41 | output_dir: Optional[str] = None, |
| 42 | cleanup: bool = True, |
| 43 | ) -> EvolutionResult: |
| 44 | """ |
| 45 | Run evolution with flexible inputs - this is the main library API. |
| 46 | |
| 47 | Args: |
| 48 | initial_program: Can be a path to a program file, the program code as a string, or a list of code lines. |
| 49 | evaluator: Can be a path to an evaluator file or a Python callable that takes a program_path and returns a metrics dict. |
| 50 | config: Can be a path to a config YAML file, a Config object, or None to use defaults. |
| 51 | iterations: Number of iterations to run (overrides the value in the config). |
| 52 | output_dir: Directory to save outputs (a temporary directory is used if None). |
| 53 | cleanup: If True, temporary files and directories created during the run will be deleted. |
| 54 | |
| 55 | Returns: |
| 56 | An EvolutionResult object containing the best program and its metrics. |
| 57 | """ |
| 58 | # Use asyncio.run to execute the asynchronous implementation of the evolution process. |
| 59 | return asyncio.run( |
| 60 | _run_evolution_async(initial_program, evaluator, config, iterations, output_dir, cleanup) |
| 61 | ) |
| 62 | |
| 63 | |
| 64 | async def _run_evolution_async( |
no test coverage detected