From af5dc23d57c1f03f1a5ddd830a76a4601a42c3e1 Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Mon, 8 Apr 2024 12:39:30 +0100 Subject: [PATCH 1/2] Print somd2 and sire versions on non-interactive startup. --- src/somd2/__init__.py | 27 +++++++++++++++++++++++++++ src/somd2/app/run.py | 11 ----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/somd2/__init__.py b/src/somd2/__init__.py index d320de9..2ae79ec 100644 --- a/src/somd2/__init__.py +++ b/src/somd2/__init__.py @@ -30,3 +30,30 @@ from loguru import logger as _logger from . import runner + +# Store the somd2 version. +from ._version import __version__ + +# Store the sire version. +from sire import __version__ as _sire_version +from sire import __revisionid__ as _sire_revisionid + +# Determine whether we're being run interactively. +try: + _shell = get_ipython().__class__.__name__ + if _shell == "ZMQInteractiveShell": + _is_interactive = True # Jupyter notebook or qtconsole + elif _shell == "TerminalInteractiveShell": + _is_interactive = True # Terminal running IPython + else: + _is_interactive = False # Other type (?) + del _shell +except NameError: + _is_interactive = False # Probably standard Python interpreter + +if not _is_interactive: + # Log the versions of somd2 and sire. + _logger.info(f"somd2 version: {__version__}") + _logger.info(f"sire version: {_sire_version}+{_sire_revisionid}") + +del _is_interactive diff --git a/src/somd2/app/run.py b/src/somd2/app/run.py index 4a19df2..f92fd55 100644 --- a/src/somd2/app/run.py +++ b/src/somd2/app/run.py @@ -43,13 +43,6 @@ def cli(): from somd2.io import yaml_to_dict - # Store the somd2 version. - from somd2._version import __version__ - - # Store the sire version. - from sire import __version__ as sire_version - from sire import __revisionid__ as sire_revisionid - # Generate the parser. parser = Config._create_parser() @@ -86,10 +79,6 @@ def cli(): # Instantiate a Config object to validate the arguments. config = Config(**args) - # Log the versions of somd2 and sire. - _logger.info(f"somd2 version: {__version__}") - _logger.info(f"sire version: {sire_version}+{sire_revisionid}") - # Instantiate a Runner object to run the simulation. runner = Runner(system, config) From 9954b82a4bc3a0f093a7304c906417a028b62c02 Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Mon, 8 Apr 2024 12:48:52 +0100 Subject: [PATCH 2/2] Add somd2 and sire versions to parquet file metadata. --- src/somd2/runner/_runner.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/somd2/runner/_runner.py b/src/somd2/runner/_runner.py index b7d2acb..8848522 100644 --- a/src/somd2/runner/_runner.py +++ b/src/somd2/runner/_runner.py @@ -938,12 +938,16 @@ def _run(sim, is_restart=False): raise self._sim._cleanup() + from somd2 import __version__, _sire_version, _sire_revisionid + # Write final dataframe for the system to the energy trajectory file. # Note that sire s3 checkpoint files contain energy trajectory data, so this works even for restarts. _ = _dataframe_to_parquet( df, metadata={ "attrs": df.attrs, + "somd2 version": __version__, + "sire version": f"{_sire_version}+{_sire_revisionid}", "lambda": str(lambda_value), "lambda_array": self._lambda_values, "lambda_grad": lambda_grad,