"""Split the v3 tasks that have no clean trial yet into K shards (one per token). Clean trial = result.json with no exception_info and a verifier_result, in any job dir matching the given globs. python -I v3/della/remaining.py [ ...] SRC_GLOB (env): which task dirs to draw from (default: all of tasks/prophet-v3-sif/shard*/*/). """ import glob, json, os, shutil, sys R = '/scratch/gpfs/TRIDAO/ly3223/oraclebench/' K, out, globs = int(sys.argv[1]), sys.argv[2], sys.argv[3:] done = set() for g in globs: for f in glob.glob(R + 'jobs/' + g + '/*__*/result.json'): r = json.load(open(f)) if r.get('exception_info') is None and r.get('verifier_result'): done.add(os.path.basename(r['config']['task']['path'].rstrip('/'))) src = sorted(glob.glob(os.environ.get('SRC_GLOB', R + 'tasks/prophet-v3-sif/shard*/*/'))) todo = [p for p in src if os.path.basename(p.rstrip('/')) not in done] shutil.rmtree(out, ignore_errors=True) for i, p in enumerate(todo): shutil.copytree(p, os.path.join(out, f'shard{i % K + 1}', os.path.basename(p.rstrip('/')))) print(f'all {len(src)} clean {len(done)} todo {len(todo)} shards {K}')