Test specified optimizer performance on entire benchmark dataset with concurrency control.
(optimizer_type: str, benchmark_name: str, experiment_file: str, concurrency: int = 4)
| 395 | |
| 396 | |
| 397 | async def run_optimizer_on_benchmark(optimizer_type: str, benchmark_name: str, experiment_file: str, concurrency: int = 4): |
| 398 | """Test specified optimizer performance on entire benchmark dataset with concurrency control.""" |
| 399 | logger.info(f"| 🧪 Testing {optimizer_type.upper()} optimizer on complete benchmark: {benchmark_name}") |
| 400 | logger.info(f"| ⚡ Using concurrency level: {concurrency}") |
| 401 | |
| 402 | # Get all tasks first |
| 403 | all_tasks = await get_all_incorrect_tasks(experiment_file, benchmark_name) |
| 404 | total_tasks = len(all_tasks) |
| 405 | |
| 406 | if total_tasks == 0: |
| 407 | logger.warning("⚠️ No tasks available to run (Dataset empty or all finished).") |
| 408 | return |
| 409 | |
| 410 | logger.info(f"| 📋 Total tasks to process: {total_tasks}") |
| 411 | |
| 412 | # Initialize result saver |
| 413 | model_name = 'openrouter/gemini-3-flash-preview' |
| 414 | result_saver = ExperimentResultSaver(optimizer_type, benchmark_name, concurrency, total_tasks, model_name) |
| 415 | logger.info(f"| 💾 Results will be saved to: {result_saver.get_file_path()}") |
| 416 | |
| 417 | # Create semaphore for concurrency control |
| 418 | semaphore = asyncio.Semaphore(concurrency) |
| 419 | completed_count = 0 |
| 420 | |
| 421 | async def process_with_semaphore(task_data: Dict, task_index: int): |
| 422 | """Process a task with semaphore control.""" |
| 423 | nonlocal completed_count |
| 424 | async with semaphore: |
| 425 | try: |
| 426 | await process_single_task(optimizer_type, benchmark_name, task_data, task_index, total_tasks, result_saver) |
| 427 | finally: |
| 428 | completed_count += 1 |
| 429 | # Progress reporting |
| 430 | if completed_count % concurrency == 0 or completed_count == total_tasks: |
| 431 | progress_msg = f"| 📊 Progress: {completed_count}/{total_tasks} tasks completed" |
| 432 | logger.info(progress_msg) |
| 433 | print(progress_msg) |
| 434 | |
| 435 | # Create all tasks and run them with semaphore-controlled concurrency |
| 436 | tasks = [process_with_semaphore(task_data, i) for i, task_data in enumerate(all_tasks)] |
| 437 | await asyncio.gather(*tasks) |
| 438 | |
| 439 | logger.info(f"| ✅ All {total_tasks} tasks completed for {optimizer_type.upper()} optimizer") |
| 440 | |
| 441 | |
| 442 | async def main(): |
no test coverage detected