1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-11-04 13:14:02 +01:00

First working prototype (manual installation)

This commit is contained in:
q-posev 2022-05-02 16:14:18 +02:00
parent 036fcc6fda
commit faecae6aa8
6 changed files with 51 additions and 2127 deletions

22
python/README.md Normal file
View File

@ -0,0 +1,22 @@
# Python API of the QMCkl library
## Requirements
- `numpy`
- `SWIG` (>= 4.0)
## Manual installation
1. Install the QMCkl as usual
2. Get the latest `qmckl.h` file
3. `python process.py` to generate `pyqmckl_include.i` list of SWIG patterns
4. `swig -python -py3 -o pyqmckl_wrap.c pyqmckl.i` to generate the SWIG wrapper code in C and `pyqmckl.py` module in Python.
**Note:** for this to work three files have to be present in the working directory: `pyqmckl.i`, `pyqmckl_include.i` and `numpy.i`.
5. `<c-compiler> -I/usr/include/python3.8 -c -fPIC pyqmckl_wrap.c` to compile the wrapper code into an object file using the `<c-compiler>` (replace with your C compiler, e.g. `gcc`) on your machine
6. `<c-compiler> -shared pyqmckl_wrap.o -lqmckl -o _pyqmckl.so` to produce the final C extension (this requires the `qmckl` library to be installed and present in the linking paths together with all its dependencies like `trexio`)
7. Put the produced `_pyqmckl.so` and `pyqmckl.py` files in the working directory and then run `import pyqmckl`
## Python-ic installation

View File

@ -1,18 +1,37 @@
#!/bin/bash
set -e set -e
set -x set -x
source export_files.sh # check if qmckl header exists
if [[ ! -f 'qmckl.h' ]]; then
echo "qmckl.h NOT FOUND"
exit 1
fi
cp qmckl.h pyqmckl.i numpy.i src/ # process the qmckl header file to get patterns for SWIG
python process.py
cd src/ # check if SWIG files exist
SWIG_LIST='pyqmckl.i pyqmckl_include.i numpy.i'
for file in $SWIG_LIST; do
if [[ ! -f $file ]]; then
echo "$file NOT FOUND"
exit 1
fi
done
# run SWIG interface file to produce the Python wrappers
swig -python -py3 -o pyqmckl_wrap.c pyqmckl.i swig -python -py3 -o pyqmckl_wrap.c pyqmckl.i
gcc -c -fPIC -I/usr/include/python3.8 ${C_FILES} pyqmckl_wrap.c -ltrexio # compile the wrapper code
cc -c -fPIC `pkg-config --cflags qmckl` -I/usr/include/python3.8 pyqmckl_wrap.c -o pyqmckl_wrap.o
gfortran -c -fPIC -I/usr/include/python3.8 ${F_FILES} # link against the previously installed QMCkl library (as detected by pkg-config)
cc -shared pyqmckl_wrap.o `pkg-config --libs qmckl` -o _pyqmckl.so
gcc -shared ${C_O_FILES} pyqmckl_wrap.o -o _pyqmckl.so # test
cp _pyqmckl.so pyqmckl.py -- test/
cd test
python test_api.py

View File

