From c9450bb1a79357827ed90b8eb5eca882c04943be Mon Sep 17 00:00:00 2001 From: q-posev Date: Wed, 4 May 2022 15:06:37 +0200 Subject: [PATCH] Rename the imported functions and get rid of Python package for now --- python/{pyqmckl => }/_version.py | 0 python/manual_install_pyqmckl.sh | 6 ++--- python/pip_install_pyqmckl.sh | 6 ++++- python/pyqmckl/__init__.py | 2 -- python/setup.py | 44 ++++++++++---------------------- python/src/pyqmckl.i | 7 ++++- python/test/test_api.py | 20 +++++++-------- 7 files changed, 38 insertions(+), 47 deletions(-) rename python/{pyqmckl => }/_version.py (100%) delete mode 100644 python/pyqmckl/__init__.py diff --git a/python/pyqmckl/_version.py b/python/_version.py similarity index 100% rename from python/pyqmckl/_version.py rename to python/_version.py diff --git a/python/manual_install_pyqmckl.sh b/python/manual_install_pyqmckl.sh index f3b48e6..24f5c6a 100755 --- a/python/manual_install_pyqmckl.sh +++ b/python/manual_install_pyqmckl.sh @@ -9,15 +9,15 @@ set -e cd src/ # compile the wrapper code -cc -c -fPIC `pkg-config --cflags qmckl` -I/usr/include/python3.8 pyqmckl_wrap.c -o pyqmckl_wrap.o +cc -c -fPIC `pkg-config --cflags qmckl` -I/usr/include/python3.8 qmckl_wrap.c -o qmckl_wrap.o # link against the previously installed QMCkl library (as detected by pkg-config) -cc -shared pyqmckl_wrap.o `pkg-config --libs qmckl` -o _pyqmckl.so +cc -shared pyqmckl_wrap.o `pkg-config --libs qmckl` -o _qmckl.so cd .. # copy the produced files into the test dir -cp src/_pyqmckl.so src/pyqmckl.py test/ +cp src/_qmckl.so src/qmckl.py test/ # run tests cd test/ diff --git a/python/pip_install_pyqmckl.sh b/python/pip_install_pyqmckl.sh index 5559d65..846d571 100755 --- a/python/pip_install_pyqmckl.sh +++ b/python/pip_install_pyqmckl.sh @@ -6,8 +6,12 @@ set -e ./build_pyqmckl.sh # copy swig-produced pyqmckl.py module into the pyqmckl/ folder -cp src/pyqmckl.py pyqmckl/ +#cp src/qmckl.py qmckl/ +cp src/qmckl.py ./ # install using pip pip install . +cd test +python test_api.py +cd .. diff --git a/python/pyqmckl/__init__.py b/python/pyqmckl/__init__.py deleted file mode 100644 index e797b17..0000000 --- a/python/pyqmckl/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from .pyqmckl import * -from ._version import __version__ diff --git a/python/setup.py b/python/setup.py index 2cf89db..59a7256 100644 --- a/python/setup.py +++ b/python/setup.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 """ -setup.py file for pyqmckl package +setup.py file for qmckl package """ from setuptools import setup, Extension @@ -11,49 +11,33 @@ from os.path import join with open("README.md", "r") as fh: long_description = fh.read() -# Read the version string from the file -VERSIONFILE = "pyqmckl/_version.py" -try: - exec(open(VERSIONFILE).read()) -except: - raise IOError("Could not open the version file %s." % (VERSIONFILE, )) - -version_r = __version__ -if not version_r: - raise RuntimeError("Unable to find a version string in %s." % (VERSIONFILE, )) - - # Define the name of the Python package -mod_name = 'pyqmckl' - +MODULE_NAME = "qmckl" # Define pyqmckl extension module based on SWIG interface file (requires qmckl.h) -pyqmckl_module = Extension(name = mod_name + '._' + mod_name, - sources = [ join('src', mod_name + '_wrap.c') ], +pyqmckl_module = Extension(name = "._" + MODULE_NAME, + sources = [ join("src", MODULE_NAME + "_wrap.c") ], #include_dirs = [numpy_includedir], #library_dirs = [], - #runtime_library_dirs = [], - libraries = ['qmckl'], - extra_compile_args = ['-Wall'], + libraries = ["qmckl"], + extra_compile_args = ["-Wall"], #extra_link_args = [h5_ldflags], - #swig_opts = ['-py3' , '-builtin'], - depends = [ join('src', 'qmckl.h') ], - language = 'c' + depends = [ join("src", "qmckl.h") ], + language = "c" ) -setup(name = mod_name, - version = version_r, +setup(name = MODULE_NAME, + version = "0.2.0", author = "TREX-CoE", author_email = "posenitskiy@irsamc.ups-tlse.fr", description = """Python API of the QMCkl library""", long_description = long_description, long_description_content_type = "text/markdown", ext_modules = [pyqmckl_module], - py_modules = [mod_name], - packages = [mod_name], - url = 'https://github.com/TREX-CoE/qmckl', - license = 'BSD', + py_modules = [MODULE_NAME], + url = "https://github.com/TREX-CoE/qmckl", + license = "BSD", classifiers=[ "Intended Audience :: Science/Research", "Intended Audience :: Developers", @@ -69,5 +53,5 @@ setup(name = mod_name, "Operating System :: MacOS" ], python_requires = ">=3.0", - install_requires = ['numpy>=1.17.3'] + install_requires = ["numpy>=1.17.3"] ) diff --git a/python/src/pyqmckl.i b/python/src/pyqmckl.i index df36681..7a26756 100644 --- a/python/src/pyqmckl.i +++ b/python/src/pyqmckl.i @@ -1,4 +1,4 @@ -%module pyqmckl +%module qmckl /* Define SWIGWORDSIZE in order to properly align long integers on 64-bit system */ #define SWIGWORDSIZE64 %{ @@ -7,6 +7,11 @@ #include "qmckl.h" %} +/* + * Get rid of the function prefixes, as the scripting language will use + * the module's namespace. + */ +%rename("%(strip:[qmckl_])s") ""; /* Include stdint to recognize types from stdint.h */ %include diff --git a/python/test/test_api.py b/python/test/test_api.py index 99c57d8..2c85456 100644 --- a/python/test/test_api.py +++ b/python/test/test_api.py @@ -1,13 +1,13 @@ """ This is the test of the Python API of the QMCkl library. -It is the `bench_mos.c` C code adapted from the `qmckl_bench` +It is the `bench_mos.c` C code adapted from the `bench` repo and translated into Python with some modifications. """ from os.path import join import time -import pyqmckl as pq +import qmckl as pq from data.data import coord @@ -16,34 +16,34 @@ elec_num = 158 ITERMAX = 10 -ctx = pq.qmckl_context_create() +ctx = pq.context_create() try: - pq.qmckl_trexio_read(ctx, 'fake.h5') + pq.trexio_read(ctx, 'fake.h5') except RuntimeError: print('Error handling check: passed') fname = join('data', 'Alz_small.h5') -pq.qmckl_trexio_read(ctx, fname) +pq.trexio_read(ctx, fname) print('trexio_read: passed') -pq.qmckl_set_electron_walk_num(ctx, walk_num) +pq.set_electron_walk_num(ctx, walk_num) -mo_num = pq.qmckl_get_mo_basis_mo_num(ctx) +mo_num = pq.get_mo_basis_mo_num(ctx) assert mo_num == 404 -pq.qmckl_set_electron_coord(ctx, 'T', coord) +pq.set_electron_coord(ctx, 'T', coord) size_max = 5*walk_num*elec_num*mo_num -mo_vgl = pq.qmckl_get_mo_basis_mo_vgl(ctx, size_max) +mo_vgl = pq.get_mo_basis_mo_vgl(ctx, size_max) assert mo_vgl.size == size_max start = time.clock_gettime_ns(time.CLOCK_REALTIME) for _ in range(ITERMAX): - mo_vgl_in = pq.qmckl_get_mo_basis_mo_vgl_inplace(ctx, size_max) + mo_vgl_in = pq.get_mo_basis_mo_vgl_inplace(ctx, size_max) end = time.clock_gettime_ns(time.CLOCK_REALTIME)