Skip to content

Commit

Permalink
Merge pull request #18 from loriab/pylibefp_buildsys
Browse files Browse the repository at this point in the history
Add pylibefp python bindings to upstream libefp
  • Loading branch information
slipchenko authored Apr 1, 2024
2 parents cdc28e6 + 81f4827 commit 96fd560
Show file tree
Hide file tree
Showing 21 changed files with 4,811 additions and 1,092 deletions.
75 changes: 60 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
cmargs: >
-D BUILD_SHARED_LIBS=ON
-D LIBEFP_ENABLE_OPENMP=ON
pytest-marker-expr: "test" # i.e., all

- label: L-Gnu
runs-on: ubuntu-latest
Expand All @@ -29,49 +30,57 @@ jobs:
cmargs: >
-D BUILD_SHARED_LIBS=ON
-D LIBEFP_ENABLE_OPENMP=ON
pytest-marker-expr: "test"

- label: L-Intel
runs-on: ubuntu-latest
python-version: "3.10"
blas: MKL
build_type: Release
cmargs: >
-D CMAKE_C_COMPILER=icx
-D CMAKE_CXX_COMPILER=icpx
-D CMAKE_C_FLAGS="--gcc-toolchain=${CONDA_PREFIX} --sysroot=${CONDA_PREFIX}/${HOST}/sysroot -target ${HOST}"
-D CMAKE_CXX_FLAGS="--gcc-toolchain=${CONDA_PREFIX} --sysroot=${CONDA_PREFIX}/${HOST}/sysroot -target ${HOST}"
-D BUILD_SHARED_LIBS=ON
-D LIBEFP_ENABLE_OPENMP=OFF
pytest-marker-expr: "not dict_5" # the forced fail fails?

- label: M-Clang
# test nans on macos-latest (macos-12)
# NaNs in tests on macos-latest (macos-12)
runs-on: macos-13
python-version: "3.10"
blas: OBL
build_type: Release
cmargs: >
-D BUILD_SHARED_LIBS=ON
-D LIBEFP_ENABLE_OPENMP=ON
pytest-marker-expr: "test"

- label: M-Clang
# test nans on macos-latest (macos-12)
# NaNs in tests on macos-latest (macos-12)
runs-on: macos-13
python-version: "3.10"
blas: ACC
build_type: Release
cmargs: >
-D BUILD_SHARED_LIBS=ON
-D LIBEFP_ENABLE_OPENMP=ON
pytest-marker-expr: "test"

- label: W-ClangCL
- label: W-MinGW
runs-on: windows-latest
python-version: "3.10"
blas: MKL
build_type: Release
cmargs: >
-D CMAKE_C_COMPILER="gcc.exe"
-D CMAKE_CXX_COMPILER="g++.exe"
-D CMAKE_Fortran_COMPILER="gfortran.exe"
-D BUILD_SHARED_LIBS=OFF
-D LIBEFP_ENABLE_OPENMP=ON
# using gnu, not clang-cl, for consistent compiler stack incl. Fortran
- label: L-Intel
runs-on: ubuntu-latest
python-version: "3.10"
blas: MKL
build_type: Release
cmargs: >
-D CMAKE_C_COMPILER=icx
-D CMAKE_C_FLAGS="--gcc-toolchain=${CONDA_PREFIX} --sysroot=${CONDA_PREFIX}/${HOST}/sysroot -target ${HOST}"
-D BUILD_SHARED_LIBS=ON
-D LIBEFP_ENABLE_OPENMP=OFF
pytest-marker-expr: "test"

name: "Build • 🐍 ${{ matrix.cfg.python-version }} • ${{ matrix.cfg.label }} • ${{ matrix.cfg.blas }}"
runs-on: ${{ matrix.cfg.runs-on }}
Expand All @@ -97,6 +106,12 @@ jobs:
#ACC- libblas=*=*accelerate
#OBL- libblas=*=*openblas
#OBL- openblas=*=*openmp*
# pylibefp
- cxx-compiler
- pybind11
- qcelemental
#- libpython
- pytest
EOF
if [[ "${{ runner.os }}" == "Linux" ]]; then
:
Expand All @@ -114,6 +129,7 @@ jobs:
sed -i "s;fortran-compiler;m2w64-gcc-fortran;g" export.yaml
sed -i "s;#${{ matrix.cfg.blas }};;g" export.yaml
sed -i "s;openmp;pthreads;g" export.yaml # W openblas is pthreads
sed -i "s;#- libpython;- libpython;g" export.yaml
fi
# model sed for L/W
# sed -i "s;;;g" export.yaml
Expand Down Expand Up @@ -202,7 +218,36 @@ jobs:
return 0;
}
EOF
cmake -S . -B build -G Ninja --log-level verbose -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="${CONDA_PREFIX};${{github.workspace}}/installed"
cmake -S . -B build -G Ninja --log-level verbose -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="${CONDA_PREFIX};${{ github.workspace }}/installed"
cmake --build build
./build/hello
# Step is unnecessary; remove for debugging.
- name: Confound Environment - test fetched pybind11
if: ${{ matrix.cfg.blas == 'OBL' }}
run: mamba remove pybind11

