Logging and Job Log Files in PLAMS¶
Inspect the PLAMS logging system, see how job status is recorded, and learn where to find the generated text and CSV logs.
Downloads: Notebook | Script ?
Requires: AMS2027 or later
Related tutorials
Related documentation
Logging in PLAMS¶
PLAMS has built-in logging which aims to simplify tracking the progress and status of jobs. This consists of progress logging to stdout and a logfile, and writing job summaries to CSV files. Each of these is explained below.
Progress Logger¶
PLAMS writes job progress to stdout and a plain text logfile. The location of this logfile is determined by the working directory of the default job manager, and is called logfile.
Users can also write logs to the same locations using the log function. This takes a level argument. By convention in PLAMS, the level should be between 0-7, with 0 being the most and 7 the least important logging.
The level of logging that is written to stdout and the logfile can be changed through the config.LogSettings.
from scm.base import ChemicalSystem
from scm.inputs import AMS, DFTB
from scm.plams import AMSJob, log, config
counter = 0
def get_test_job():
global counter
s = AMS(Task="SinglePoint")
s.Engine = DFTB()
counter += 1
return AMSJob(name=f"test{counter}", molecule=ChemicalSystem.from_smiles("C"), settings=s)
config.log.stdout = 3
config.log.file = 5
config.jobmanager.hashing = None # Force PLAMS to re-run identical test jobs
job = get_test_job()
job.run()
log("Test job finished", 5)
[19.10|16:05:31] JOB test1 STARTED
[19.10|16:05:31] JOB test1 RUNNING
[19.10|16:05:32] JOB test1 FINISHED
[19.10|16:05:32] JOB test1 SUCCESSFUL
with open(config.default_jobmanager.logfile, "r") as f:
print(f.read())
[19.10|16:05:31] Starting test1.prerun()
[19.10|16:05:31] test1.prerun() finished
[19.10|16:05:31] JOB test1 RUNNING
[19.10|16:05:31] Executing test1.run
[19.10|16:05:32] Execution of test1.run finished with returncode 0
[19.10|16:05:32] JOB test1 FINISHED
[19.10|16:05:32] Starting test1.postrun()
[19.10|16:05:32] test1.postrun() finished
[19.10|16:05:32] JOB test1 SUCCESSFUL
[19.10|16:05:32] Test job finished
Note that the logs from an AMS calculation can also be forwarded to the progress logs using the watch = True flag.
job = get_test_job()
job.run(watch=True);
[19.10|16:05:32] JOB test2 STARTED
[19.10|16:05:32] JOB test2 RUNNING
[19.10|16:05:32] test2: AMS 2026.201 RunTime: Oct19-2026 16:05:32 ShM Nodes: 1 Procs: 6
[19.10|16:05:33] test2: DFTB: SCC cycle
[19.10|16:05:33] test2: cyc= 1 err=1.1E+00 method=1 nvec= 1 mix=0.075 e= 0.0000
[19.10|16:05:33] test2: cyc= 2 err=1.1E+00 method=1 nvec= 1 mix=0.154 e= 0.0000
[19.10|16:05:33] test2: cyc= 3 err=8.9E-01 method=1 nvec= 2 mix=0.201 e= 0.0000
[19.10|16:05:33] test2: cyc= 4 err=1.7E-02 method=1 nvec= 3 mix=0.207 e= 0.0000
[19.10|16:05:33] test2: cyc= 5 err=6.8E-03 method=1 nvec= 3 mix=0.213 e= 0.0000
[19.10|16:05:33] test2: cyc= 6 err=2.3E-05 method=1 nvec= 4 mix=0.219 e= 0.0000
[19.10|16:05:33] test2: cyc= 7 err=6.0E-05 method=1 nvec= 5 mix=0.213 e= 0.0000
[19.10|16:05:33] test2: cyc= 8 err=1.6E-08 method=1 nvec= 3 mix=0.219 e= 0.0000
[19.10|16:05:33] test2: cyc= 9 err=2.6E-10 method=1 nvec= 4 mix=0.226 e= 0.0000
[19.10|16:05:33] test2: SCC cycle converged!
[19.10|16:05:33] test2: NORMAL TERMINATION
[19.10|16:05:33] JOB test2 FINISHED
[19.10|16:05:33] JOB test2 SUCCESSFUL
Job Summary Logger¶
PLAMS also writes summaries of jobs to a CSV file, the location of which by default is also determined by the job manager. It is called job_logfile.csv.
jobs = [get_test_job() for _ in range(3)]
jobs[2].settings.input.Engine.ResourcesDir = "DefinitelyNotAParameterSet"
for job in jobs:
job.run()
[19.10|16:05:33] JOB test3 STARTED
[19.10|16:05:33] JOB test3 RUNNING
[19.10|16:05:34] JOB test3 FINISHED
[19.10|16:05:34] JOB test3 SUCCESSFUL
[19.10|16:05:34] JOB test4 STARTED
[19.10|16:05:34] JOB test4 RUNNING
[19.10|16:05:34] JOB test4 FINISHED
[19.10|16:05:34] JOB test4 SUCCESSFUL
[19.10|16:05:34] JOB test5 STARTED
[19.10|16:05:34] JOB test5 RUNNING
[19.10|16:05:42] WARNING: Job test5 finished with nonzero return code
[19.10|16:05:42] JOB test5 CRASHED
[19.10|16:05:42] Error message for job test5 was:
ResourcesDir does not exist: /Users/ormrodmorley/Documents/code/ams/amshome_version_bump/atomicdata/DFTB/DefinitelyNotAParameterSet
These CSVs give overall information on the status of all jobs run by a given job manager.
import csv
try:
with open(config.default_jobmanager.job_logger.logfile, newline="") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print(f"{row['job_name']} {row['job_status']}: {row['job_get_errormsg']}")
except AttributeError:
pass
test1 successful:
test2 successful:
test3 successful:
test4 successful:
test5 crashed: ResourcesDir does not exist: /Users/ormrodmorley/Documents/code/ams/amshome_version_bump/atomicdata/DFTB/DefinitelyNotAParameterSet
Job Status Change Callback¶
PLAMS also supports users adding a custom callback which fires when a job status changes.
This is very flexible and can be used to set up custom notifications, for instance sending a desktop prompt, email or messaging app notification.
For example, below we show how to raise a desktop notification when a job finishes. Note that this requires the external library plyer, which needs to be installed into your python environment.
First we set up our notification function:
try:
import plyer
except ImportError:
print(
"Install plyer into your python environment to run this example. For example, with 'pip install plyer' or 'pip install plyer[macosx]' for Mac users."
)
def send_desktop_notification(name, path, status, at, **_):
if status == "successful":
plyer.notification.notify(
title=f"PLAMS job {name}",
message=f"Completed successfully at {at:%H:%M:%S UTC}",
timeout=5,
)
elif status in ["crashed", "failed"]:
plyer.notification.notify(
title=f"PLAMS job {name}",
message=f"Errored at {at:%H:%M:%S UTC}",
timeout=5,
)
Then we apply it to all jobs using the global config:
config.job.on_status_change = send_desktop_notification
When jobs are run, notifications should then be raised to the desktop.
jobs = [get_test_job() for _ in range(3)]
jobs[2].settings.input.Engine.ResourcesDir = "DefinitelyNotAParameterSet"
for job in jobs:
job.run()
[19.10|16:05:42] JOB test6 STARTED
[19.10|16:05:42] JOB test6 RUNNING
[19.10|16:05:43] JOB test6 FINISHED
[19.10|16:05:43] JOB test6 SUCCESSFUL
[19.10|16:05:43] JOB test7 STARTED
[19.10|16:05:43] JOB test7 RUNNING
[19.10|16:05:44] JOB test7 FINISHED
[19.10|16:05:44] JOB test7 SUCCESSFUL
[19.10|16:05:44] JOB test8 STARTED
[19.10|16:05:44] JOB test8 RUNNING
[19.10|16:05:52] WARNING: Job test8 finished with nonzero return code
[19.10|16:05:52] JOB test8 CRASHED
[19.10|16:05:52] Error message for job test8 was:
ResourcesDir does not exist: /Users/ormrodmorley/Documents/code/ams/amshome_version_bump/atomicdata/DFTB/DefinitelyNotAParameterSet
Note that the given callbacks will never block job execution.
However, if many notifications are being sent, or there is a significant overhead to sending a notification, you may need to customize the wait time at the end of the script to allow all notifications to be sent successfully. To do this set the number of seconds for config.atexit_timeout:
config.atexit_timeout = 120
See also¶
Python Script¶
#!/usr/bin/env python
# coding: utf-8
# ## Logging in PLAMS
# PLAMS has built-in logging which aims to simplify tracking the progress and status of jobs. This consists of progress logging to stdout and a logfile, and writing job summaries to CSV files. Each of these is explained below.
# ### Progress Logger
# PLAMS writes job progress to stdout and a plain text logfile. The location of this logfile is determined by the working directory of the default job manager, and is called `logfile`.
#
# Users can also write logs to the same locations using the `log` function. This takes a `level` argument. By convention in PLAMS, the level should be between 0-7, with 0 being the most and 7 the least important logging.
#
# The level of logging that is written to stdout and the logfile can be changed through the `config.LogSettings`.
from scm.base import ChemicalSystem
from scm.inputs import AMS, DFTB
from scm.plams import AMSJob, log, config
counter = 0
def get_test_job():
global counter
s = AMS(Task="SinglePoint")
s.Engine = DFTB()
counter += 1
return AMSJob(name=f"test{counter}", molecule=ChemicalSystem.from_smiles("C"), settings=s)
config.log.stdout = 3
config.log.file = 5
config.jobmanager.hashing = None # Force PLAMS to re-run identical test jobs
job = get_test_job()
job.run()
log("Test job finished", 5)
with open(config.default_jobmanager.logfile, "r") as f:
print(f.read())
# Note that the logs from an AMS calculation can also be forwarded to the progress logs using the `watch = True` flag.
job = get_test_job()
job.run(watch=True);
# ### Job Summary Logger
# PLAMS also writes summaries of jobs to a CSV file, the location of which by default is also determined by the job manager. It is called `job_logfile.csv`.
jobs = [get_test_job() for _ in range(3)]
jobs[2].settings.input.Engine.ResourcesDir = "DefinitelyNotAParameterSet"
for job in jobs:
job.run()
# These CSVs give overall information on the status of all jobs run by a given job manager.
import csv
try:
with open(config.default_jobmanager.job_logger.logfile, newline="") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print(f"{row['job_name']} {row['job_status']}: {row['job_get_errormsg']}")
except AttributeError:
pass
# ### Job Status Change Callback
# PLAMS also supports users adding a custom callback which fires when a job status changes.
#
# This is very flexible and can be used to set up custom notifications, for instance sending a desktop prompt, email or messaging app notification.
# For example, below we show how to raise a desktop notification when a job finishes. Note that this requires the external library `plyer`, which needs to be installed into your python environment.
# First we set up our notification function:
try:
import plyer
except ImportError:
print(
"Install plyer into your python environment to run this example. For example, with 'pip install plyer' or 'pip install plyer[macosx]' for Mac users."
)
def send_desktop_notification(name, path, status, at, **_):
if status == "successful":
plyer.notification.notify(
title=f"PLAMS job {name}",
message=f"Completed successfully at {at:%H:%M:%S UTC}",
timeout=5,
)
elif status in ["crashed", "failed"]:
plyer.notification.notify(
title=f"PLAMS job {name}",
message=f"Errored at {at:%H:%M:%S UTC}",
timeout=5,
)
# Then we apply it to all jobs using the global config:
config.job.on_status_change = send_desktop_notification
# When jobs are run, notifications should then be raised to the desktop.
jobs = [get_test_job() for _ in range(3)]
jobs[2].settings.input.Engine.ResourcesDir = "DefinitelyNotAParameterSet"
for job in jobs:
job.run()
# Note that the given callbacks will never block job execution.
#
# However, if many notifications are being sent, or there is a significant overhead to sending a notification, you may need to customize the wait time at the end of the script to allow all notifications to be sent successfully. To do this set the number of seconds for `config.atexit_timeout`:
config.atexit_timeout = 120