Merge pull request #2589 from akohlmey/check-python-version-match

Add version check for liblammps vs. python module
This commit is contained in:
Axel Kohlmeyer
2021-02-09 16:22:20 -05:00
committed by GitHub
16 changed files with 81 additions and 16 deletions

View File

@ -662,8 +662,8 @@ if(BUILD_SHARED_LIBS)
endif()
if (Python_EXECUTABLE)
add_custom_target(
install-python
${Python_EXECUTABLE} install.py -v ${LAMMPS_SOURCE_DIR}/version.h
install-python ${CMAKE_COMMAND} -E remove_directory build
COMMAND ${Python_EXECUTABLE} install.py -v ${LAMMPS_SOURCE_DIR}/version.h
-p ${LAMMPS_PYTHON_DIR}/lammps
-l ${CMAKE_BINARY_DIR}/liblammps${LAMMPS_MACHINE}${CMAKE_SHARED_LIBRARY_SUFFIX}
WORKING_DIRECTORY ${LAMMPS_PYTHON_DIR}

View File

@ -90,7 +90,7 @@ The fix must also do the following:
The fix must also specify whether (by default) to include or exclude
these contributions to the global/peratom energy/virial of the system.
For the fix to include the contributions, set either of both of these
variables in the contructor:
variables in the constructor:
* *thermo_energy* = 1, for global and peratom energy
* *thermo_virial* = 1, for global and peratom virial

View File

@ -26,6 +26,23 @@ There are multiple Python interface classes in the :py:mod:`lammps` module:
.. _mpi4py_url: https://mpi4py.readthedocs.io
.. admonition:: Version check
:class: note
The :py:mod:`lammps` module stores the version number of the LAMMPS
version it is installed from. When initializing the
:py:class:`lammps <lammps.lammps>` class, this version is checked to
be the same as the result from :py:func:`lammps.version`, the version
of the LAMMPS shared library that the module interfaces to. If the
they are not the same an AttributeError exception is raised since a
mismatch of versions (e.g. due to incorrect use of the
``LD_LIBRARY_PATH`` or ``PYTHONPATH`` environment variables can lead
to crashes or data corruption and otherwise incorrect behavior.
.. automodule:: lammps
:members:
:noindex:
----------
The ``lammps`` class API

View File

@ -103,7 +103,7 @@ uninterrupted fashion.
The :doc:`fix_modify <fix_modify>` *energy* option is supported by
this fix to add the potential energy of the CMAP interactions to both
the global potential energy and peratom potential energies of the
sysstem as part of :doc:`thermodynamic output <thermo_style>` or
system as part of :doc:`thermodynamic output <thermo_style>` or
output by the :doc:`compute pe/atom <compute_pe_atom>` command. The
default setting for this fix is :doc:`fix_modify energy yes
<fix_modify>`.

View File

@ -115,7 +115,7 @@ in a pair of double quotes ("), or can span multiple lines when bracketed
by a pair of triple double quotes (""", like python embedded documentation).
This fix computes a global scalar which can be accessed by various
:doc:`output commands <Howto_output>`. The scalar is the Covars
:doc:`output commands <Howto_output>`. The scalar is the Colvars
energy mentioned above. The scalar value calculated by this fix is
"extensive".

View File

@ -165,8 +165,9 @@ LAMMPS was built with that package. See the :doc:`Build package
Related commands
""""""""""""""""
:doc:`fix addforce <fix_addforce>`, :doc:`compute temp/profile
<compute_temp_profile>`, :doc:`velocity <velocity>`
:doc:`fix addforce <fix_addforce>`,
:doc:`compute temp/profile <compute_temp_profile>`,
:doc:`velocity <velocity>`
Default
"""""""

View File

@ -83,7 +83,7 @@ appropriate fix.
.. note::
For most fixes that suppport the *energy* keyword, the default
For most fixes that support the *energy* keyword, the default
setting is *no*. For a few it is *yes*, when a user would expect
that to be the case. The doc page of each fix gives the default.
@ -108,7 +108,7 @@ option to include or exclude the contribution from fixes.
.. note::
For most fixes that suppport the *virial* keyword, the default
For most fixes that support the *virial* keyword, the default
setting is *no*. For a few it is *yes*, when a user would expect
that to be the case. The doc page of each fix gives the default.

View File

@ -149,7 +149,7 @@ No information about this fix is written to :doc:`binary restart files
The :doc:`fix_modify <fix_modify>` *energy* option is supported by
this fix to add the potential energy of atom interactions with the
grain bounadry driving force to the global potential energy of the
grain boundary driving force to the global potential energy of the
system as part of :doc:`thermodynamic output <thermo_style>`. The
default setting for this fix is :doc:`fix_modify energy no
<fix_modify>`.

View File

@ -103,7 +103,7 @@ files <restart>`.
The :doc:`fix_modify <fix_modify>` *energy* option is supported by
this fix to add the potential energy of atom interactions with the
grain bounadry driving force to the global potential energy of the
grain boundary driving force to the global potential energy of the
system as part of :doc:`thermodynamic output <thermo_style>`. The
default setting for this fix is :doc:`fix_modify energy no
<fix_modify>`.

View File

@ -141,7 +141,7 @@ No information about this fix is written to :doc:`binary restart files
<restart>`.
The :doc:`fix_modify <fix_modify>` *energy* option is supported by
this fix to add the energy assocatiated with the spin precession
this fix to add the energy associated with the spin precession
torque to the global potential energy of the system as part of
:doc:`thermodynamic output <thermo_style>`. The default setting for
this fix is :doc:`fix_modify energy no <fix_modify>`.

View File

@ -240,7 +240,7 @@ compute temperature on a subset of atoms.
keyword will be unaffected by the *temp* setting.
The cumulative energy change in the system imposed by these fixes, due
to thermostatting and/or barostating, are included in the
to thermostatting and/or barostatting, are included in the
:doc:`thermodynamic output <thermo_style>` keywords *ecouple* and
*econserve*. See the :doc:`thermo_style <thermo_style>` doc page for
details.

View File

@ -131,7 +131,7 @@ The :doc:`fix_modify <fix_modify>` *energy* option is supported by
these fixes to add the energy of interaction between atoms and all the
specified walls or region wall to the global potential energy of the
system as part of :doc:`thermodynamic output <thermo_style>`. The
default settings for thes fixes are :doc:`fix_modify energy no
default settings for these fixes are :doc:`fix_modify energy no
<fix_modify>`.
The :doc:`fix_modify <fix_modify>` *respa* option is supported by

View File

@ -508,6 +508,7 @@ cpp
cpu
createatoms
createAtoms
CreateIDs
crespi
Crespi
Critchley
@ -788,6 +789,7 @@ ees
eFF
efield
effm
eflag
eflux
eg
Eggebrecht
@ -2681,6 +2683,7 @@ rfile
rg
Rg
Rhaphson
Rhe
rheological
rheology
rhodo
@ -3335,6 +3338,7 @@ verlet
Verlet
versa
ves
vflag
vhi
vibrational
Vij

View File

@ -1,4 +1,38 @@
"""
LAMMPS module global members:
.. data:: __version__
Numerical representation of the LAMMPS version this
module was taken from. Has the same format as the
result of :py:func:`lammps.version`.
"""
from .constants import *
from .core import *
from .data import *
from .pylammps import *
# convert module string version to numeric version
def get_version_number():
from datetime import datetime
from sys import version_info
vstring = None
if version_info.major == 3 and version_info.minor >= 8:
from importlib.metadata import version
try:
vstring = version('lammps')
except: pass
else:
from pkg_resources import get_distribution
try:
vstring = get_distribution('lammps').version
except: pass
if not vstring:
return 0
d = datetime.strptime(vstring, "%d%b%Y")
return d.year*10000 + d.month*100 + d.day
__version__ = get_version_number()

View File

@ -381,6 +381,13 @@ class lammps(object):
self._installed_packages = None
self._available_styles = None
# check if liblammps version matches the installed python module version
# but not for in-place usage, i.e. when the version is 0
import lammps
if lammps.__version__ > 0 and lammps.__version__ != self.lib.lammps_version(self.lmp):
raise(AttributeError("LAMMPS Python module installed for LAMMPS version %d, but shared library is version %d" \
% (lammps.__version__, self.lib.lammps_version(self.lmp))))
# add way to insert Python callback for fix external
self.callback = {}
self.FIX_EXTERNAL_CALLBACK_FUNC = CFUNCTYPE(None, py_object, self.c_bigint, c_int, POINTER(self.c_tagint), POINTER(POINTER(c_double)), POINTER(POINTER(c_double)))

View File

@ -272,11 +272,13 @@ mpi-stubs:
@cd STUBS; $(MAKE) clean; $(MAKE)
# install LAMMPS shared lib and Python wrapper for Python usage
# include python package settings to
# automatically adapt name of python interpreter
# include python package settings to automatically adapt name of
# the python interpreter. must purge build folder to not install
# unwanted outdated files.
sinclude ../lib/python/Makefile.lammps
install-python:
@rm -rf ../python/build
@$(PYTHON) ../python/install.py -v ../src/version.h \
-p ../python/lammps -l ../src/liblammps.so