@ -1,11 +0,0 @@
export C_FILES="qmckl_electron.c qmckl_nucleus.c qmckl_determinant.c qmckl_error.c qmckl_verificarlo.c qmckl_jastrow.c qmckl_sherman_morrison_woodbury.c qmckl_trexio.c qmckl_numprec.c qmckl_context.c qmckl_mo.c qmckl_blas.c qmckl_memory.c qmckl_local_energy.c qmckl_point.c qmckl_ao.c"
export F_FILES="qmckl_electron_f.F90 qmckl_distance_f.F90 qmckl_nucleus_f.F90 qmckl_determinant_f.F90 qmckl_verificarlo_f.F90 qmckl_jastrow_f.F90 qmckl_mo_f.F90 qmckl_blas_f.F90 qmckl_local_energy_f.F90 qmckl_ao_f.F90"
export C_O_FILES="qmckl_electron.o qmckl_nucleus.o qmckl_determinant.o qmckl_error.o qmckl_verificarlo.o qmckl_jastrow.o qmckl_sherman_morrison_woodbury.o qmckl_trexio.o qmckl_numprec.o qmckl_context.o qmckl_mo.o qmckl_blas.o qmckl_memory.o qmckl_local_energy.o qmckl_point.o qmckl_ao.o"
export FH_FUNC_FILES="qmckl_electron_fh_func.F90 qmckl_distance_fh_func.F90 qmckl_nucleus_fh_func.F90 qmckl_error_fh_func.F90 qmckl_sherman_morrison_woodbury_fh_func.F90 qmckl_trexio_fh_func.F90 qmckl_numprec_fh_func.F90 qmckl_context_fh_func.F90 qmckl_mo_fh_func.F90 qmckl_blas_fh_func.F90 qmckl_point_fh_func.F90 qmckl_ao_fh_func.F90"
export FH_TYPE_FILES="qmckl_error_fh_type.F90 qmckl_context_fh_type.F90"
export H_FUNC_FILES="qmckl_electron_func.h qmckl_distance_func.h qmckl_nucleus_func.h qmckl_determinant_func.h qmckl_error_func.h qmckl_jastrow_func.h qmckl_sherman_morrison_woodbury_func.h qmckl_trexio_func.h qmckl_numprec_func.h qmckl_context_func.h qmckl_mo_func.h qmckl_blas_func.h qmckl_local_energy_func.h qmckl_point_func.h qmckl_ao_func.h"
export H_TYPE_FILES="qmckl_error_type.h qmckl_numprec_type.h qmckl_context_type.h"
export H_PRIVATE_FUNC_FILES="qmckl_electron_private_func.h qmckl_nucleus_private_func.h qmckl_determinant_private_func.h qmckl_error_private_func.h qmckl_verificarlo_private_func.h qmckl_jastrow_private_func.h qmckl_mo_private_func.h qmckl_blas_private_func.h qmckl_memory_private_func.h qmckl_local_energy_private_func.h qmckl_point_private_func.h qmckl_ao_private_func.h"
export H_PRIVATE_TYPE_FILES="qmckl_electron_private_type.h qmckl_nucleus_private_type.h qmckl_determinant_private_type.h qmckl_error_private_type.h qmckl_jastrow_private_type.h qmckl_numprec_private_type.h qmckl_context_private_type.h qmckl_mo_private_type.h qmckl_blas_private_type.h qmckl_memory_private_type.h qmckl_local_energy_private_type.h qmckl_point_private_type.h qmckl_ao_private_type.h"

View File

