Skip to content

Commit 4a7f1b1

Browse files
authored
feat: better logging (#74)
* feat: rename DEV dict and run for fewer steps * feat: remove BFGS logging * feat: filter warnings This filters out all warnings. Not the best practice. Otherwise we get jax warnings all over the place. * feat: allow disabling mlip logging * feat: log number of simulation steps
1 parent 8bb1dcb commit 4a7f1b1

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

src/mlipaudit/benchmarks/folding_stability/folding_stability.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@
5656
"temperature_kelvin": 300.0,
5757
}
5858

59-
SIMULATION_CONFIG_FAST = {
60-
"num_steps": 20,
61-
"snapshot_interval": 10,
62-
"num_episodes": 1,
59+
SIMULATION_CONFIG_DEV = {
60+
"num_steps": 10,
61+
"snapshot_interval": 1,
62+
"num_episodes": 10,
6363
"temperature_kelvin": 300.0,
6464
}
6565

@@ -195,7 +195,7 @@ def run_model(self) -> None:
195195
structure_names = STRUCTURE_NAMES
196196

197197
if self.run_mode == RunMode.DEV:
198-
md_kwargs = SIMULATION_CONFIG_FAST
198+
md_kwargs = SIMULATION_CONFIG_DEV
199199
else:
200200
md_kwargs = SIMULATION_CONFIG
201201

src/mlipaudit/benchmarks/nudged_elastic_band/engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def run(self) -> None:
127127
parallel=True,
128128
)
129129

130-
dyn = BFGS(self.neb, alpha=70, maxstep=0.03)
130+
dyn = BFGS(self.neb, alpha=70, maxstep=0.03, logfile=None)
131131

132132
def log_to_console() -> None:
133133
"""Logs info to console."""

src/mlipaudit/main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import logging
1616
import textwrap
17+
import warnings
1718
from argparse import ArgumentParser, Namespace, RawDescriptionHelpFormatter
1819

1920
import mlipaudit
@@ -27,6 +28,7 @@
2728
from mlipaudit.run_mode import RunMode
2829

2930
logger = logging.getLogger("mlipaudit")
31+
warnings.filterwarnings("ignore")
3032

3133
EXTERNAL_MODEL_VARIABLE_NAME = "mlipaudit_external_model"
3234
DESCRIPTION = textwrap.dedent(f"""\
@@ -108,6 +110,12 @@ def _subparse_benchmark(parser):
108110
help="mode to run the benchmarks in, either 'dev', 'fast' or 'standard'",
109111
metavar="",
110112
)
113+
parser.add_argument(
114+
"-v",
115+
"--verbose",
116+
action="store_true",
117+
help="enable verbose logging output from mlip",
118+
)
111119

112120

113121
def _subparse_app(parser):
@@ -173,6 +181,18 @@ def main():
173181
parser = _parser()
174182
args = parser.parse_args()
175183

184+
logging.basicConfig(
185+
level=logging.INFO,
186+
format="[%(asctime)s][%(name)s][%(levelname)s] - %(message)s",
187+
force=True,
188+
)
189+
190+
if getattr(args, "verbose", False):
191+
logger.setLevel(logging.INFO)
192+
else:
193+
mlip_logger = logging.getLogger("mlip")
194+
mlip_logger.setLevel(logging.WARNING)
195+
176196
if args.command == "benchmark":
177197
benchmarks_to_run = _get_benchmarks_to_run(args)
178198
run_benchmarks(

src/mlipaudit/utils/simulation.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ def get_simulation_engine(
9999
and kwargs.get("simulation_type", "md") == "md"
100100
):
101101
md_config = JaxMDSimulationEngine.Config(**kwargs)
102+
# Log the number of steps that will be run and for how many episodes
103+
logger.info(
104+
"Running MD simulation for %d steps and %d episodes.",
105+
md_config.num_steps,
106+
md_config.num_episodes,
107+
)
102108
return JaxMDSimulationEngine(atoms, force_field, md_config)
103109

104110
kwargs_copy = deepcopy(kwargs)
@@ -107,11 +113,19 @@ def get_simulation_engine(
107113
# Case 2: Minimization with ForceField objects -> use ASE
108114
if isinstance(force_field, ForceField):
109115
minimization_config = ASESimulationEngine.Config(**kwargs_copy)
116+
logger.info(
117+
"Running energy minimization with ASE for a maximum of %d steps.",
118+
minimization_config.num_steps,
119+
)
110120
return ASESimulationEngine(atoms, force_field, minimization_config)
111121

112122
# Case 3: MD or minimization with ASECalculator objects -> use ASE
113123
if isinstance(force_field, ASECalculator):
114124
sim_config = ASESimulationEngine.Config(**kwargs_copy)
125+
logger.info(
126+
"Running ASE-based simulation for a maximum of %d steps.",
127+
sim_config.num_steps,
128+
)
115129
return ASESimulationEngineWithCalculator(atoms, force_field, sim_config)
116130

117131
raise ValueError(

0 commit comments

Comments
 (0)