Skip to content

Commit

Permalink
Update logger for singlepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliottKasoar committed Mar 15, 2024
1 parent 9b31f3e commit f433091
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions janus_core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions janus_core/single_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Devices,
MaybeList,
MaybeSequence,
PathLike,
)
from janus_core.log import config_logger
from janus_core.mlip_calculators import choose_calculator
Expand Down Expand Up @@ -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
----------
Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit f433091

Please sign in to comment.