1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-11-19 12:32:40 +01:00

Separate installation and build scripts

This commit is contained in:
q-posev 2022-05-03 15:09:49 +02:00
parent 3b7b96d451
commit a68b66e142
4 changed files with 69 additions and 25 deletions

View File

@ -1,22 +1,42 @@
# Python API of the QMCkl library # Python API of the QMCkl library
## Requirements ## Requirements
- `setuptools`
- `numpy` - `numpy`
- `SWIG` (>= 4.0) - `swig` (>= 4.0)
## Manual installation ## Manual installation
1. Install the QMCkl as usual 1. Install the QMCkl library (see upstream instructions)
2. Get the latest `qmckl.h` file 2. `./manual_install_pyqmckl.sh` which should do the following
3. `python process.py` to generate `pyqmckl_include.i` list of SWIG patterns 3. Copy the produced `_pyqmckl.so` and `pyqmckl.py` files into your working directory and do not forget to `import pyqmckl` in your Python scripts
4. `swig -python -py3 -o pyqmckl_wrap.c pyqmckl.i` to generate the SWIG wrapper code in C and `pyqmckl.py` module in Python.
The second step executes the following under the hood:
1. `./build_pyqmckl.sh`
2. `<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
3. `<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`)
## Python-ic installation (recommended)
1. Install the QMCkl library (see upstream instructions)
2. `./pip_install_pyqmckl.sh`
The last step runs `./build_pyqmckl.sh`, copies the result into the `pyqmckl/` directory and
then runs `pip install .` to install the `pyqmckl` Python package in your environment.
## SWIG pre-processing
Both aforementioned steps call `build_pyqmckl.sh` script which does the following pre-processing for SWIG
1. Copy the latest `qmckl.h` file fron `include/` into the `src/` directory
2. `python process_header.py` to generate `pyqmckl_include.i` list of SWIG patterns
3. `swig -python -py3 -builtin -threads -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`. **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

@ -3,7 +3,7 @@
set -e set -e
set -x set -x
cp ../include/qmckl.h . cp ../include/qmckl.h src/
cd src/ cd src/
@ -26,18 +26,6 @@ for file in $SWIG_LIST; do
done done
# run SWIG interface file to produce the Python wrappers # run SWIG interface file to produce the Python wrappers
swig -python -py3 -o pyqmckl_wrap.c pyqmckl.i swig -python -py3 -builtin -threads -o pyqmckl_wrap.c pyqmckl.i
# compile the wrapper code
cc -c -fPIC `pkg-config --cflags qmckl` -I/usr/include/python3.8 pyqmckl_wrap.c -o pyqmckl_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
cd .. cd ..
# test
cp src/_pyqmckl.so src/pyqmckl.py -- test/
cd test
python test_api.py

View File

@ -0,0 +1,23 @@
#!/bin/bash
set -x
set -e
./build_pyqmckl.sh
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
# link against the previously installed QMCkl library (as detected by pkg-config)
cc -shared pyqmckl_wrap.o `pkg-config --libs qmckl` -o _pyqmckl.so
cd ..
# test
cp src/_pyqmckl.so src/pyqmckl.py test/
cd test/
python test_api.py
cd ..

13
python/pip_install_pyqmckl.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
set -x
set -e
./build_pyqmckl.sh
# copy swig-produced pyqmckl.py module into the pyqmckl/ folder
cp src/pyqmckl.py pyqmckl/
# install using pip
pip install .