jupyter¶
Notebook Execution Helpers¶
Running shell commands and complex scientific workflows inside Jupyter notebooks can often lead to verbose and “scary” boilerplate code.
Added in version 0.1.0.
The rgpycrumbs.run.jupyter module runs subprocesses for tutorial notebooks, like those in the Atomistic Cookbook.
The rgpycrumbs.eon.helpers module writes eOn config.ini files.
Subprocess Management¶
The run_command_or_exit function streams stdout and stderr in real-time
to the notebook cell output so that long-running simulation jobs (like
eonclient) do not appear to hang.
from rgpycrumbs.run.jupyter import run_command_or_exit
# Runs 'eonclient', streams output, and raises SystemExit on failure
# This prevents the notebook from continuing if the simulation crashes.
run_command_or_exit(["eonclient"], timeout=300)
The timeout is in seconds and covers the whole command, including the processes it starts.
At the deadline the helper kills them all and exits with status 124.
The default, timeout=None, sets no deadline.
On POSIX the command runs in its own session.
Ctrl-C in a terminal then reaches only the helper, which kills the command.
Configuration Generation¶
Instead of writing config.ini files using fragile f-strings, use
write_eon_config to generate them from Python dictionaries.
from rgpycrumbs.eon.helpers import write_eon_config
settings = {
"Main": {"job": "nudged_elastic_band"},
"Potential": {"potential": "Metatomic"},
}
# Writes to ./config.ini safely
write_eon_config(".", settings)
API Reference¶
For developer details see rgpycrumbs.run.jupyter.
write_eon_config is documented in rgpycrumbs.eon.helpers.