From f433091f9e5d43ec18ac70ac9d0004453b797186 Mon Sep 17 00:00:00 2001 From: ElliottKasoar Date: Fri, 15 Mar 2024 16:59:35 +0000 Subject: [PATCH] Update logger for singlepoint --- janus_core/cli.py | 4 ++-- janus_core/single_point.py | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/janus_core/cli.py b/janus_core/cli.py index 35802ffa..1dc8d155 100644 --- a/janus_core/cli.py +++ b/janus_core/cli.py @@ -160,7 +160,7 @@ def singlepoint( device=device, read_kwargs=read_kwargs, calc_kwargs=calc_kwargs, - log_file=log_file, + log_kwargs={"filename": log_file, "filemode": "a"}, ) s_point.run_single_point( properties=properties, write_results=True, write_kwargs=write_kwargs @@ -242,7 +242,7 @@ def geomopt( # pylint: disable=too-many-arguments,too-many-locals device=device, read_kwargs=read_kwargs, calc_kwargs=calc_kwargs, - log_file=log_file, + log_kwargs={"filename": log_file, "filemode": "w"}, ) opt_kwargs = {"trajectory": traj_file} if traj_file else None diff --git a/janus_core/single_point.py b/janus_core/single_point.py index f1223e8b..9f74e1b3 100644 --- a/janus_core/single_point.py +++ b/janus_core/single_point.py @@ -16,7 +16,6 @@ Devices, MaybeList, MaybeSequence, - PathLike, ) from janus_core.log import config_logger from janus_core.mlip_calculators import choose_calculator @@ -46,8 +45,8 @@ class SinglePoint: Keyword arguments to pass to ase.io.read. Default is {}. calc_kwargs : Optional[dict[str, Any]] Keyword arguments to pass to the selected calculator. Default is {}. - log_file : Optional[PathLike] - Name of log file if writing logs. Default is None. + log_kwargs : Optional[dict[str, any]] + Keyword arguments to pass to `config_logger`. Default is {}. Attributes ---------- @@ -83,7 +82,7 @@ def __init__( device: Devices = "cpu", read_kwargs: Optional[ASEReadArgs] = None, calc_kwargs: Optional[dict[str, Any]] = None, - log_file: Optional[PathLike] = None, + log_kwargs: Optional[dict[str, any]] = None, ) -> None: """ Read the structure being simulated and attach an MLIP calculator. @@ -108,8 +107,8 @@ def __init__( Keyword arguments to pass to ase.io.read. Default is {}. calc_kwargs : Optional[dict[str, Any]] Keyword arguments to pass to the selected calculator. Default is {}. - log_file : Optional[PathLike] - Name of log file if writing logs. Default is None. + log_kwargs : Optional[dict[str, any]] + Keyword arguments to pass to `config_logger`. Default is {}. """ if struct and struct_path: raise ValueError( @@ -123,10 +122,15 @@ def __init__( "or a path to the structure file (`struct_path`)" ) - self.logger = config_logger(name=__name__, filename=log_file) - read_kwargs = read_kwargs if read_kwargs else {} calc_kwargs = calc_kwargs if calc_kwargs else {} + log_kwargs = log_kwargs if log_kwargs else {} + + if log_kwargs and "filename" not in log_kwargs: + raise ValueError("'filename' must be included in `log_kwargs`") + + log_kwargs.setdefault("name", __name__) + self.logger = config_logger(**log_kwargs) self.architecture = architecture self.device = device