MCPcopy Create free account
hub / github.com/It4innovations/hyperqueue / execute

Function execute

benchmarks/src/submit/execute_script.py:27–92  ·  view source on GitHub ↗
(
    directory: Path = typer.Option(...),
    benchmarks: Path = typer.Option(...),
    submit_options: Path = typer.Option(...),
    database_path: Optional[Path] = None,
    resubmit: Optional[bool] = False,
)

Source from the content-addressed store, hash-verified

25
26
27def execute(
28 directory: Path = typer.Option(...),
29 benchmarks: Path = typer.Option(...),
30 submit_options: Path = typer.Option(...),
31 database_path: Optional[Path] = None,
32 resubmit: Optional[bool] = False,
33):
34 identifiers = deserialize_identifiers(benchmarks)
35 options = deserialize_submit_options(submit_options)
36
37 database_file = (directory / "result.json").resolve()
38 if database_path and database_path.is_file() and database_file != database_path.resolve():
39 database_file = directory / database_path.name
40 shutil.copyfile(database_path, database_file)
41
42 database = Database(database_file)
43 runner = BenchmarkRunner(database, workdir=directory, materialize_fn=materialize_benchmark)
44 benchmark_count = len(identifiers)
45
46 def run():
47 for identifier, benchmark, result in tqdm(runner.compute(identifiers), total=benchmark_count):
48 logging.info(f"Finished benchmark {identifier}: {result}")
49
50 max_runtime = options.walltime
51 if max_runtime.total_seconds() > 60:
52 max_runtime = max_runtime - timedelta(minutes=1)
53
54 logging.info(f"Starting to benchmark {benchmark_count} benchmarks, max time is {max_runtime}")
55
56 start = time.time()
57 try:
58 with_timeout(run, timeout_s=max_runtime.total_seconds())
59 runner.save()
60
61 duration = time.time() - start
62 logging.info(f"Benchmark finished in {duration}s")
63
64 # Store a symlink to the final resubmitted directory into the root directory
65 if resubmit:
66 root_dir = directory.parent.parent
67 os.symlink(directory, root_dir / "final-run", target_is_directory=True)
68 except TimeoutException:
69 runner.save()
70
71 if resubmit:
72 root_dir = directory.parent
73 else:
74 root_dir = directory / "resubmits"
75 directory = generate_job_dir(root_dir)
76
77 remaining = [identifier for identifier in identifiers if not database.has_record_for(identifier)]
78
79 logging.warning(
80 f"Benchmark didn't finish in {max_runtime}, computed {benchmark_count - len(remaining)}"
81 f"/{benchmark_count}, resubmitting at {directory}"
82 )
83 submit(
84 remaining,

Callers

nothing calls this directly

Calls 12

saveMethod · 0.95
has_record_forMethod · 0.95
deserialize_identifiersFunction · 0.90
DatabaseClass · 0.90
BenchmarkRunnerClass · 0.90
with_timeoutFunction · 0.90
generate_job_dirFunction · 0.90
submitFunction · 0.90
infoMethod · 0.80
timeMethod · 0.80
resolveMethod · 0.45

Tested by

no test coverage detected