Skip to content

Commit

Permalink
metrics logging unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilferrit committed Sep 16, 2024
1 parent 0a201a3 commit 34fca7d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ def tiny_config(tmp_path):
"devices": None,
"random_seed": 454,
"n_log": 1,
"tb_summarywriter": None,
"tb_summarywriter": False,
"log_metrics": False,
"log_every_n_steps": 50,
"n_peaks": 150,
"min_mz": 50.0,
"max_mz": 2500.0,
Expand Down
39 changes: 39 additions & 0 deletions tests/unit_tests/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Unit tests specifically for the model_runner module."""

import shutil
from pathlib import Path

import pytest
Expand Down Expand Up @@ -282,3 +283,41 @@ def test_evaluate(
)

result_file.unlink()


def test_metrics_logging(tmp_path, mgf_small, tiny_config):
config = Config(tiny_config)
config._user_config["log_metrics"] = True
config._user_config["log_every_n_steps"] = 1
config.tb_summarywriter = True
config.max_epochs = 1

curr_model_path = tmp_path / "foo.epoch=0-step=1.ckpt"
best_model_path = tmp_path / "foo.best.ckpt"
tb_path = tmp_path / "tensorboard"
csv_path = tmp_path / "csv_logs"

with ModelRunner(
config, output_dir=tmp_path, output_rootname="foo"
) as runner:
runner.train([mgf_small], [mgf_small])

assert curr_model_path.is_file()
assert best_model_path.is_file()
assert tb_path.is_dir()
assert csv_path.is_dir()

curr_model_path.unlink()
best_model_path.unlink()
shutil.rmtree(tb_path)

with pytest.raises(FileExistsError):
with ModelRunner(
config, output_dir=tmp_path, output_rootname="foo"
) as runner:
runner.train([mgf_small], [mgf_small])

assert not curr_model_path.is_file()
assert not best_model_path.is_file()
assert not tb_path.is_dir()
assert csv_path.is_dir()

0 comments on commit 34fca7d

Please sign in to comment.