Load a single problem from a standalone .py file.
(
path: str,
level: int = 1,
problem_id: int = 0,
)
| 444 | |
| 445 | |
| 446 | def load_from_file( |
| 447 | path: str, |
| 448 | level: int = 1, |
| 449 | problem_id: int = 0, |
| 450 | ) -> KernelBenchProblem: |
| 451 | """Load a single problem from a standalone .py file.""" |
| 452 | p = Path(path) |
| 453 | if not p.exists(): |
| 454 | print(f"ERROR: File not found: {path}") |
| 455 | sys.exit(1) |
| 456 | source = p.read_text(encoding="utf-8") |
| 457 | name = p.stem.replace("_", " ") |
| 458 | prob = KernelBenchProblem( |
| 459 | level=level, problem_id=problem_id, name=name, source_code=source, |
| 460 | ) |
| 461 | prob.save_to_cache() |
| 462 | return prob |
| 463 | |
| 464 | |
| 465 | # --------------------------------------------------------------------------- |
no test coverage detected