Skip to content

Commit

Permalink
Merge pull request #269 from loriab/windows
Browse files Browse the repository at this point in the history
gss/sss (solid harmonic ordering) runtime switchable
  • Loading branch information
evaleev authored Sep 18, 2023
2 parents 46b2a5f + 78c00e1 commit 5d5dd0b
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 53 deletions.
148 changes: 143 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ on: [push, pull_request]
#env:

jobs:
build:
build_repo:
strategy:
fail-fast: false
matrix:
build_type : [ Release, Debug ]
os : [ macos-latest, ubuntu-20.04 ]
include:
- os: ubuntu-20.04
cxx: /usr/bin/g++-9
cxx: g++-10
- os: macos-latest
cxx: clang++

Expand Down Expand Up @@ -65,8 +65,8 @@ jobs:
if: ${{ steps.skip_check.outputs.should_skip != 'true' && matrix.os == 'ubuntu-20.04' }}
run: |
sudo apt-get update
sudo apt-get install ninja-build g++-9 gfortran-9 liblapack-dev libboost-dev libeigen3-dev ccache python3-numpy python3-scipy
echo "FC=/usr/bin/gfortran-9" >> $GITHUB_ENV
sudo apt-get install ninja-build g++-10 gfortran-10 liblapack-dev libboost-dev libeigen3-dev ccache python3-numpy python3-scipy
echo "FC=/usr/bin/gfortran-10" >> $GITHUB_ENV
echo "EIGEN3_INCLUDE_DIR=/usr/include/eigen3" >> $GITHUB_ENV
- name: Prepare ccache timestamp
Expand Down Expand Up @@ -104,6 +104,16 @@ jobs:
make check
cd src/bin/test_eri && ./stdtests.pl && cd ../../..
make export
echo "ARTIFACT=`ls -1 libint*tgz`" >> $GITHUB_ENV
- name: Archive Library Tarball
if: ${{ steps.skip_check.outputs.should_skip != 'true' && matrix.build_type == 'Release'}}
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: ${{ runner.os }}-${{ matrix.cxx }}
path: ${{github.workspace}}/build/compiler/${{ env.ARTIFACT }}
retention-days: 1

- name: Build+test+install Libint library
if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
Expand All @@ -113,7 +123,7 @@ jobs:
tar -xzf ../compiler/libint-2*.tgz
cd libint-2*
echo "LIBINT_EXPORTED_DIR=`pwd`" >> $GITHUB_ENV
cmake -S . -B build -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPYTHON_EXECUTABLE=`which python3` $BUILD_CONFIG
cmake -S . -B build -DCMAKE_BUILD_TYPE=$BUILD_TYPE $BUILD_CONFIG
cmake --build build --target check
cmake --build build --target install
Expand Down Expand Up @@ -145,4 +155,132 @@ jobs:
cmake --build . --target libint2-python
cmake --build . --target libint2-python-test
build_export:
# to debug the second stage, it is handy to short-circuit the first stage down to ~6 minutes:
# * run only the Linux/Release (remove items from matrix.build_type and matrix.os)
# * don't generate any derivative ints (edit CPPFLAGS)
# * turn off generator testing (comment out "make check" and "stdtests.pl" lines)
# * suppress last two (test library and bindings) steps ("if: false")
needs: build_repo
if: always() && (needs.build_repo.steps.skip_check.outputs.should_skip != 'true')
strategy:
fail-fast: false
matrix:
cfg:
- runs-on: ubuntu-latest
lane: ubuntu-gnu
libargs: >
-DBUILD_SHARED_LIBS=ON
testargs: ""
# note full paths depend on setup-miniconda:
# * Miniforge is miniconda3 vs. Miniconda is miniconda

- runs-on: macos-latest
lane: macos-clang
libargs: >
-DBUILD_SHARED_LIBS=ON
testargs: ""

- runs-on: ubuntu-latest
lane: ubuntu-intel
libargs: >
-DCMAKE_CXX_COMPILER=icpx
-DCMAKE_CXX_FLAGS="--gcc-toolchain=/usr/share/miniconda3/envs/test --sysroot=/usr/share/miniconda3/envs/test/x86_64-conda-linux-gnu/sysroot -target x86_64-conda-linux-gnu"
# flags are long-form of below (envvars not available at spinup)
# -DCMAKE_CXX_FLAGS="--gcc-toolchain=${CONDA_PREFIX} --sysroot=${CONDA_PREFIX}/${HOST}/sysroot -target ${HOST}"
testargs: >
-DCMAKE_CXX_COMPILER=icpx
-DCMAKE_CXX_FLAGS="--gcc-toolchain=/usr/share/miniconda3/envs/test --sysroot=/usr/share/miniconda3/envs/test/x86_64-conda-linux-gnu/sysroot -target x86_64-conda-linux-gnu"
name: "Export • ${{ matrix.cfg.lane }} • ${{ matrix.cfg.libargs }}"
runs-on: ${{ matrix.cfg.runs-on }}

