Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Merge a2e5128 into 8fa7431
Browse files Browse the repository at this point in the history
  • Loading branch information
mfherbst committed Aug 9, 2018
2 parents 8fa7431 + a2e5128 commit 1e7877f
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 32 deletions.
36 changes: 22 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ env:
# The regex for tests to run (disable running tests by TESTS=0)
- TESTS=1 TESTS_REGEX="gint_tests_"


# Cache the directory cache_libint, such that libint does not need
# to be rebuild each time.
cache:
Expand Down Expand Up @@ -78,7 +79,7 @@ before_install:

matrix:
include:
# Clang 3.5 with disabled c++14 support with libstdc++-4.9
# System clang with disabled c++14 support with libstdc++-4.9
- addons:
apt:
sources: *def_sources
Expand All @@ -89,29 +90,36 @@ matrix:
- export EXTRA_OPTS="-DDRB_MAXIMUM_CXX_STANDARD=11"
- export GCOV="llvm-cov gcov"
compiler: clang
env: CC_COMP="clang" CXX_COMP="clang++"
env: CC_COMP="clang" CXX_COMP="clang++" CXXFLAGS="-DBOOST_PP_VARIADICS=1"
#
# Clang 5.0 (has c++17) with libc++-1
# Note that c++17 is disabled due to cmake < 3.8 where c++17 is not yet ready
# TODO Here we used to test with libc++1 by installing libc++-dev,
# but this does not go well with libint any more
# Clang 5.0 with disabled c++17 support
- addons:
apt:
sources: *def_sources
packages:
- *def_packages
- &clang_newest [ clang-5.0, libc++-dev, llvm-5.0, clang-tidy-5.0 ]
- &clang_newest [ clang-5.0, llvm-5.0, clang-tidy-5.0 ]
install:
- export EXTRA_OPTS="-DDRB_MAXIMUM_CXX_STANDARD=14"
- export GCOV="llvm-cov-5.0 gcov"
compiler: clang
env: CC_COMP="clang-5.0" CXX_COMP="clang++-5.0"
# CXXFLAGS="-DBOOST_PP_VARIADICS=1" is required because the
# variadic macro check built into the current version of boost is not working
env: CC_COMP="clang-5.0" CXX_COMP="clang++-5.0" CXXFLAGS="-DBOOST_PP_VARIADICS=1"
#
# gcc-4.8 (c++11 and without tests, since rapidcheck does not compile like this)
- install:
- export TESTS=0 EXTRA_OPTS="-DGINT_ENABLE_TESTS=OFF"
# gcc-5
- addons:
apt:
sources: *def_sources
packages:
- *def_packages
- g++-5
compiler: gcc
env: CC_COMP="gcc" CXX_COMP="g++"
env: CC_COMP="gcc-5" CXX_COMP="g++-5"
#
# gcc-7 (with tests and c++17)
# Note that c++17 is disabled due to cmake < 3.8 where c++17 is not yet ready
- addons:
apt:
sources: *def_sources
Expand All @@ -124,7 +132,6 @@ matrix:
env: CC_COMP="gcc-7" CXX_COMP="g++-7"
#
# Clang-tidy 5.0
# Note that c++17 is disabled due to cmake < 3.8 where c++17 is not yet ready
- addons:
apt:
sources: *def_sources
Expand All @@ -151,7 +158,8 @@ script:
-DLIBINT_INCLUDE_DIR=$HOME/cache_libint/include
-DLIBINT_LIBRARY=$HOME/cache_libint/lib/libint2.a"
;else
LIBINT_OPTS="-DGINT_LIBINT_MAX_AM=3 -DDEP_BUILD_libint_NJOBS=2"
LIBINT_OPTS="-DGINT_LIBINT_MAX_AM=3 -DDEP_BUILD_libint_NJOBS=2
-DGINT_LIBINT_MAX_MULTIPOLE=2"
;fi
#
# Configure build and test
Expand All @@ -167,7 +175,7 @@ script:
-DGINT_ENABLE_LIBCINT=ON
-DGINT_ENABLE_LIBINT=ON ${LIBINT_OPTS}
-GNinja ..
- cmake --build . --target ${BUILD_TARGET:-all} -- -j ${CORES}
- travis_wait 20 cmake --build . --target ${BUILD_TARGET:-all} -- -j ${CORES}
- if [ "${TESTS}" != "0" ]; then
ctest -j ${CORES} --output-on-failure -R "${TESTS_REGEX}"
;else true; fi
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ More documentation will follow ...
For *building* `gint` the following things are required:
- ``cmake`` >= 3.0.0
- A compiler supporting ``C++11``: ``clang`` starting from `clang-3.5` and `gcc` starting
from `gcc-4.8` should work.
from `gcc-5` should work.
- [``swig``](http://swig.org/) >= 2.0.11
- [``python``](https://www.python.org/) >= 3.4, including the development headers
- The [usual build process](#building-gint) mentioned below
Expand Down
18 changes: 15 additions & 3 deletions cmake/findLibint.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ message(WARNING "AUTOCHECKOUT_FORCED should be worked into this.")
# -------
#

function(SETUP_LIBINT2_FOR_EXTERNAL_BUILD TARGET LIBINT_MAX_AM)
function(SETUP_LIBINT2_FOR_EXTERNAL_BUILD TARGET LIBINT_MAX_AM LIBINT_MAX_MULTIPOLE_ORDER)
# Determine compiler flags which are in use in outer project
# and remove all -W and -f flags
string(REGEX REPLACE "(-(W|f)[^ ]+|-pedantic)" "" TMP
Expand Down Expand Up @@ -81,7 +81,9 @@ function(SETUP_LIBINT2_FOR_EXTERNAL_BUILD TARGET LIBINT_MAX_AM)
"CXX=${CMAKE_CXX_COMPILER}"
#
# Optimisation flags for all compilation processes inside libint
"CXXFLAGS=${CXX_STANDARD_FLAG} ${CLANG_CXX_FLAGS}"
# TODO Note that -DBOOST_PP_VARIADICS=1 was added to work around
# a common bug in boost
"CXXFLAGS=${CXX_STANDARD_FLAG} ${CLANG_CXX_FLAGS} -DBOOST_PP_VARIADICS=1"
"LDFLAGS=${CLANG_LD_FLAGS}"
#
# Optimisation flags for the inner compiler
Expand All @@ -94,6 +96,9 @@ function(SETUP_LIBINT2_FOR_EXTERNAL_BUILD TARGET LIBINT_MAX_AM)
# Optimise maximally up to angular momentum 4
"--with-opt-am=${LIBINT_OPT_AM}"
#
# Limit max multipole order
"--with-multipole-max-order=${LIBINT_MAX_MULTIPOLE_ORDER}"
#
# Disable unrolling shell sets into integrals
"--disable-unrolling"
#
Expand Down Expand Up @@ -140,6 +145,10 @@ function(SETUP_LIBINT2_FOR_EXTERNAL_BUILD TARGET LIBINT_MAX_AM)
endfunction()

function(SETUP_SYSTEM_LIBINT TARGET VERSION)
string(REGEX REPLACE "^([0-9.]+).*" "\\1"
LIBINT_VERSION "${VERSION}")
set(VERSION "${LIBINT_VERSION}")

find_package(Libint2 ${VERSION} QUIET MODULE)
if (NOT LIBINT_FOUND)
return()
Expand Down Expand Up @@ -191,6 +200,8 @@ Try setting Eigen3_DIR to the location.")
message(STATUS "Found eigen3 include directory at ${Eigen3_DIR}")
endif()

# TODO Only do this if libint autocheckout is not forced.
# i.e. read AUTOCHECKOUT_FORCED
if (LIBINT_SEARCH_SYSTEM STREQUAL "" OR LIBINT_SEARCH_SYSTEM)
set(LIBINT_TARGET "System::libint")
SETUP_SYSTEM_LIBINT(${LIBINT_TARGET} ${LIBINT_VERSION})
Expand All @@ -203,7 +214,8 @@ if (LIBINT_SEARCH_SYSTEM STREQUAL "" OR LIBINT_SEARCH_SYSTEM)
endif()
if(AUTOCHECKOUT_MISSING_REPOS)
set(LIBINT_TARGET "External::libint")
SETUP_LIBINT2_FOR_EXTERNAL_BUILD(${LIBINT_TARGET} ${LIBINT_MAX_AM})
SETUP_LIBINT2_FOR_EXTERNAL_BUILD(${LIBINT_TARGET} ${LIBINT_MAX_AM}
${LIBINT_MAX_MULTIPOLE_ORDER})
target_link_libraries(${LIBINT_TARGET} INTERFACE ${EIGEN_TARGET})

message(STATUS "Setting up libint2 as an external project")
Expand Down
8 changes: 6 additions & 2 deletions cmake/setup_optional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ option(GINT_ENABLE_STURMINT "Enable the sturmint library to compute Sturmian int

if (GINT_ENABLE_STURMINT)
include_krims_cmake_module(FindPackageAutocheckoutFallback)
find_package_autocheckout_fallback(sturmint 0.0.0)
find_package_autocheckout_fallback(sturmint 0.0.2)

foreach (build ${DRB_BUILD_TYPES})
set(GINT_DEPENDENCIES_${build} ${GINT_DEPENDENCIES_${build}} ${sturmint_${build}_TARGET})
Expand All @@ -70,6 +70,7 @@ set(GINT_LIBINT_MAX_AM 6 CACHE STRING
"Maximal angular momentum libint can perform integrals over. \
Choose a smaller value to get a faster build."
) # Note: ORCA uses a value of 7 (up to K) in the setting above.
set(GINT_LIBINT_MAX_MULTIPOLE 10 CACHE STRING "Maximal multipole order to use for builds.")

if (GINT_ENABLE_LIBINT)
# Check options:
Expand All @@ -78,13 +79,16 @@ if (GINT_ENABLE_LIBINT)
endif()

# Forward parameters to included module
set(LIBINT_VERSION 2.3.1) # We need at least this version
set(LIBINT_VERSION 2.5.0-beta.1) # We need at least this version
set(LIBINT_SEARCH_SYSTEM ${GINT_LIBINT_USE_SYSTEM})
set(LIBINT_MAX_AM ${GINT_LIBINT_MAX_AM})
set(LIBINT_MAX_MULTIPOLE_ORDER ${GINT_LIBINT_MAX_MULTIPOLE})

include(cmake/findLibint.cmake)
unset(LIBINT_VERSION)
unset(LIBINT_MAX_AM)
unset(LIBINT_SEARCH_SYSTEM)
unset(LIBINT_MAX_MULTIPOLE_ORDER)

set(GINT_DEPENDENCIES ${GINT_DEPENDENCIES} ${LIBINT_TARGET})
enable_feature(libint)
Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ function(setup_example_target TARGET)
endfunction()

add_subdirectory(laplace)
add_subdirectory(rhf)
23 changes: 23 additions & 0 deletions examples/rhf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## ---------------------------------------------------------------------
##
## Copyright (C) 2017 by the gint authors
##
## This file is part of gint.
##
## gint is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## gint is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with gint. If not, see <http://www.gnu.org/licenses/>.
##
## ---------------------------------------------------------------------

add_executable(rhf main.cc)
setup_example_target(rhf)
114 changes: 114 additions & 0 deletions examples/rhf/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//
// Copyright (C) 2017 by the gint authors
//
// This file is part of gint.
//
// gint is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// gint is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with gint. If not, see <http://www.gnu.org/licenses/>.
//

#include <gint/IntegralLookup.hh>
#include <gint/IntegralUpdateKeys.hh>
#include <gint/Structure.hh>
#include <krims/GenMap.hh>
#include <lazyten/SmallVector.hh>
#include <lazyten/eigensystem.hh>

namespace rhf {
void restricted_hartree_fock(const krims::GenMap& intparams, const size_t n_alpha,
const size_t n_orbs = 4, const size_t max_iter = 100) {
using gint::IntegralTypeKeys;
using gint::IntegralUpdateKeys;
using namespace lazyten;

// Get the integrals for the appropriate integral parameters
auto integrals = gint::IntegralLookup<SmallMatrix<double>>(intparams);
auto S_bb = integrals.lookup_integral(IntegralTypeKeys::overlap);
auto T_bb = integrals.lookup_integral(IntegralTypeKeys::kinetic);
auto V_bb = integrals.lookup_integral(IntegralTypeKeys::nuclear_attraction);
auto J_bb = integrals.lookup_integral(IntegralTypeKeys::coulomb);
auto K_bb = integrals.lookup_integral(IntegralTypeKeys::exchange);

// Get an hcore guess
const auto hcore_bb = T_bb + V_bb;
const auto eigensolution = eigensystem_hermitian(hcore_bb, S_bb, n_orbs);

// Current occupied coefficients in convenient data structure
const auto cocc = eigensolution.evectors().subview({0, n_alpha});

// Initialise two-electron terms with guess coefficients
J_bb.update({{IntegralUpdateKeys::coefficients_occupied, cocc}});
K_bb.update({{IntegralUpdateKeys::coefficients_occupied, cocc}});

double oldene = 0;
std::cout << "Iter etot echange" << std::endl;
for (size_t i = 0; i < max_iter; ++i) {
// Obtain new eigenpairs ...
const auto F_bb = hcore_bb + (2 * J_bb - K_bb);
const auto eigensolution = eigensystem_hermitian(F_bb, S_bb, n_orbs);

// ... and new occupied coefficients
const auto cocc = eigensolution.evectors().subview({0, n_alpha});

// Compute HF energies
// For example coulomb energy is tr(C^T J C)
double ene_one_elec = trace(outer_prod_sum(cocc, hcore_bb * cocc));
double ene_coulomb = 2 * trace(outer_prod_sum(cocc, J_bb * cocc));
double ene_exchge = -trace(outer_prod_sum(cocc, K_bb * cocc));
double energy = 2 * (ene_one_elec + .5 * ene_coulomb + .5 * ene_exchge);

// Display current iteration
double energy_change = energy - oldene;
std::cout << i << " " << energy << " " << energy_change << std::endl;
oldene = energy;

// Check for convergence
if (fabs(energy_change) < 1e-6) break;

// Update the two-electron integrals, before coefficients
// go out of scope
J_bb.update({{IntegralUpdateKeys::coefficients_occupied, cocc}});
K_bb.update({{IntegralUpdateKeys::coefficients_occupied, cocc}});
}

std::cout << "Doubly occupied orbitals: " << std::endl;
for (size_t i = 0; i < n_alpha; ++i) {
std::cout << " " << eigensolution.evalues()[i] << std::endl;
}
}
} // namespace rhf

int main() {
gint::Structure be{
{"Be", {{0., 0., 0.}}},
};
const size_t n_alpha = 2;

krims::GenMap params_gauss{
{"basis_type", "gaussian/libint"},
{"basis_set_name", "pc-2"},
{"structure", be},
};

krims::GenMap params_sturm{
{"basis_type", "sturmian/atomic/cs_dummy"},
{"k_exponent", 1.988},
{"n_max", 5},
{"l_max", 1},
{"m_max", 1},
{"structure", be},
};

rhf::restricted_hartree_fock(params_gauss, n_alpha);
return 0;
}
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[flake8]
ignore = E241,E266
max-line-length = 90

[bumpversion]
current_version = 0.0.0
commit = True
tag = True

[bumpversion:file:CMakeLists.txt]
12 changes: 7 additions & 5 deletions src/gint/ERITensor_i.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ void ERITensor_i<Scalar>::contract_with(const iface_multivector_type& c_wa,
std::vector<Scalar> i1_wbcd(n_w * n_bas() * n_bas() * n_bas());

auto contract_kernel = [&i1_wbcd, &c_wa, &absidx_wbcd](
const std::array<krims::Range<size_t>, 4>& batch, const Scalar* values) {
const std::array<krims::Range<size_t>, 4>& batch,
const Scalar* values) {
#ifdef DEBUG
const size_t values_size =
batch[0].length() * batch[1].length() * batch[2].length() * batch[3].length();
Expand Down Expand Up @@ -197,10 +198,9 @@ void ERITensor_i<Scalar>::contract_with(const iface_multivector_type& c_wa,

template <typename Scalar>
void ERITensor_i<Scalar>::extract_block(const std::array<krims::Range<size_t>, 4>& block,
std::vector<Scalar>& out) const {
Scalar* out) const {
using krims::intersection;
assert_size(out.size(), block[0].length() * block[1].length() * block[2].length() *
block[3].length());

assert_greater(block[0].back(), n_bas());
assert_greater(block[1].back(), n_bas());
assert_greater(block[2].back(), n_bas());
Expand All @@ -211,6 +211,8 @@ void ERITensor_i<Scalar>::extract_block(const std::array<krims::Range<size_t>, 4
#ifdef DEBUG
const size_t values_size =
batch[0].length() * batch[1].length() * batch[2].length() * batch[3].length();
const size_t block_size =
block[0].length() * block[1].length() * block[2].length() * block[3].length();
#endif

// Get the intersection of the range we have in the current batch
Expand Down Expand Up @@ -250,7 +252,7 @@ void ERITensor_i<Scalar>::extract_block(const std::array<krims::Range<size_t>, 4
const size_t idx_bch = absidx_bch({{a_bch, b_bch, c_bch, d_bch}});

assert_internal(idx_bch < values_size);
assert_internal(idx_blk < out.size());
assert_internal(idx_blk < block_size);
out[idx_blk] = it[idx_bch];
} // d
} // c
Expand Down
Loading

0 comments on commit 1e7877f

Please sign in to comment.