@ -1,11 +0,0 @@
export C_FILES="src/qmckl_electron.c src/qmckl_nucleus.c src/qmckl_determinant.c src/qmckl_error.c src/qmckl_verificarlo.c src/qmckl_jastrow.c src/qmckl_sherman_morrison_woodbury.c src/qmckl_trexio.c src/qmckl_numprec.c src/qmckl_context.c src/qmckl_mo.c src/qmckl_blas.c src/qmckl_memory.c src/qmckl_local_energy.c src/qmckl_point.c src/qmckl_ao.c"
export F_FILES="src/qmckl_electron_f.F90 src/qmckl_distance_f.F90 src/qmckl_nucleus_f.F90 src/qmckl_determinant_f.F90 src/qmckl_verificarlo_f.F90 src/qmckl_jastrow_f.F90 src/qmckl_mo_f.F90 src/qmckl_blas_f.F90 src/qmckl_local_energy_f.F90 src/qmckl_ao_f.F90"
export C_O_FILES="src/qmckl_electron.o src/qmckl_nucleus.o src/qmckl_determinant.o src/qmckl_error.o src/qmckl_verificarlo.o src/qmckl_jastrow.o src/qmckl_sherman_morrison_woodbury.o src/qmckl_trexio.o src/qmckl_numprec.o src/qmckl_context.o src/qmckl_mo.o src/qmckl_blas.o src/qmckl_memory.o src/qmckl_local_energy.o src/qmckl_point.o src/qmckl_ao.o"
export FH_FUNC_FILES="src/qmckl_electron_fh_func.F90 src/qmckl_distance_fh_func.F90 src/qmckl_nucleus_fh_func.F90 src/qmckl_error_fh_func.F90 src/qmckl_sherman_morrison_woodbury_fh_func.F90 src/qmckl_trexio_fh_func.F90 src/qmckl_numprec_fh_func.F90 src/qmckl_context_fh_func.F90 src/qmckl_mo_fh_func.F90 src/qmckl_blas_fh_func.F90 src/qmckl_point_fh_func.F90 src/qmckl_ao_fh_func.F90"
export FH_TYPE_FILES="src/qmckl_error_fh_type.F90 src/qmckl_context_fh_type.F90"
export H_FUNC_FILES="src/qmckl_electron_func.h src/qmckl_distance_func.h src/qmckl_nucleus_func.h src/qmckl_determinant_func.h src/qmckl_error_func.h src/qmckl_jastrow_func.h src/qmckl_sherman_morrison_woodbury_func.h src/qmckl_trexio_func.h src/qmckl_numprec_func.h src/qmckl_context_func.h src/qmckl_mo_func.h src/qmckl_blas_func.h src/qmckl_local_energy_func.h src/qmckl_point_func.h src/qmckl_ao_func.h"
export H_TYPE_FILES="src/qmckl_error_type.h src/qmckl_numprec_type.h src/qmckl_context_type.h"
export H_PRIVATE_FUNC_FILES="src/qmckl_electron_private_func.h src/qmckl_nucleus_private_func.h src/qmckl_determinant_private_func.h src/qmckl_error_private_func.h src/qmckl_verificarlo_private_func.h src/qmckl_jastrow_private_func.h src/qmckl_mo_private_func.h src/qmckl_blas_private_func.h src/qmckl_memory_private_func.h src/qmckl_local_energy_private_func.h src/qmckl_point_private_func.h src/qmckl_ao_private_func.h"
export H_PRIVATE_TYPE_FILES="src/qmckl_electron_private_type.h src/qmckl_nucleus_private_type.h src/qmckl_determinant_private_type.h src/qmckl_error_private_type.h src/qmckl_jastrow_private_type.h src/qmckl_numprec_private_type.h src/qmckl_context_private_type.h src/qmckl_mo_private_type.h src/qmckl_blas_private_type.h src/qmckl_memory_private_type.h src/qmckl_local_energy_private_type.h src/qmckl_point_private_type.h src/qmckl_ao_private_type.h"

View File

@ -13,7 +13,7 @@ numbers = {}
qmckl_public_api = [] qmckl_public_api = []
with open("include/qmckl.h", 'r') as f_in: with open("qmckl.h", 'r') as f_in:
for line in f_in: for line in f_in:
if get_name: if get_name:
@ -103,10 +103,8 @@ with open("include/qmckl.h", 'r') as f_in:
#if 'num' in line and 'get' in func_name and not 'qmckl_get' in line and collect: #if 'num' in line and 'get' in func_name and not 'qmckl_get' in line and collect:
if 'get' in func_name and not 'qmckl_get' in line and collect and ';' in line: if 'get' in func_name and not 'qmckl_get' in line and collect and ';' in line:
#print(func_name)
print(func_name) #print(line)
print(line)
pattern = line.replace(';','').replace(')','').strip() pattern = line.replace(';','').replace(')','').strip()
datatype = pattern.replace('const','').replace('*','').split()[0] datatype = pattern.replace('const','').replace('*','').split()[0]
@ -143,7 +141,7 @@ for k,v in numbers.items():
print(v) print(v)
with open("python/pyqmckl_include.i", 'w') as f_out: with open("pyqmckl_include.i", 'w') as f_out:
swig_type = '' swig_type = ''
for v in numbers.values(): for v in numbers.values():

File diff suppressed because it is too large Load Diff