- name: Build & Install Python bindings
run: |
cd python
cmake \
-S . \
-B build \
-G Ninja \
-D CMAKE_PREFIX_PATH="${CONDA_PREFIX};${{ github.workspace }}/installed" \
-D CMAKE_INSTALL_PREFIX="${{ github.workspace }}/installed" \
${{ matrix.cfg.cmargs }}
cmake --build build --target install
# psi4 with MKL avail for qmefp test
- name: Install Psi4 for QM/EFP testing
if: ${{ matrix.cfg.blas == 'MKL' }}
run: conda install psi4 -c conda-forge

- name: Test (pytest) -- unit tests Python bindings
run: |
PYTHONPATH="${{ github.workspace }}/installed/lib" \
pytest --cache-clear -v -rws --color=yes \
--durations=50 --durations-min=1 --strict-markers \
-k "${{ matrix.cfg.pytest-marker-expr }}" \
"${{ github.workspace }}/installed/"
31 changes: 27 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
cmake_minimum_required(VERSION 3.16)
if (POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif ()

# extract project version from source
file(STRINGS "src/efp.h" _src_efp_h REGEX "LIBEFP_VERSION_STRING")
if (${_src_efp_h} MATCHES "^#define LIBEFP_VERSION_STRING \"(.*)\"$")
set(_libefp_VERSION ${CMAKE_MATCH_1})
endif()

project(
libefp
# sync VERSION here with src/efp.h LIBEFP_VERSION_STRING
# someday when Makefile dropped, configure efp.h.in from cmake
VERSION 1.8.0
VERSION ${_libefp_VERSION}
LANGUAGES C
)
set(libefp_AUTHORS "Ilya A. Kaliman, Lori A. Burns, Dmitry Morozov, Carlos H. Borca, Yen (Terri) Bui, Yongbin Kim, Lyudmila V. Slipchenko")
Expand Down Expand Up @@ -32,6 +40,12 @@ if (${efp}_IS_TOP_LEVEL)
if (DEFINED ENABLE_OPENMP)
message(FATAL_ERROR "Use LIBEFP_ENABLE_OPENMP instead of ENABLE_OPENMP.")
endif()
if (DEFINED FRAGLIB_UNDERSCORE_L)
message(WARNING "Using FRAGLIB_UNDERSCORE_L=OFF is deprecated and may be removed as soon as v1.10. Please adapt your fragment search to handle name and name_L.")
endif()
if (DEFINED FRAGLIB_DEEP)
message(WARNING "Using FRAGLIB_DEEP=OFF is deprecated and may be removed as soon as v1.10. Please adapt your fraglib library usage to handle a list of paths.")
endif()
endif()

option_with_default(CMAKE_BUILD_TYPE "Build type" Release)
Expand All @@ -43,12 +57,15 @@ endif()
option_with_print(LIBEFP_ENABLE_OPENMP "Enable OpenMP parallelization. Psi4 wants OFF" OFF)
option_with_print(ENABLE_GENERIC "Enable mostly static linking in shared library" OFF)
include(xhost) # defines: option(ENABLE_XHOST "Enable processor-specific optimization" ON)
option_with_print(FRAGLIB_UNDERSCORE_L "Installed fragment library has names ending in _L. Psi4 wants OFF" ON)
option_with_print(FRAGLIB_DEEP "Installed fragment libary has hierarchical, not flat, filestructure. Psi4 wants OFF" ON)
option_with_print(FRAGLIB_UNDERSCORE_L "DEPRECATED: Installed fragment library has names ending in _L. Psi4 wants OFF" ON)
option_with_print(FRAGLIB_DEEP "DEPRECATED: Installed fragment libary has hierarchical, not flat, filestructure. Psi4 wants OFF" ON)
option_with_print(INSTALL_DEVEL_HEADERS "Install additional namespaced devel headers beyond convenience efp.h" OFF)
option_with_default(LIBEFP_CMAKECONFIG_INSTALL_DIR "Directory within CMAKE_INSTALL_PREFIX to which CMake configuration files installed" "share/cmake/libefp")
option_with_print(LIBEFP_ENABLE_EFPMD "Build standalone efpmd executable (requires Fortran). This also enables testing" ON)

option_with_default(PYMOD_INSTALL_LIBDIR "If LIBEFP_ENABLE_PYTHON, location within CMAKE_INSTALL_LIBDIR to which python modules are installed" /)
option_with_print(LIBEFP_ENABLE_PYTHON "Build Python bindings (requires CXX, Python, and Pybind11)" OFF)

######################### Process & Validate Options ###########################
include(autocmake_safeguards)
include(custom_static_library)
Expand Down Expand Up @@ -163,6 +180,12 @@ target_link_libraries(
$<$<TARGET_EXISTS:OpenMP::OpenMP_C>:OpenMP::OpenMP_C>
)

# pylibefp bindings
if (LIBEFP_ENABLE_PYTHON)
enable_language(CXX)
add_subdirectory(python)
endif()

# efpmd executable
if (LIBEFP_ENABLE_EFPMD)
# needed to link the Fortran routines in libff into the efpmd executable
Expand Down
Loading

0 comments on commit 96fd560

Please sign in to comment.