From 960f72244eebd21bf062442ce30c72075b2c300e Mon Sep 17 00:00:00 2001 From: Ou Ku Date: Wed, 10 Jun 2026 11:38:52 +0200 Subject: [PATCH 1/5] add timestamp suffix --- climanet/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/climanet/utils.py b/climanet/utils.py index c60bc5b..3501f48 100644 --- a/climanet/utils.py +++ b/climanet/utils.py @@ -4,6 +4,7 @@ import numpy as np import xarray as xr import torch +import time from torch.utils.tensorboard import SummaryWriter @@ -222,7 +223,8 @@ def set_seed(seed: int = 42): def setup_logging(log_dir: str) -> SummaryWriter: """Set up TensorBoard logging directory and writer.""" Path(log_dir).mkdir(parents=True, exist_ok=True) - return SummaryWriter(log_dir) + timestamp_utc = time.strftime("%Y%m%dT%H%M%S", time.gmtime()) + return SummaryWriter(log_dir, filename_suffix=f'_UTC{timestamp_utc}') def compute_masked_loss( From d9721dfd2b971b06d77c55ad2761974c203df1a7 Mon Sep 17 00:00:00 2001 From: Ou Ku Date: Wed, 10 Jun 2026 11:46:38 +0200 Subject: [PATCH 2/5] add unit test for writer --- tests/test_utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index f4f5361..6c720b7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,2 +1,11 @@ -def test_dummy(): - assert True +from climanet.utils import setup_logging + + +def test_setup_logging(tmp_path): + writer = setup_logging(str(tmp_path)) + writer.add_text("test", "This is a test log entry.") + writer.close() + + # Test that there is at least one events file + # The filename should have "UTC" keyword, which is the timestamp suffix + assert any(tmp_path.glob("events.out.*UTC*")) From 2e791be5fcf029e794a7fdbb5a44703667f9fa21 Mon Sep 17 00:00:00 2001 From: Ou Ku Date: Wed, 10 Jun 2026 13:21:25 +0200 Subject: [PATCH 3/5] add tbparse as dependency --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 9261094..1c4aae6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ dependencies = [ "matplotlib>=3.10.8", "netcdf4>=1.7.4", "scipy>=1.17.1", + "tbparse>=0.0.9", "tensorboard", "torch>=2.10.0", "xarray>=2025.12.0", From 00368b7ad96cddfec9192db2270d15c6f9ced3be Mon Sep 17 00:00:00 2001 From: Ou Ku Date: Wed, 10 Jun 2026 13:24:10 +0200 Subject: [PATCH 4/5] add tbparse log file reading in test --- tests/test_utils.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 6c720b7..b4ae4f9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,11 +1,18 @@ from climanet.utils import setup_logging +from tbparse import SummaryReader def test_setup_logging(tmp_path): - writer = setup_logging(str(tmp_path)) - writer.add_text("test", "This is a test log entry.") + writer = setup_logging(tmp_path) + log_text = "This is a test log entry." + writer.add_scalar("Test Scalar", 42) + writer.add_text("Test Text", log_text) writer.close() - # Test that there is at least one events file - # The filename should have "UTC" keyword, which is the timestamp suffix - assert any(tmp_path.glob("events.out.*UTC*")) + # Test that there is one event file + # The file should have "UTC" keyword in timestamp suffix + assert len(list(tmp_path.glob("events*UTC*"))) == 1 + + # Load the events file with SummaryReader + reader = SummaryReader(tmp_path) + assert reader.text["value"].iloc[0] == log_text From fc867aea517e0dd999012b386a64f6eb93cf82bf Mon Sep 17 00:00:00 2001 From: Ou Ku Date: Wed, 10 Jun 2026 13:29:11 +0200 Subject: [PATCH 5/5] add scalar value check test --- tests/test_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index b4ae4f9..66bcb93 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -15,4 +15,5 @@ def test_setup_logging(tmp_path): # Load the events file with SummaryReader reader = SummaryReader(tmp_path) - assert reader.text["value"].iloc[0] == log_text + assert reader.text["value"].iloc[0] == log_text # check text + assert reader.scalars["value"].iloc[0] == 42 # check scalar