Merge branch 'lammps:develop' into mliappy_unified
This commit is contained in:
@ -11,7 +11,7 @@ independently and used to build the wheel without installing it.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
import sys,os,shutil,time,glob,subprocess
|
||||
import sys,os,shutil,glob,subprocess
|
||||
from argparse import ArgumentParser
|
||||
|
||||
parser = ArgumentParser(prog='install.py',
|
||||
@ -23,6 +23,8 @@ parser.add_argument("-l", "--lib", required=True,
|
||||
help="path to the compiled LAMMPS shared library")
|
||||
parser.add_argument("-n", "--noinstall", action="store_true", default=False,
|
||||
help="only build a binary wheel. Don't attempt to install it")
|
||||
parser.add_argument("-w", "--wheeldir", required=False,
|
||||
help="path to a directory where the created wheel will be stored")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@ -30,7 +32,7 @@ args = parser.parse_args()
|
||||
|
||||
if args.package:
|
||||
if not os.path.exists(args.package):
|
||||
print( "ERROR: LAMMPS package %s does not exist" % args.package)
|
||||
print("ERROR: LAMMPS package %s does not exist" % args.package)
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
else:
|
||||
@ -38,12 +40,20 @@ if args.package:
|
||||
|
||||
if args.lib:
|
||||
if not os.path.exists(args.lib):
|
||||
print( "ERROR: LAMMPS shared library %s does not exist" % args.lib)
|
||||
print("ERROR: LAMMPS shared library %s does not exist" % args.lib)
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
else:
|
||||
args.lib = os.path.abspath(args.lib)
|
||||
|
||||
if args.wheeldir:
|
||||
if not os.path.exists(args.wheeldir):
|
||||
print("ERROR: directory %s to store the wheel does not exist" % args.wheeldir)
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
else:
|
||||
args.wheeldir = os.path.abspath(args.wheeldir)
|
||||
|
||||
# we need to switch to the folder of the python package
|
||||
olddir = os.path.abspath('.')
|
||||
os.chdir(os.path.dirname(args.package))
|
||||
@ -62,10 +72,10 @@ shutil.copy(args.lib,'lammps')
|
||||
# create a virtual environment for building the wheel
|
||||
shutil.rmtree('buildwheel',True)
|
||||
try:
|
||||
txt = subprocess.check_output([sys.executable, '-m', 'virtualenv', 'buildwheel', '-p', sys.executable], stderr=subprocess.STDOUT, shell=False)
|
||||
txt = subprocess.check_output([sys.executable, '-m', 'venv', 'buildwheel'], stderr=subprocess.STDOUT, shell=False)
|
||||
print(txt.decode('UTF-8'))
|
||||
except subprocess.CalledProcessError as err:
|
||||
sys.exit("Failed to create a virtualenv: {0}".format(err.output.decode('UTF-8')))
|
||||
sys.exit("Failed to create a virtual environment: {0}".format(err.output.decode('UTF-8')))
|
||||
|
||||
# now run the commands to build the wheel. those must be in a separate script
|
||||
# and run in subprocess, since this will use the virtual environment and
|
||||
@ -80,10 +90,18 @@ os.remove(os.path.join('lammps',os.path.basename(args.lib)))
|
||||
|
||||
# stop here if we were asked not to install the wheel we created
|
||||
if args.noinstall:
|
||||
exit(0)
|
||||
if args.wheeldir:
|
||||
for wheel in glob.glob('lammps-*.whl'):
|
||||
shutil.copy(wheel, args.wheeldir)
|
||||
os.remove(wheel)
|
||||
exit(0)
|
||||
|
||||
# install the wheel with pip. first try to install in the default environment.
|
||||
# that will be a virtual environment, if active, or the system folder.
|
||||
# if in a virtual environment, we must not use the python executable
|
||||
# that is running this script (configured by cmake), but use "python"
|
||||
# from the regular system path. The user may have changed to the virtual
|
||||
# environment *after* running cmake.
|
||||
# recent versions of pip will automatically drop to use the user folder
|
||||
# in case the system folder is not writable.
|
||||
|
||||
@ -93,21 +111,35 @@ if args.noinstall:
|
||||
# must be uninstalled manually. We must not ignore this and drop
|
||||
# back to install into a (forced) user folder.
|
||||
|
||||
print("Installing wheel")
|
||||
if "VIRTUAL_ENV" in os.environ:
|
||||
print("Installing wheel into virtual environment")
|
||||
py_exe = 'python'
|
||||
else:
|
||||
print("Installing wheel into system site-packages folder")
|
||||
py_exe = sys.executable
|
||||
|
||||
for wheel in glob.glob('lammps-*.whl'):
|
||||
try:
|
||||
txt = subprocess.check_output([sys.executable, '-m', 'pip', 'install', '--force-reinstall', wheel], stderr=subprocess.STDOUT, shell=False)
|
||||
txt = subprocess.check_output([py_exe, '-m', 'pip', 'install', '--force-reinstall', wheel], stderr=subprocess.STDOUT, shell=False)
|
||||
print(txt.decode('UTF-8'))
|
||||
if args.wheeldir:
|
||||
shutil.copy(wheel, args.wheeldir)
|
||||
else:
|
||||
shutil.copy(wheel, olddir)
|
||||
os.remove(wheel)
|
||||
continue
|
||||
except subprocess.CalledProcessError as err:
|
||||
errmsg = err.output.decode('UTF-8')
|
||||
if errmsg.find("distutils installed"):
|
||||
sys.exit(errmsg + "You need to uninstall the LAMMPS python module manually first.\n")
|
||||
try:
|
||||
print('Installing wheel into standard site-packages folder failed. Trying user folder now')
|
||||
print('Installing wheel into system site-packages folder failed. Trying user folder now')
|
||||
txt = subprocess.check_output([sys.executable, '-m', 'pip', 'install', '--user', '--force-reinstall', wheel], stderr=subprocess.STDOUT, shell=False)
|
||||
print(txt.decode('UTF-8'))
|
||||
if args.wheeldir:
|
||||
shutil.copy(wheel, args.wheeldir)
|
||||
else:
|
||||
shutil.copy(wheel, olddir)
|
||||
os.remove(wheel)
|
||||
except:
|
||||
sys.exit('Failed to install wheel ' + wheel)
|
||||
shutil.copy(wheel, olddir)
|
||||
os.remove(wheel)
|
||||
|
||||
@ -188,20 +188,17 @@ class lammps(object):
|
||||
[c_void_p,POINTER(c_double),POINTER(c_double),c_double,c_double,c_double]
|
||||
self.lib.lammps_reset_box.restype = None
|
||||
|
||||
self.lib.lammps_gather_atoms.argtypes = \
|
||||
[c_void_p,c_char_p,c_int,c_int,c_void_p]
|
||||
self.lib.lammps_gather_atoms.argtypes = [c_void_p,c_char_p,c_int,c_int,c_void_p]
|
||||
self.lib.lammps_gather_atoms.restype = None
|
||||
|
||||
self.lib.lammps_gather_atoms_concat.argtypes = \
|
||||
[c_void_p,c_char_p,c_int,c_int,c_void_p]
|
||||
self.lib.lammps_gather_atoms_concat.argtypes = [c_void_p,c_char_p,c_int,c_int,c_void_p]
|
||||
self.lib.lammps_gather_atoms_concat.restype = None
|
||||
|
||||
self.lib.lammps_gather_atoms_subset.argtypes = \
|
||||
[c_void_p,c_char_p,c_int,c_int,c_int,POINTER(c_int),c_void_p]
|
||||
self.lib.lammps_gather_atoms_subset.restype = None
|
||||
|
||||
self.lib.lammps_scatter_atoms.argtypes = \
|
||||
[c_void_p,c_char_p,c_int,c_int,c_void_p]
|
||||
self.lib.lammps_scatter_atoms.argtypes = [c_void_p,c_char_p,c_int,c_int,c_void_p]
|
||||
self.lib.lammps_scatter_atoms.restype = None
|
||||
|
||||
self.lib.lammps_scatter_atoms_subset.argtypes = \
|
||||
@ -211,20 +208,17 @@ class lammps(object):
|
||||
self.lib.lammps_gather_bonds.argtypes = [c_void_p,c_void_p]
|
||||
self.lib.lammps_gather_bonds.restype = None
|
||||
|
||||
self.lib.lammps_gather.argtypes = \
|
||||
[c_void_p,c_char_p,c_int,c_int,c_void_p]
|
||||
self.lib.lammps_gather.argtypes = [c_void_p,c_char_p,c_int,c_int,c_void_p]
|
||||
self.lib.lammps_gather.restype = None
|
||||
|
||||
self.lib.lammps_gather_concat.argtypes = \
|
||||
[c_void_p,c_char_p,c_int,c_int,c_void_p]
|
||||
self.lib.lammps_gather_concat.argtypes = [c_void_p,c_char_p,c_int,c_int,c_void_p]
|
||||
self.lib.lammps_gather_concat.restype = None
|
||||
|
||||
self.lib.lammps_gather_subset.argtypes = \
|
||||
[c_void_p,c_char_p,c_int,c_int,c_int,POINTER(c_int),c_void_p]
|
||||
self.lib.lammps_gather_subset.restype = None
|
||||
|
||||
self.lib.lammps_scatter.argtypes = \
|
||||
[c_void_p,c_char_p,c_int,c_int,c_void_p]
|
||||
self.lib.lammps_scatter.argtypes = [c_void_p,c_char_p,c_int,c_int,c_void_p]
|
||||
self.lib.lammps_scatter.restype = None
|
||||
|
||||
self.lib.lammps_scatter_subset.argtypes = \
|
||||
@ -244,7 +238,8 @@ class lammps(object):
|
||||
self.lib.lammps_neighlist_num_elements.argtypes = [c_void_p, c_int]
|
||||
self.lib.lammps_neighlist_num_elements.restype = c_int
|
||||
|
||||
self.lib.lammps_neighlist_element_neighbors.argtypes = [c_void_p, c_int, c_int, POINTER(c_int), POINTER(c_int), POINTER(POINTER(c_int))]
|
||||
self.lib.lammps_neighlist_element_neighbors.argtypes = \
|
||||
[c_void_p, c_int, c_int, POINTER(c_int), POINTER(c_int), POINTER(POINTER(c_int))]
|
||||
self.lib.lammps_neighlist_element_neighbors.restype = None
|
||||
|
||||
self.lib.lammps_is_running.argtypes = [c_void_p]
|
||||
@ -368,11 +363,9 @@ class lammps(object):
|
||||
if type(cmdargs[i]) is str:
|
||||
cmdargs[i] = cmdargs[i].encode()
|
||||
cargs = (c_char_p*narg)(*cmdargs)
|
||||
self.lib.lammps_open.argtypes = [c_int, c_char_p*narg, \
|
||||
MPI_Comm, c_void_p]
|
||||
self.lib.lammps_open.argtypes = [c_int, c_char_p*narg, MPI_Comm, c_void_p]
|
||||
else:
|
||||
self.lib.lammps_open.argtypes = [c_int, c_char_p, \
|
||||
MPI_Comm, c_void_p]
|
||||
self.lib.lammps_open.argtypes = [c_int, c_char_p, MPI_Comm, c_void_p]
|
||||
|
||||
self.opened = 1
|
||||
comm_ptr = self.MPI._addressof(comm)
|
||||
@ -390,8 +383,7 @@ class lammps(object):
|
||||
if type(cmdargs[i]) is str:
|
||||
cmdargs[i] = cmdargs[i].encode()
|
||||
cargs = (c_char_p*narg)(*cmdargs)
|
||||
self.lib.lammps_open_no_mpi.argtypes = [c_int, c_char_p*narg, \
|
||||
c_void_p]
|
||||
self.lib.lammps_open_no_mpi.argtypes = [c_int, c_char_p*narg, c_void_p]
|
||||
self.lmp = c_void_p(self.lib.lammps_open_no_mpi(narg,cargs,None))
|
||||
else:
|
||||
self.lib.lammps_open_no_mpi.argtypes = [c_int, c_char_p, c_void_p]
|
||||
@ -963,17 +955,14 @@ class lammps(object):
|
||||
return ptr
|
||||
|
||||
elif ctype == LMP_SIZE_COLS:
|
||||
if cstyle == LMP_STYLE_GLOBAL \
|
||||
or cstyle == LMP_STYLE_ATOM \
|
||||
or cstyle == LMP_STYLE_LOCAL:
|
||||
if cstyle == LMP_STYLE_GLOBAL or cstyle == LMP_STYLE_ATOM or cstyle == LMP_STYLE_LOCAL:
|
||||
self.lib.lammps_extract_compute.restype = POINTER(c_int)
|
||||
with ExceptionCheck(self):
|
||||
ptr = self.lib.lammps_extract_compute(self.lmp,cid,cstyle,ctype)
|
||||
return ptr[0]
|
||||
|
||||
elif ctype == LMP_SIZE_VECTOR or ctype == LMP_SIZE_ROWS:
|
||||
if cstyle == LMP_STYLE_GLOBAL \
|
||||
or cstyle == LMP_STYLE_LOCAL:
|
||||
if cstyle == LMP_STYLE_GLOBAL or cstyle == LMP_STYLE_LOCAL:
|
||||
self.lib.lammps_extract_compute.restype = POINTER(c_int)
|
||||
with ExceptionCheck(self):
|
||||
ptr = self.lib.lammps_extract_compute(self.lmp,cid,cstyle,ctype)
|
||||
|
||||
@ -165,7 +165,7 @@ class numpy_wrapper:
|
||||
"""
|
||||
value = self.lmp.extract_compute(cid, cstyle, ctype)
|
||||
|
||||
if cstyle in (LMP_STYLE_GLOBAL, LMP_STYLE_LOCAL):
|
||||
if cstyle == LMP_STYLE_GLOBAL:
|
||||
if ctype == LMP_TYPE_VECTOR:
|
||||
nrows = self.lmp.extract_compute(cid, cstyle, LMP_SIZE_VECTOR)
|
||||
return self.darray(value, nrows)
|
||||
@ -173,6 +173,13 @@ class numpy_wrapper:
|
||||
nrows = self.lmp.extract_compute(cid, cstyle, LMP_SIZE_ROWS)
|
||||
ncols = self.lmp.extract_compute(cid, cstyle, LMP_SIZE_COLS)
|
||||
return self.darray(value, nrows, ncols)
|
||||
elif cstyle == LMP_STYLE_LOCAL:
|
||||
nrows = self.lmp.extract_compute(cid, cstyle, LMP_SIZE_ROWS)
|
||||
ncols = self.lmp.extract_compute(cid, cstyle, LMP_SIZE_COLS)
|
||||
if ncols == 0:
|
||||
return self.darray(value, nrows)
|
||||
else:
|
||||
return self.darray(value, nrows, ncols)
|
||||
elif cstyle == LMP_STYLE_ATOM:
|
||||
if ctype == LMP_TYPE_VECTOR:
|
||||
nlocal = self.lmp.extract_global("nlocal")
|
||||
|
||||
@ -449,6 +449,8 @@ class PyLammps(object):
|
||||
:type ptr: pointer
|
||||
:param comm: MPI communicator (as provided by `mpi4py <mpi4py_docs_>`_). ``None`` means use ``MPI_COMM_WORLD`` implicitly.
|
||||
:type comm: MPI_Comm
|
||||
:param verbose: print all LAMMPS output to stdout
|
||||
:type verbose: bool
|
||||
|
||||
:ivar lmp: instance of original LAMMPS Python interface
|
||||
:vartype lmp: :py:class:`lammps`
|
||||
@ -457,8 +459,9 @@ class PyLammps(object):
|
||||
:vartype run: list
|
||||
"""
|
||||
|
||||
def __init__(self, name="", cmdargs=None, ptr=None, comm=None):
|
||||
def __init__(self, name="", cmdargs=None, ptr=None, comm=None, verbose=False):
|
||||
self.has_echo = False
|
||||
self.verbose = verbose
|
||||
|
||||
if cmdargs:
|
||||
if '-echo' in cmdargs:
|
||||
@ -869,8 +872,8 @@ class PyLammps(object):
|
||||
if comm:
|
||||
output = self.lmp.comm.bcast(output, root=0)
|
||||
|
||||
if 'verbose' in kwargs and kwargs['verbose']:
|
||||
print(output)
|
||||
if self.verbose or ('verbose' in kwargs and kwargs['verbose']):
|
||||
print(output, end = '')
|
||||
|
||||
lines = output.splitlines()
|
||||
|
||||
|
||||
@ -1,14 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys,os,shutil
|
||||
import sys,os,site
|
||||
|
||||
# find python script to activate the virtual environment and source it
|
||||
base = os.path.abspath('buildwheel')
|
||||
if sys.platform == 'win32':
|
||||
virtenv=os.path.join('buildwheel','Scripts','activate_this.py')
|
||||
bin_dir=os.path.join(base,'Scripts')
|
||||
else:
|
||||
virtenv=os.path.join('buildwheel','bin','activate_this.py')
|
||||
bin_dir=os.path.join(base,'bin')
|
||||
|
||||
exec(open(virtenv).read(), {'__file__': virtenv})
|
||||
# prepend bin to PATH, set venv path
|
||||
os.environ["PATH"] = os.pathsep.join([bin_dir] + os.environ.get("PATH", "").split(os.pathsep))
|
||||
os.environ["VIRTUAL_ENV"] = base
|
||||
|
||||
# add the virtual environments libraries to the host python import mechanism
|
||||
prev_length = len(sys.path)
|
||||
for lib in "__LIB_FOLDERS__".split(os.pathsep):
|
||||
path = os.path.realpath(os.path.join(bin_dir, lib))
|
||||
site.addsitedir(path)
|
||||
sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]
|
||||
|
||||
sys.real_prefix = sys.prefix
|
||||
sys.prefix = base
|
||||
|
||||
# update pip and install all requirements to build the wheel
|
||||
os.system('python -m pip install --upgrade pip')
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
from setuptools import setup
|
||||
from setuptools.dist import Distribution
|
||||
from sys import version_info
|
||||
import os,time,shutil
|
||||
import os,time
|
||||
LAMMPS_PYTHON_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
LAMMPS_DIR = os.path.dirname(LAMMPS_PYTHON_DIR)
|
||||
LAMMPS_SOURCE_DIR = os.path.join(LAMMPS_DIR, 'src')
|
||||
@ -24,7 +24,7 @@ def get_lammps_version():
|
||||
|
||||
class BinaryDistribution(Distribution):
|
||||
"""Wrapper to enforce creating a binary package"""
|
||||
def has_ext_modules(foo):
|
||||
def has_ext_modules(self):
|
||||
return True
|
||||
|
||||
if version_info.major >= 3:
|
||||
|
||||
Reference in New Issue
Block a user