MCPcopy Create free account
hub / github.com/NVIDIA/SOL-ExecBench / build_solution_for_problem

Function build_solution_for_problem

scripts/run_dataset.py:117–136  ·  view source on GitHub ↗

Build a solution for a problem directory. If *solution_name* is given, looks for that file inside *problem_dir*. ``.json`` files are loaded directly; ``.py`` files are wrapped as a custom solution. Falls back to the definition's reference code when the file does not exist or *solut

(
    definition: dict, problem_dir: Path, solution_name: str | None = None
)

Source from the content-addressed store, hash-verified

115
116
117def build_solution_for_problem(
118 definition: dict, problem_dir: Path, solution_name: str | None = None
119) -> dict:
120 """Build a solution for a problem directory.
121
122 If *solution_name* is given, looks for that file inside *problem_dir*.
123 ``.json`` files are loaded directly; ``.py`` files are wrapped as a custom
124 solution. Falls back to the definition's reference code when the file does
125 not exist or *solution_name* is ``None``.
126 """
127 if solution_name is not None:
128 solution_file = problem_dir / solution_name
129 if solution_file.exists():
130 if solution_file.suffix == ".json":
131 print(f" Using solution in {solution_file}...")
132 return json.loads(solution_file.read_text())
133 print(f" Building solution from {solution_file}...")
134 return build_custom_solution(definition, solution_file)
135 print(" Building solution from Definition.reference...")
136 return build_reference_solution(definition)
137
138
139def build_custom_solution(definition: dict, solution_py: Path) -> dict:

Callers 1

mainFunction · 0.85

Calls 2

build_custom_solutionFunction · 0.85
build_reference_solutionFunction · 0.85

Tested by

no test coverage detected