Evaluate a pipeline configuration program. Args: program_path: Path to the Python file containing configure_pipeline() Returns: dict with 'metrics' and optionally 'artifacts'
(program_path: str)
| 46 | |
| 47 | |
| 48 | def evaluate(program_path: str) -> dict: |
| 49 | """ |
| 50 | Evaluate a pipeline configuration program. |
| 51 | |
| 52 | Args: |
| 53 | program_path: Path to the Python file containing configure_pipeline() |
| 54 | |
| 55 | Returns: |
| 56 | dict with 'metrics' and optionally 'artifacts' |
| 57 | """ |
| 58 | start_time = time.time() |
| 59 | |
| 60 | try: |
| 61 | # Load and execute the program |
| 62 | spec = importlib.util.spec_from_file_location("program", program_path) |
| 63 | module = importlib.util.module_from_spec(spec) |
| 64 | sys.modules["program"] = module |
| 65 | spec.loader.exec_module(module) |
| 66 | |
| 67 | # Get the configuration |
| 68 | if hasattr(module, 'run_pipeline'): |
| 69 | config = module.run_pipeline() |
| 70 | elif hasattr(module, 'configure_pipeline'): |
| 71 | config = module.configure_pipeline() |
| 72 | else: |
| 73 | return _error_result("Program must define run_pipeline() or configure_pipeline()") |
| 74 | |
| 75 | # Validate the configuration |
| 76 | validation_errors = validate_config(config) |
| 77 | if validation_errors: |
| 78 | return _validation_error_result(validation_errors) |
| 79 | |
| 80 | # Score the configuration |
| 81 | correct_count, module_results = score_config(config) |
| 82 | |
| 83 | # Calculate metrics |
| 84 | accuracy = correct_count / NUM_MODULES |
| 85 | |
| 86 | # The combined score rewards finding more correct modules |
| 87 | # but gives NO information about which modules are correct |
| 88 | combined_score = accuracy |
| 89 | |
| 90 | eval_time = time.time() - start_time |
| 91 | |
| 92 | # Build artifacts - provide feedback that helps evolution |
| 93 | # but doesn't reveal which specific modules are wrong |
| 94 | artifacts = build_artifacts(config, correct_count, module_results, eval_time) |
| 95 | |
| 96 | # Return metrics at top level for OpenEvolve compatibility |
| 97 | return { |
| 98 | "correct_modules": correct_count, |
| 99 | "total_modules": NUM_MODULES, |
| 100 | "accuracy": accuracy, |
| 101 | "combined_score": combined_score, |
| 102 | "eval_time": eval_time, |
| 103 | "artifacts": artifacts, |
| 104 | } |
| 105 |
no test coverage detected