Manages evolution trace logging with support for multiple formats
| 61 | |
| 62 | |
| 63 | class EvolutionTracer: |
| 64 | """Manages evolution trace logging with support for multiple formats""" |
| 65 | |
| 66 | def __init__( |
| 67 | self, |
| 68 | output_path: Optional[str] = None, |
| 69 | format: str = "jsonl", |
| 70 | include_code: bool = False, |
| 71 | include_prompts: bool = True, |
| 72 | enabled: bool = True, |
| 73 | buffer_size: int = 10, |
| 74 | compress: bool = False, |
| 75 | include_changes_description: bool = True, |
| 76 | ): |
| 77 | """ |
| 78 | Initialize the evolution tracer |
| 79 | |
| 80 | Args: |
| 81 | output_path: Path to save trace data |
| 82 | format: Output format ('jsonl', 'json', 'hdf5') |
| 83 | include_code: Whether to include full code in traces |
| 84 | include_prompts: Whether to include prompts and LLM responses |
| 85 | enabled: Whether tracing is enabled |
| 86 | buffer_size: Number of traces to buffer before writing |
| 87 | compress: Whether to compress output files |
| 88 | include_changes_description: Whether to include per-program changes descriptions |
| 89 | """ |
| 90 | self.enabled = enabled |
| 91 | self.format = format |
| 92 | self.include_code = include_code |
| 93 | self.include_prompts = include_prompts |
| 94 | self.include_changes_description = include_changes_description |
| 95 | self.compress = compress |
| 96 | self.buffer_size = buffer_size |
| 97 | |
| 98 | # Track statistics |
| 99 | self.stats = { |
| 100 | "total_traces": 0, |
| 101 | "improvement_count": 0, |
| 102 | "total_improvement": {}, |
| 103 | "best_improvement": {}, |
| 104 | "worst_decline": {}, |
| 105 | } |
| 106 | |
| 107 | if not self.enabled: |
| 108 | logger.info("Evolution tracing is disabled") |
| 109 | return |
| 110 | |
| 111 | # Set up output path |
| 112 | if output_path: |
| 113 | self.output_path = Path(output_path) |
| 114 | else: |
| 115 | self.output_path = Path(f"evolution_trace.{format}") |
| 116 | |
| 117 | # Add compression extension if needed |
| 118 | if self.compress and format == "jsonl": |
| 119 | self.output_path = self.output_path.with_suffix(".jsonl.gz") |
| 120 |
no outgoing calls