@@ -34,15 +34,50 @@ def build_benchmark(
3434 raise SystemExit (f"Unknown benchmark '{ benchmark_name } '. Choose one of: { choices } " ) from e
3535
3636 if task_name :
37- benchmark = benchmark .subset_from_glob ("task_name" , task_name )
38- tasks = list (set (e .task_name for e in benchmark .env_args_list ))
39- logger .warning (f'Found { len (tasks )} tasks matching "{ task_name } :" \n { tasks } , using only the first one.' )
40- task = tasks [0 ]
37+ try :
38+ benchmark = benchmark .subset_from_glob ("task_name" , task_name )
39+ tasks = sorted ({e .task_name for e in benchmark .env_args_list })
40+ if not tasks :
41+ msg = f"No tasks found matching pattern '{ task_name } '."
42+ logger .error (msg )
43+ raise SystemExit (msg )
44+ if len (tasks ) > 1 :
45+ logger .warning (
46+ "Found %d tasks matching '%s'. Using only the first: %s" ,
47+ len (tasks ),
48+ task_name ,
49+ tasks [0 ],
50+ )
51+ task = tasks [0 ]
52+ except SystemExit :
53+ raise
54+ except Exception as e :
55+ logger .error (f"Error occurred while filtering tasks: { e } " )
56+ raise SystemExit (str (e ))
4157
4258 # If specific seeds are provided, duplicate envs for each seed
4359 if seeds is not None :
4460 new_env_args_list = []
45- task_env = next ((x for x in benchmark .env_args_list if x .task_name == task ))
61+ # If a specific task was selected above, duplicate that; otherwise, ensure there is exactly one task
62+ if 'task' in locals ():
63+ task_env = next ((x for x in benchmark .env_args_list if x .task_name == task ), None )
64+ if task_env is None :
65+ msg = f"Internal error: selected task '{ task } ' not found in env list."
66+ logger .error (msg )
67+ raise SystemExit (msg )
68+ else :
69+ unique_tasks = sorted ({e .task_name for e in benchmark .env_args_list })
70+ if not unique_tasks :
71+ raise SystemExit ("No tasks available in the selected benchmark." )
72+ if len (unique_tasks ) > 1 :
73+ raise SystemExit (
74+ "Multiple tasks present in benchmark. Please specify --task-name to apply seeds to a single task."
75+ )
76+ task = unique_tasks [0 ]
77+ task_env = next ((x for x in benchmark .env_args_list if x .task_name == task ), None )
78+ if task_env is None :
79+ raise SystemExit (f"Task '{ task } ' not found in env list." )
80+
4681 for seed in seeds :
4782 ea = copy .deepcopy (task_env )
4883 ea .task_seed = seed
0 commit comments