Skip to content

Commit

Permalink
Use InitRestart when running QMFlows jobs (#198)
Browse files Browse the repository at this point in the history
* Exposed ``InitRestart`` to the main QMFlows ``__init__.py`` file.
* Exchanged ``plams.init()`` / ``plams.finish()`` for ``qmflows.InitRestart`` in the ``qmflows.run()`` function.
* Store the ``cache.db`` file in the PLAMS working directory.
  • Loading branch information
BvB93 committed Jun 9, 2020
1 parent 61c6451 commit 49a74a0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Version 0.10.1 (09/06/2020)

# Changed
* Exposed ``InitRestart`` to the main QMFlows ``__init__.py`` file.
* Exchanged ``plams.init()`` / ``plams.finish()`` for ``qmflows.InitRestart`` in the ``qmflows.run()`` function.
* Store the ``cache.db`` file in the PLAMS working directory.


# Version 0.10.0 (XX/03/2020)

Expand Down
3 changes: 3 additions & 0 deletions src/qmflows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from .logger import logger

from .utils import InitRestart

from .components import (
Angle, Dihedral, Distance,
find_first_job, select_max, select_min)
Expand All @@ -19,6 +21,7 @@
__all__ = [
'__version__',
'logger',
'InitRestart',
'Angle', 'Dihedral', 'Distance', 'Settings',
'adf', 'cp2k', 'cp2k_mm', 'dftb', 'orca', 'run', 'PackageWrapper',
'example_H2O2_TS', 'example_freqs', 'example_generic_constraints',
Expand Down
4 changes: 3 additions & 1 deletion src/qmflows/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__version__ = "0.10.0"
"""The QMFlows version."""

__version__ = "0.10.1"
34 changes: 22 additions & 12 deletions src/qmflows/packages/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
from scm import plams

from .serializer import SerMolecule, SerMol, SerSettings, SerNDFrame
from ..type_hints import WarnMap, WarnDict, WarnParser, PromisedObject, MolType, _Settings
from ..utils import InitRestart
from ..fileFunctions import yaml2Settings
from ..settings import Settings
from ..settings import _Settings as _SettingsType
from ..warnings_qmflows import QMFlows_Warning
from ..type_hints import WarnMap, WarnDict, WarnParser, PromisedObject, MolType, _Settings

__all__ = ['Package', 'run', 'registry', 'Result', 'SerMolecule', 'SerSettings']

Expand Down Expand Up @@ -542,6 +543,7 @@ def run_job(cls, settings: Settings, mol: plams.Molecule, job_name: str,
def run(job: PromisedObject, runner: Optional[str] = None,
path: Union[None, str, os.PathLike] = None,
folder: Union[None, str, os.PathLike] = None,
load_jobs: bool = False,
**kwargs: Any) -> Result:
r"""Pickup a runner and initialize it.
Expand All @@ -560,31 +562,32 @@ def run(job: PromisedObject, runner: Optional[str] = None,
folder : :class:`str` or :class:`~os.PathLike`, optional
The name of the new PLAMS working directory.
Will default to ``"plams_workdir"`` if ``None``.
load_jobs : :class:`bool`
Load all pre-existing Jobs (contained within the working directory) into memory.
Note that this can be quite slow if a large number of pre-existing jobs is present.
\**kwargs : :data:`~typing.Any`
Further keyword arguments to-be passed to :func:`call_default`.
Returns
-------
:class:`Result`
A new Result instance.
The exact type will depend on **job**.
See Also
--------
:func:`noodles.run_parallel`
Run a workflow in parallel threads, storing results in a Sqlite3 database.
"""
plams.init(path=path, folder=folder)
plams.config.log.stdout = 0

if runner is None:
ret = call_default(job, kwargs.get('n_processes', 1),
kwargs.get('always_cache', True))
else:
raise ValueError(f"Don't know runner: {runner}")
with InitRestart(path=path, folder=folder):
plams.config.log.stdout = 0

plams.finish()
return ret
if runner is None:
return call_default(job, kwargs.get('n_processes', 1),
kwargs.get('always_cache', True))
else:
raise ValueError(f"Don't know runner: {runner!r}")


def call_default(wf: PromisedObject, n_processes: int, always_cache: bool) -> Result:
Expand All @@ -593,9 +596,16 @@ def call_default(wf: PromisedObject, n_processes: int, always_cache: bool) -> Re
Caching can be turned off by specifying ``cache=None``.
"""
# In case 'default_jobmanager' is not set (for some reason)
try:
workdir = plams.config.get('default_jobmanager').workdir
except AttributeError as ex:
raise plams.PlamsError("Failed to initialize the PLAMS jobmanager") from ex

db_file = join(workdir, 'cache.db')
return run_parallel(
wf, n_threads=n_processes, registry=registry,
db_file='cache.db', always_cache=always_cache, echo_log=False)
db_file=db_file, always_cache=always_cache, echo_log=False)


#: A :class:`Registry` instance to-be returned by :func:`registry`.
Expand Down

0 comments on commit 49a74a0

Please sign in to comment.