| 76 | |
| 77 | @classmethod |
| 78 | def load_from_cache(cls, level: int, problem_id: int) -> Optional["KernelBenchProblem"]: |
| 79 | cache_path = KB_CACHE_DIR / f"level{level}" / f"{problem_id}.py" |
| 80 | meta_path = cache_path.with_suffix(".json") |
| 81 | if not cache_path.exists(): |
| 82 | return None |
| 83 | source = cache_path.read_text(encoding="utf-8") |
| 84 | name = f"problem_{problem_id}" |
| 85 | if meta_path.exists(): |
| 86 | meta = json.loads(meta_path.read_text(encoding="utf-8")) |
| 87 | name = meta.get("name", name) |
| 88 | return cls(level=level, problem_id=problem_id, name=name, source_code=source) |
| 89 | |
| 90 | # ----- Analysis ----- |
| 91 | |