Skip to content

Remove print statements for logging (#421) #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ select = [
# isort
"I",
# Banned imports
"TID"
"TID",
# print
"T201"
]

# These rules are sensible and should be enabled at a later stage.
Expand Down
15 changes: 9 additions & 6 deletions scripts/check_gh_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
https://stackoverflow.com/questions/60717142/getting-linked-issues-and-projects-associated-with-a-pull-request-form-github-ap
"""

import logging
import re

import requests
from bs4 import BeautifulSoup
import re

repo = "ecmwf/WeatherGenerator"

Expand All @@ -31,6 +33,7 @@
See https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue
"""

_logger = logging.getLogger(__name__)

if __name__ == "__main__":
import argparse
Expand All @@ -47,13 +50,13 @@
msg = msg_template.format(pr=pr, repo=repo)

if not issueForm:
print(msg)
_logger.warning(msg)
exit(1)
issues = [i["href"] for i in issueForm[0].find_all("a")]
issues = [i for i in issues if i is not None and repo in i]
print(f"Linked issues for PR {pr}:")
print(f"Found {len(issues)} linked issues.")
print("\n".join(issues))
_logger.info(f"Linked issues for PR {pr}:")
_logger.warning(f"Found {len(issues)} linked issues.")
_logger.info("\n".join(issues))
if not issues:
print(msg)
_logger.warning(msg)
exit(1)
1 change: 1 addition & 0 deletions src/weathergen/model/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: T201
# (C) Copyright 2025 WeatherGenerator contributors.

#
Expand Down
29 changes: 12 additions & 17 deletions src/weathergen/train/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,14 +682,13 @@ def validate(self, epoch):
self.train_logger.add_val(samples, losses_all, stddev_all)

if self.cf.rank == 0:
print(
f"validation ({cf.run_id}) : {epoch:03d} :",
f" loss = {torch.nanmean(losses_all[0]):.4E}",
flush=True,
)
_logger.info(f"validation ({cf.run_id}) : {epoch:03d}")
_logger.info(f": loss = {torch.nanmean(losses_all[0]):.4E}")
# creating a string with all stream losses
stream_string = ""
for i_obs, rt in enumerate(cf.streams):
print("{}".format(rt["name"]) + f" : {losses_all[0, i_obs]:0.4E}")

stream_string += f" {rt['name']} : {losses_all[0, i_obs]:0.4E} \t"
_logger.info(stream_string)
# avoid that there is a systematic bias in the validation subset
self.dataset_val.advance()

Expand Down Expand Up @@ -784,7 +783,7 @@ def log_terminal(self, bidx, epoch):
pstr = "{:03d} : {:05d}/{:05d} : {:06d} : loss = {:.4E} "
pstr += "(lr={:.2E}, s/sec={:.3f})"
len_dataset = len(self.data_loader) // self.cf.batch_size
print(
_logger.info(
pstr.format(
epoch,
bidx,
Expand All @@ -793,15 +792,11 @@ def log_terminal(self, bidx, epoch):
np.nanmean(l_avg[0]),
self.lr_scheduler.get_lr(),
(self.print_freq * self.cf.batch_size) / dt,
),
flush=True,
)
)
print("\t", end="")
stream_string = ""
for i_obs, rt in enumerate(self.cf.streams):
print(
"{}".format(rt["name"]) + f" : {l_avg[0, i_obs]:0.4E} \t",
end="",
)
print("\n", flush=True)

# creating a string with all stream losses
stream_string += f"{rt['name']} : {l_avg[0, i_obs]:0.4E} \t"
_logger.info("\t" + stream_string)
self.t_start = time.time()
6 changes: 5 additions & 1 deletion src/weathergen/utils/compare_run_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
# nor does it submit to any jurisdiction.

import argparse
import logging

import dictdiffer
from obslearn.utils.config import Config

_logger = logging.getLogger(__name__)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-r1", "--run_id_1", required=True)
Expand All @@ -31,4 +35,4 @@
# name = cf1.streams[item[1][1]]['name']
# item[1][1] = name

print(f"{item[1]} :: {item[2]}")
_logger.info(f"Difference {item[1]} :: {item[2]}")
5 changes: 4 additions & 1 deletion src/weathergen/utils/run_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
import logging

from weathergen.train.utils import get_run_id

_logger = logging.getLogger(__name__)

if __name__ == "__main__":
print(get_run_id())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually we can fully remove this main block. This is meant for people who want to create their own run ids.This is also implemented in the private repo, and it has no dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't seem to find any dependencies on this file so can I go ahead and delete the whole file?

_logger.info(f"Run ID: {get_run_id()}")
1 change: 0 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def write_stream_file(write_path, content: str):


def get_expected_config(key, config):
print(key, config)
config = OmegaConf.create(config)
config.name = key
return config
Expand Down