steps:
# Note we're not checking out the repo. All src from Linux tarball generated above.

- name: Write a Conda Env File
shell: bash -l {0}
run: |
cat > export.yaml <<EOF
name: test
channels:
- conda-forge
dependencies:
- cmake
- ninja
- cxx-compiler
- python
- boost
- eigen
- numpy
- scipy
- pybind11
#- dpcpp_linux-64
EOF
if [[ "${{ matrix.cfg.lane }}" == "ubuntu-intel" ]]; then
sed -i "s/#- dpcpp_linux-64/- dpcpp_linux-64/g" export.yaml
fi
cat export.yaml
- name: Create Conda Environment
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
use-mamba: true
python-version: "3.9"
activate-environment: test
channels: conda-forge
environment-file: export.yaml
show-channel-urls: true

- name: Environment Information
shell: bash -l {0}
run: |
conda info
conda list
- uses: actions/download-artifact@v3
with:
name: Linux-g++-10

- name: Extract, Build, Install Libint Library
shell: bash -l {0}
run: |
tar -zxf libint*tgz
mkdir libint && mv libint-2*/* libint/ && cd libint/
cmake \
-S. \
-Bbuild \
-DCMAKE_INSTALL_PREFIX="${{github.workspace}}/installed" \
-DCMAKE_CXX_COMPILER=${CXX} \
-DLIBINT2_PYTHON=ON \
-DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \
${{ matrix.cfg.libargs }}
cmake --build build --target install libint2-python-test
- name: Test Installed Libint library
shell: bash -l {0}
run: |
mkdir test_installed_library && cd test_installed_library
cat > CMakeLists.txt <<EOF
cmake_minimum_required(VERSION 3.16)
project(hf++)
find_package(Libint2 2.7.2 REQUIRED COMPONENTS eri_c4_d0_l2 CXX_ho)
get_target_property(_l2_maxam Libint2::int2 Libint2_MAX_AM_ERI)
message("Libint2_MAX_AM_ERI \${_l2_maxam}")
find_package(Threads) # clang does not autolink threads even though we are using std::thread
add_executable(hf++ EXCLUDE_FROM_ALL "../libint/tests/hartree-fock/hartree-fock++.cc")
target_link_libraries(hf++ Libint2::cxx Threads::Threads)
EOF
cmake -S . -B build -DCMAKE_PREFIX_PATH="${{github.workspace}}/installed" ${{ matrix.cfg.testargs }}
cmake --build build --target hf++
./build/hf++ ../libint/tests/hartree-fock/h2o_rotated.xyz | python ../libint/tests/hartree-fock/hartree-fock++-validate.py ../libint/MakeVars.features
- name: Build (again) & Test Python bindings
shell: bash -l {0}
working-directory: ${{github.workspace}}/libint/python
run: |
cmake . -D LIBINT2_PYTHON=ON -D CMAKE_PREFIX_PATH="${{github.workspace}}/installed" ${{ matrix.cfg.testargs }}
cmake --build . --target libint2-python
cmake --build . --target libint2-python-test
2 changes: 1 addition & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ then either choose path a or b:
Building the Python module
---------------------------
Configure libint (Step 2) with `--enable-eri2 --enable-eri3`, export (Step 3b), untar exported archive:
$ cmake -DPYTHON_EXECUTABLE=`which python3` -DLIBINT2_PYTHON=ON -DCMAKE_PREFIX_PATH=$EIGEN_INSTALL_PATH -DCMAKE_INSTALL_PREFIX=<install-path> .
$ cmake -DPython_EXECUTABLE=`which python3` -DLIBINT2_PYTHON=ON -DCMAKE_PREFIX_PATH=$EIGEN_INSTALL_PATH -DCMAKE_INSTALL_PREFIX=<install-path> .
$ cd python
$ make
$ cd .. && make install
Expand Down
34 changes: 23 additions & 11 deletions export/cmake/CMakeLists.txt.export
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.8) # introduced C++ standards as features
cmake_minimum_required(VERSION 3.16) # 3.15: new Python detection; 3.16 to make the final leap
# 3.8: introduced C++ standards as features
cmake_policy(SET CMP0079 NEW)

project(Libint LANGUAGES CXX C)

Expand Down Expand Up @@ -47,6 +49,7 @@ endif(ENABLE_FORTRAN)
# these are known orderings, must match config.h
set(LIBINT_SHGSHELL_ORDERING_STANDARD 1)
set(LIBINT_SHGSHELL_ORDERING_GAUSSIAN 2)
# August 2023: the following variable has an effect on `INT_SOLIDHARMINDEX(l, m)` but otherwise the choice can be deferred to runtime.
set(LIBINT2_SHGAUSS_ORDERING "standard" CACHE STRING "Use one of the following known orderings for shells of solid harmonic Gaussians:
standard -- standard ordering (-l, -l+1 ... l)
gaussian -- the Gaussian ordering (0, 1, -1, 2, -2, ... l, -l)
Expand Down Expand Up @@ -151,11 +154,15 @@ if (NOT LIBINT_HAS_SYSTEM_BOOST_PREPROCESSOR_VARIADICS OR LIBINT_USE_BUNDLED_BOO
endif()
endif()

# Python is optional, unless ...
if (ENABLE_FORTRAN OR LIBINT2_PYTHON) # ... need fortran
find_package(PythonInterp REQUIRED)
# Python is optionally used for testing.
# * But for Fortran, it's additionally required for preprocessing.
# * And for Python bindings, it's required along with its headers.
if (LIBINT2_PYTHON)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
elseif (ENABLE_FORTRAN)
find_package(Python COMPONENTS Interpreter REQUIRED)
else()
find_package(PythonInterp)
find_package(Python COMPONENTS Interpreter)
endif()

# Set install paths ====================================================================================================
Expand Down Expand Up @@ -351,14 +358,14 @@ if (LIBINT_HAS_CXX_API)
target_link_libraries(hf-libint2 libint2_cxx)
add_test(libint2/hf/build "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target hf-libint2)
set_tests_properties(libint2/hf/build PROPERTIES FIXTURES_SETUP LIBINT2_HFTEST_EXEC)
if (PYTHONINTERP_FOUND)
if (Python_Interpreter_FOUND)
add_test(NAME libint2/hf/run
COMMAND ${CMAKE_COMMAND}
-DtestName=hf-libint2
-DfileName=hartree-fock
-DtestArgs=${PROJECT_SOURCE_DIR}/tests/hartree-fock/h2o.xyz
-DsrcDir=${PROJECT_SOURCE_DIR}
-DpythonExec=${PYTHON_EXECUTABLE}
-DpythonExec=${Python_EXECUTABLE}
-P ${PROJECT_SOURCE_DIR}/cmake/hftest.cmake)
else()
add_test(NAME libint2/hf/run
Expand All @@ -372,14 +379,14 @@ if (LIBINT_HAS_CXX_API)
target_link_libraries(hf++-libint2 libint2_cxx Threads::Threads)
add_test(libint2/hf++/build "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target hf++-libint2)
set_tests_properties(libint2/hf++/build PROPERTIES FIXTURES_SETUP LIBINT2_HFXXTEST_EXEC)
if (PYTHONINTERP_FOUND)
if (Python_Interpreter_FOUND)
add_test(NAME libint2/hf++/run
COMMAND ${CMAKE_COMMAND}
-DtestName=hf++-libint2
-DfileName=hartree-fock++
-DtestArgs=${PROJECT_SOURCE_DIR}/tests/hartree-fock/h2o_rotated.xyz
-DsrcDir=${PROJECT_SOURCE_DIR}
-DpythonExec=${PYTHON_EXECUTABLE}
-DpythonExec=${Python_EXECUTABLE}
-P ${PROJECT_SOURCE_DIR}/cmake/hftest.cmake)
else()
add_test(NAME libint2/hf++/run
Expand Down Expand Up @@ -413,14 +420,14 @@ if (ENABLE_FORTRAN)

# translated Libint_t
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/fortran/libint2_types_f.h
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/fortran/c_to_f.py ${CMAKE_BINARY_DIR}/fortran/libint2.h.i ${CMAKE_BINARY_DIR}/fortran/libint2_types_f.h Libint_t
COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/fortran/c_to_f.py ${CMAKE_BINARY_DIR}/fortran/libint2.h.i ${CMAKE_BINARY_DIR}/fortran/libint2_types_f.h Libint_t
DEPENDS ${CMAKE_BINARY_DIR}/fortran/libint2.h.i
COMMENT "Generating libint2_types_f.h"
)

# extracted defines from libint2_types.h
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/fortran/fortran_incldefs.h
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/fortran/make_defs.py ${PROJECT_SOURCE_DIR}/include/libint2_types.h ${PROJECT_BINARY_DIR}/fortran/fortran_incldefs.h
COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/fortran/make_defs.py ${PROJECT_SOURCE_DIR}/include/libint2_types.h ${PROJECT_BINARY_DIR}/fortran/fortran_incldefs.h
DEPENDS ${PROJECT_SOURCE_DIR}/include/libint2_types.h
COMMENT "Generating fortran_incldefs.h"
)
Expand Down Expand Up @@ -476,6 +483,11 @@ configure_file(
@ONLY
)

# In the future CMake switchover, configuration.h/cc define a string summary of capabilities. @ONLY is maximally deferred in case config2 changes the
# summary (as it used to when LIBINT_SHGSHELL_ORDERING was library-config-time selected).
#configure_file(${PROJECT_SOURCE_DIR}/include/libint2/util/configuration.h.cmake.in ${PROJECT_BINARY_DIR}/include/libint2/util/configuration.h @ONLY)
configure_file(src/configuration.cc.cmake.in ${PROJECT_BINARY_DIR}/src/configuration.cc @ONLY)

configure_file(
include/libint2/basis.h.in
${PROJECT_BINARY_DIR}/include/libint2/basis.h
Expand Down
1 change: 1 addition & 0 deletions include/libint2.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <libint2/util/intrinsic_types.h>
#include <libint2/util/generated/libint2_params.h>
#include <libint2/util/generated/libint2_types.h>
#include <libint2/util/configuration.h>

#if defined(__cplusplus)
#include <libint2/numeric.h>
Expand Down
2 changes: 1 addition & 1 deletion include/libint2/cxxapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# error "Libint2 C++ API requires C++11 support"
#endif

#include <libint2.h> // NB this loads libint2/config.h
#include <libint2.h> // NB this loads libint2/config.h and libint2/util/configuration.h

#ifdef LIBINT_USER_DEFINED_REAL
# error "C++11 API does not support with user-defined real types yet; omit --with-real-type when configuring"
Expand Down
20 changes: 20 additions & 0 deletions include/libint2/initialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <libint2/util/deprecated.h>
#include <libint2/util/singleton.h>
#include <libint2/deriv_map.h>
#include <libint2/shgshell_ordering.h>

namespace libint2 {

Expand All @@ -56,6 +57,10 @@ namespace libint2 {
static std::ostream* value = &std::clog;
return value;
}
inline std::atomic<SHGShellOrdering>& solid_harmonics_ordering_accessor() {
static std::atomic<SHGShellOrdering> value{libint2::SHGShellOrdering_Standard};
return value;
}
} // namespace libint2::detail

/// checks if the libint has been initialized.
Expand All @@ -74,6 +79,11 @@ namespace libint2 {
(void) x; // to suppress unused variable warning (not guaranteed to work) TODO revise when upgrade to C++17
assert(x != nullptr);
verbose_accessor() = verbose;

// initialize() functions that take `SHGShellOrdering sho` as an argument aren't provided because
// * (a) with casting, it's hard to disentangle from `bool verbose`
// * (b) a separate setter is needed anyways for cases like the Python module, where initialize(sho) lives in libint code
// * code in initializer would go here as `solid_harmonics_ordering_accessor() = sho;`
}
}

Expand All @@ -93,8 +103,18 @@ namespace libint2 {
managed_singleton<__initializer>::delete_instance();
verbose_accessor() = true;
verbose_stream_accessor() = &std::clog;
solid_harmonics_ordering_accessor() = libint2::SHGShellOrdering_Standard;
}
}
/// Setter for the SHGShellOrdering
inline void set_solid_harmonics_ordering(SHGShellOrdering sho) {
detail::solid_harmonics_ordering_accessor() = sho;
}
/// Accessor for the SHGShellOrdering
/// @return the val for Operator::nucleus
inline SHGShellOrdering solid_harmonics_ordering() {
return detail::solid_harmonics_ordering_accessor();
}
/// Accessor for the disgnostics stream
/// @return the stream to which the diagnostics will be written if verbose() returns true
inline std::ostream& verbose_stream() {
Expand Down
Loading

0 comments on commit 5d5dd0b

Please sign in to comment.