Skip to content

Commit 1244e41

Browse files
authored
refactor: name -> benchmark_name (#48)
1 parent f1f50ca commit 1244e41

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/mlipaudit/io.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@
3434

3535

3636
def write_benchmark_result_to_disk(
37-
name: str,
37+
benchmark_name: str,
3838
result: BenchmarkResult,
3939
output_dir: str | os.PathLike,
4040
) -> None:
4141
"""Writes a benchmark result to disk.
4242
4343
Args:
44-
name: The benchmark name.
44+
benchmark_name: The benchmark name.
4545
result: The benchmark result.
4646
output_dir: Directory to which to write the result.
4747
"""
4848
_output_dir = Path(output_dir)
4949
_output_dir.mkdir(exist_ok=True, parents=True)
50-
(_output_dir / name).mkdir(exist_ok=True)
50+
(_output_dir / benchmark_name).mkdir(exist_ok=True)
5151

52-
with (_output_dir / name / RESULT_FILENAME).open("w") as json_file:
52+
with (_output_dir / benchmark_name / RESULT_FILENAME).open("w") as json_file:
5353
json_as_str = json.loads(result.model_dump_json()) # type: ignore
5454
json.dump(json_as_str, json_file, indent=2)
5555

@@ -192,20 +192,20 @@ def load_scores_from_disk(
192192

193193

194194
def write_model_output_to_disk(
195-
name: str, model_output: ModelOutput, output_dir: str | os.PathLike
195+
benchmark_name: str, model_output: ModelOutput, output_dir: str | os.PathLike
196196
) -> None:
197197
"""Writes a model output to disk.
198198
199199
Each model output is written to disk as a zip archive.
200200
201201
Args:
202-
name: The benchmark name.
202+
benchmark_name: The benchmark name.
203203
model_output: The model output to save.
204204
output_dir: Directory to which to write the model output.
205205
"""
206206
_output_dir = Path(output_dir)
207207
_output_dir.mkdir(exist_ok=True, parents=True)
208-
(_output_dir / name).mkdir(exist_ok=True)
208+
(_output_dir / benchmark_name).mkdir(exist_ok=True)
209209

210210
data, arrays = dataclass_to_dict_with_arrays(model_output)
211211

@@ -218,7 +218,9 @@ def write_model_output_to_disk(
218218

219219
np.savez(arrays_path, **arrays)
220220

221-
with ZipFile(_output_dir / name / MODEL_OUTPUT_ZIP_FILENAME, "w") as zip_object:
221+
with ZipFile(
222+
_output_dir / benchmark_name / MODEL_OUTPUT_ZIP_FILENAME, "w"
223+
) as zip_object:
222224
zip_object.write(json_path, os.path.basename(json_path))
223225
zip_object.write(arrays_path, os.path.basename(arrays_path))
224226

tests/test_io.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ def test_benchmark_results_io_works(
3838
):
3939
"""Tests whether results can be saved and loaded again to and from disk."""
4040
model_1_path = Path(tmpdir) / "model_1"
41-
for name, result in dummy_benchmark_results_model_1.items():
42-
write_benchmark_result_to_disk(name, result, model_1_path)
41+
for benchmark_name, result in dummy_benchmark_results_model_1.items():
42+
write_benchmark_result_to_disk(benchmark_name, result, model_1_path)
4343

4444
assert set(os.listdir(model_1_path)) == {"benchmark_1", "benchmark_2"}
4545
assert os.listdir(model_1_path / "benchmark_1") == ["result.json"]
4646

4747
model_2_path = Path(tmpdir) / "model_2"
48-
for name, result in dummy_benchmark_results_model_2.items():
49-
write_benchmark_result_to_disk(name, result, model_2_path)
48+
for benchmark_name, result in dummy_benchmark_results_model_2.items():
49+
write_benchmark_result_to_disk(benchmark_name, result, model_2_path)
5050

5151
assert set(os.listdir(model_2_path)) == {"benchmark_1", "benchmark_2"}
5252
assert os.listdir(model_2_path / "benchmark_1") == ["result.json"]
@@ -121,8 +121,8 @@ def test_model_outputs_io_works(
121121
),
122122
}
123123

124-
for name, model_output in model_outputs.items():
125-
write_model_output_to_disk(name, model_output, Path(tmpdir))
124+
for benchmark_name, model_output in model_outputs.items():
125+
write_model_output_to_disk(benchmark_name, model_output, Path(tmpdir))
126126

127127
assert set(os.listdir(Path(tmpdir))) == {"benchmark_1", "benchmark_2"}
128128

0 commit comments

Comments
 (0)