|
3 | 3 | """Get instances based on specific pattern.""" |
4 | 4 |
|
5 | 5 | import argparse |
6 | | -from pathlib import Path |
7 | 6 | from collections import defaultdict |
8 | | -from pyexpat import model |
| 7 | +from pathlib import Path |
9 | 8 |
|
10 | 9 | from codeclash.analysis.llm_as_judge.utils import InstanceBatch, get_instances |
11 | 10 |
|
|
16 | 15 | args = parser.parse_args() |
17 | 16 |
|
18 | 17 | SELECTED_ROUNDS = [1, 2, 3, 5, 10, 12, 14, 15] |
19 | | - SELECTED_GAME = "BattleSnake" |
20 | | - NUMBER_OF_INDEPENDENT_GAMES = 3 |
| 18 | + SELECTED_GAMES = ["BattleSnake"] # Set to None to select all games |
| 19 | + NUMBER_OF_TOURNAMENTS = 3 |
21 | 20 |
|
22 | 21 | # first get all instances, then filter |
23 | 22 | instances = sorted(get_instances(args.input_dir), key=lambda x: x.instance_id) |
24 | 23 | print(f"Found {len(instances)} instances") |
25 | | - instances = [instance for instance in instances if SELECTED_GAME in instance.tournament_name] |
26 | | - print(f"Filtered to {len(instances)} instances because of game name") |
| 24 | + if SELECTED_GAMES is not None: |
| 25 | + instances = [ |
| 26 | + instance for instance in instances if any(game in instance.tournament_name for game in SELECTED_GAMES) |
| 27 | + ] |
| 28 | + print(f"Filtered to {len(instances)} instances because of game name") |
| 29 | + else: |
| 30 | + print("No game filtering applied (SELECTED_GAMES is None)") |
27 | 31 | instances = [instance for instance in instances if instance.round_number in SELECTED_ROUNDS] |
28 | 32 | print(f"Filtered to {len(instances)} instances because of round number") |
29 | 33 |
|
|
34 | 38 | continue |
35 | 39 | key = (model_name_player, model_name_opponent, instance.round_number) |
36 | 40 | grouped[key].append(instance) |
37 | | - |
| 41 | + |
38 | 42 | selected_instances = [] |
39 | 43 | for key, instance_list in grouped.items(): |
40 | | - if len(instance_list) < NUMBER_OF_INDEPENDENT_GAMES: |
41 | | - print(f"Warning: Only found {len(instance_list)} instances for {key}, need {NUMBER_OF_INDEPENDENT_GAMES}") |
42 | | - selected_count = min(len(instance_list), NUMBER_OF_INDEPENDENT_GAMES) |
| 44 | + if len(instance_list) < NUMBER_OF_TOURNAMENTS: |
| 45 | + print(f"Warning: Only found {len(instance_list)} instances for {key}, need {NUMBER_OF_TOURNAMENTS}") |
| 46 | + selected_count = min(len(instance_list), NUMBER_OF_TOURNAMENTS) |
43 | 47 | selected_instances.extend(instance_list[:selected_count]) |
44 | | - |
| 48 | + |
45 | 49 | instances = selected_instances |
46 | | - unique_models = set([instance.get_lm_name_self_opponent()[0] for instance in instances]) |
47 | | - print(f"Filtered to {len(instances)} instances after keeping {NUMBER_OF_INDEPENDENT_GAMES} for game repetitions for {len(unique_models)} unique model matchups") |
| 50 | + unique_models = {instance.get_lm_name_self_opponent()[0] for instance in instances} |
| 51 | + print( |
| 52 | + f"Filtered to {len(instances)} instances after keeping {NUMBER_OF_TOURNAMENTS} for game repetitions for {len(unique_models)} unique model matchups" |
| 53 | + ) |
48 | 54 |
|
49 | 55 | batch = InstanceBatch(instances=instances) |
50 | 56 | args.output_file.write_text(batch.model_dump_json()) |
|
0 commit comments