@@ -42,6 +42,42 @@ def load_instance(instance_id: str) -> dict[str, Any]:
4242 raise SystemExit (f"instance not found in { DATASET } : { instance_id } " )
4343
4444
45+ def select_instances (count : int , seed : str , explicit : str ) -> list [str ]:
46+ if count <= 0 :
47+ selected = json .loads (explicit )
48+ if not isinstance (selected , list ) or not all (isinstance (item , str ) for item in selected ):
49+ raise SystemExit ("--explicit must be a JSON list of instance IDs" )
50+ return selected
51+
52+ from datasets import load_dataset
53+
54+ dataset = load_dataset (DATASET , split = "test" )
55+ ranked = sorted (
56+ dataset ,
57+ key = lambda row : hashlib .sha256 (
58+ f"{ seed } :{ row ['instance_id' ]} " .encode ()
59+ ).hexdigest (),
60+ )
61+ selected : list [str ] = []
62+ seen_repos : set [str ] = set ()
63+ for row in ranked :
64+ instance_id = str (row ["instance_id" ])
65+ repo = str (row ["repo" ])
66+ if instance_id == "sympy__sympy-20590" :
67+ continue
68+ if repo in seen_repos :
69+ continue
70+ selected .append (instance_id )
71+ seen_repos .add (repo )
72+ if len (selected ) == count :
73+ break
74+ if len (selected ) < count :
75+ raise SystemExit (
76+ f"requested { count } unique-repository tasks but only found { len (selected )} "
77+ )
78+ return selected
79+
80+
4581def prepare (instance_id : str , workspace : Path ) -> None :
4682 workspace = workspace .resolve ()
4783 target = workspace / "target"
@@ -181,6 +217,12 @@ def main() -> int:
181217 parser = argparse .ArgumentParser ()
182218 sub = parser .add_subparsers (dest = "command" , required = True )
183219
220+ sel = sub .add_parser ("select" )
221+ sel .add_argument ("--count" , type = int , required = True )
222+ sel .add_argument ("--seed" , required = True )
223+ sel .add_argument ("--explicit" , required = True )
224+ sel .add_argument ("--github-output" , type = Path )
225+
184226 prep = sub .add_parser ("prepare" )
185227 prep .add_argument ("--instance-id" , required = True )
186228 prep .add_argument ("--workspace" , type = Path , required = True )
@@ -197,7 +239,14 @@ def main() -> int:
197239 comb .add_argument ("--output" , type = Path , required = True )
198240
199241 args = parser .parse_args ()
200- if args .command == "prepare" :
242+ if args .command == "select" :
243+ selected = select_instances (args .count , args .seed , args .explicit )
244+ payload = json .dumps (selected , separators = ("," , ":" ))
245+ print (payload )
246+ if args .github_output :
247+ with args .github_output .open ("a" , encoding = "utf-8" ) as handle :
248+ handle .write (f"instance_ids={ payload } \n " )
249+ elif args .command == "prepare" :
201250 prepare (args .instance_id , args .workspace )
202251 elif args .command == "collect" :
203252 collect (args .workspace , args .output , args .mode , args .model , args .effort )
0 commit comments