Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixup #271 #285

Merged
merged 2 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions export/cmake/CMakeLists.txt.export
Original file line number Diff line number Diff line change
Expand Up @@ -415,23 +415,18 @@ if (LIBINT_HAS_CXX_API)
tests/unit/test-shell-order.cc
tests/unit/test-util.cc
)
add_executable(unit_tests_s-libint2 EXCLUDE_FROM_ALL tests/unit/test.cc ${utests_src})
target_compile_definitions(unit_tests_s-libint2 PRIVATE -DNO_LIBINT_COMPILER_CODE)
target_link_libraries(unit_tests_s-libint2 libint2_cxx)
add_test(libint2/unit_s/build "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target unit_tests_s-libint2)
set_tests_properties(libint2/unit_s/build PROPERTIES FIXTURES_SETUP LIBINT2_UNIT_TESTS_EXEC)
add_test(NAME libint2/unit_s/run
COMMAND $<TARGET_FILE:unit_tests_s-libint2>)
set_tests_properties(libint2/unit_s/run
add_executable(unit_tests-libint2 EXCLUDE_FROM_ALL tests/unit/test.cc ${utests_src})
target_compile_definitions(unit_tests-libint2 PRIVATE -DNO_LIBINT_COMPILER_CODE)
target_link_libraries(unit_tests-libint2 libint2_cxx)
add_test(libint2/unit/build "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target unit_tests-libint2)
set_tests_properties(libint2/unit/build PROPERTIES FIXTURES_SETUP LIBINT2_UNIT_TESTS_EXEC)
add_test(NAME libint2/unit/run
COMMAND $<TARGET_FILE:unit_tests-libint2>)
set_tests_properties(libint2/unit/run
PROPERTIES FIXTURES_REQUIRED LIBINT2_UNIT_TESTS_EXEC)
add_executable(unit_tests_g-libint2 EXCLUDE_FROM_ALL tests/unit/test_g.cc ${utests_src})
target_compile_definitions(unit_tests_g-libint2 PRIVATE -DNO_LIBINT_COMPILER_CODE)
target_link_libraries(unit_tests_g-libint2 libint2_cxx)
add_test(libint2/unit_g/build "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target unit_tests_g-libint2)
set_tests_properties(libint2/unit_g/build PROPERTIES FIXTURES_SETUP LIBINT2_UNIT_TESTS_EXEC)
add_test(NAME libint2/unit_g/run
COMMAND $<TARGET_FILE:unit_tests_g-libint2>)
set_tests_properties(libint2/unit_g/run
add_test(NAME libint2/unit/sho=gaussian/run
COMMAND $<TARGET_FILE:unit_tests-libint2> --shgshell-order=gaussian)
set_tests_properties(libint2/unit/sho=gaussian/run
PROPERTIES FIXTURES_REQUIRED LIBINT2_UNIT_TESTS_EXEC)

add_executable(hf-libint2 EXCLUDE_FROM_ALL tests/hartree-fock/hartree-fock.cc)
Expand Down
2 changes: 2 additions & 0 deletions include/libint2/initialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ namespace libint2 {
}
}
/// Setter for the SHGShellOrdering
/// @warning this must be called before the first Engine has been created,
/// thus best to call BEFORE libint2::initialize()
inline void set_solid_harmonics_ordering(SHGShellOrdering sho) {
detail::solid_harmonics_ordering_accessor() = sho;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/hartree-fock/hartree-fock++.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ int main(int argc, char* argv[]) {
/*** =========================== ***/

// initializes the Libint integrals library ... now ready to compute
libint2::initialize();
libint2::set_solid_harmonics_ordering(libint2::SHGShellOrdering_Gaussian);
libint2::initialize();
printf("Configuration G: sho=%d components=%s\n", libint2::solid_harmonics_ordering(), libint2::configuration_accessor().c_str());

// compute OBS non-negligible shell-pair list
Expand Down
1 change: 1 addition & 0 deletions tests/unit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ $(TEST1): $(CXXTEST1OBJ) $(CTEST1OBJ) $(COMPUTE_LIB)

check1:: $(TEST1)
./$^
./$^ --shgshell-order=gaussian

# Source files for timer and tester are to be compiled using CXXGEN
$(TEST1): CXX=$(CXXGEN)
Expand Down
123 changes: 56 additions & 67 deletions tests/unit/test-1body.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
#include "catch.hpp"
#include "fixture.h"

TEST_CASE_METHOD(libint2::unit::DefaultFixture, "electrostatic potential", "[engine][1-body]") {
#define LIBINT2_TEST_ONEBODY(scale) \
int m0, m1; \
FOR_SOLIDHARM_STANDARD(l0, m0) \
FOR_SOLIDHARM_STANDARD(l1, m1) \
const auto i0_s = libint2::INT_SOLIDHARMINDEX_STANDARD(l0, m0); \
const auto i1_s = libint2::INT_SOLIDHARMINDEX_STANDARD(l1, m1); \
const auto i0i1_s = i0_s * n1 + i1_s; \
if (libint2::solid_harmonics_ordering() == \
libint2::SHGShellOrdering_Standard) { \
REQUIRE(engine.results()[0][i0i1_s] / scale == \
Approx(shellset_ref_standard[i0i1_s])); \
} else { \
const auto i0_g = libint2::INT_SOLIDHARMINDEX_GAUSSIAN(l0, m0); \
const auto i1_g = libint2::INT_SOLIDHARMINDEX_GAUSSIAN(l1, m1); \
const auto i0i1_g = i0_g * n1 + i1_g; \
REQUIRE(engine.results()[0][i0i1_g] / scale == \
Approx(shellset_ref_standard[i0i1_s])); \
} \
END_FOR_SOLIDHARM \
END_FOR_SOLIDHARM

TEST_CASE_METHOD(libint2::unit::DefaultFixture, "electrostatic potential",
"[engine][1-body]") {
#if defined(LIBINT2_SUPPORT_ONEBODY)

std::vector<Shell> obs{
Shell{{1.0, 3.0}, {{2, true, {1.0, 0.3}}}, {{0.0, 0.0, 0.0}}},
Shell{{2.0, 5.0}, {{2, true, {1.0, 0.2}}}, {{1.0, 1.0, 1.0}}}};

{
const auto lmax = std::min(3, LIBINT2_MAX_AM_elecpot);
if (lmax >= 2) {
Expand All @@ -17,6 +40,12 @@ TEST_CASE_METHOD(libint2::unit::DefaultFixture, "electrostatic potential", "[eng
engine.prescale_by(scale);
engine.compute(obs[0], obs[0]);
{
const auto l0 = obs[0].contr[0].l;
const auto l1 = obs[0].contr[0].l;
const auto n0 = 2 * l0 + 1;
const auto n1 = 2 * l1 + 1;

// this is laid out in standard solids order
std::vector<double> shellset_ref_standard = {
-1.238239259091998e+01, 0.000000000000000e+00,
0.000000000000000e+00, -5.775996163160049e-02,
Expand All @@ -31,26 +60,19 @@ TEST_CASE_METHOD(libint2::unit::DefaultFixture, "electrostatic potential", "[eng
0.000000000000000e+00, 1.139389632827834e-01,
-1.478824785355970e-02, 0.000000000000000e+00,
-1.241040347301479e+01};
std::vector<double> shellset_ref_gaussian = {
-1.343732979153083e+01, 0.000000000000000e+00, -6.796143730068988e-02, -1.478824785355970e-02, 0.000000000000000e+00,
0.000000000000000e+00, -1.284475452992947e+01, 0.000000000000000e+00, 0.000000000000000e+00, -5.775996163160049e-02,
-6.796143730068988e-02, 0.000000000000000e+00, -1.301230978657952e+01, 1.139389632827834e-01, 0.000000000000000e+00,
-1.478824785355970e-02, 0.000000000000000e+00, 1.139389632827834e-01, -1.241040347301479e+01, 0.000000000000000e+00,
0.000000000000000e+00, -5.775996163160049e-02, 0.000000000000000e+00, 0.000000000000000e+00, -1.238239259091998e+01};
for (int i = 0; i != 25; ++i) {
if (libint2::solid_harmonics_ordering() == libint2::SHGShellOrdering_Standard) {
if (i == 0) printf("Checking 1-body SHO=Standard\n");
REQUIRE(engine.results()[0][i]/scale == Approx(shellset_ref_standard[i]));
} else {
if (i == 0) printf("Checking 1-body SHO=Gaussian\n");
REQUIRE(engine.results()[0][i]/scale == Approx(shellset_ref_gaussian[i]));
}
}

LIBINT2_TEST_ONEBODY(scale);
}

engine.prescale_by(1);
engine.compute(obs[0], obs[1]);
{
const auto l0 = obs[0].contr[0].l;
const auto l1 = obs[1].contr[0].l;
const auto n0 = 2 * l0 + 1;
const auto n1 = 2 * l1 + 1;

// this is laid out in standard solids order
std::vector<double> shellset_ref_standard = {
-4.769186621041819e-01, -9.303619356400431e-01,
-1.559058302243514e+00, -9.290824121864600e-01,
Expand All @@ -65,19 +87,8 @@ TEST_CASE_METHOD(libint2::unit::DefaultFixture, "electrostatic potential", "[eng
-1.120272634615116e-03, -1.385603731947886e+00,
-2.105750177166632e-03, 1.380654897976564e+00,
2.115041199099945e+00};
std::vector<double> shellset_ref_gaussian = {
2.128355904665372e+00, 1.074590109905394e+00, 1.074249956874296e+00, -3.485163651594458e-03, -2.171951144148577e+00,
9.566621490332916e-01, -3.760919234260182e-01, -8.344173649626901e-01, 1.660514988916377e+00, -1.160865205880651e+00,
9.572841308198474e-01, -8.291498398421207e-01, -3.770080831197964e-01, -1.663667687168316e+00, -1.159266418436018e+00,
-2.105750177166632e-03, 1.380654897976564e+00, -1.385603731947886e+00, 2.115041199099945e+00, -1.120272634615116e-03,
-1.559058302243514e+00, -9.290824121864600e-01, -9.303619356400431e-01, -5.835786921473129e-04, -4.769186621041819e-01};
for (int i = 0; i != 25; ++i) {
if (libint2::solid_harmonics_ordering() == libint2::SHGShellOrdering_Standard) {
REQUIRE(engine.results()[0][i] == Approx(shellset_ref_standard[i]));
} else {
REQUIRE(engine.results()[0][i] == Approx(shellset_ref_gaussian[i]));
}
}

LIBINT2_TEST_ONEBODY(1.0);
}
}
}
Expand All @@ -90,55 +101,36 @@ TEST_CASE_METHOD(libint2::unit::DefaultFixture, "electrostatic potential", "[eng
auto engine = Engine(Operator::nuclear, 2, lmax, deriv_order);
engine.set_params(make_point_charges(atoms));
const auto& buf = engine.results();
REQUIRE(libint2::num_geometrical_derivatives(atoms.size() + 2, deriv_order) == buf.size());
REQUIRE(libint2::num_geometrical_derivatives(atoms.size() + 2,
deriv_order) == buf.size());
}
}

#endif // LIBINT2_SUPPORT_ONEBODY
#endif // LIBINT2_SUPPORT_ONEBODY
}

TEST_CASE_METHOD(libint2::unit::DefaultFixture, "erf correctness", "[engine][1-body]") {
TEST_CASE_METHOD(libint2::unit::DefaultFixture, "erf correctness",
"[engine][1-body]") {
#if defined(LIBINT2_SUPPORT_ONEBODY)
if (LIBINT_SHGSHELL_ORDERING != LIBINT_SHGSHELL_ORDERING_STANDARD)
return;
if (LIBINT_SHGSHELL_ORDERING != LIBINT_SHGSHELL_ORDERING_STANDARD) return;

constexpr int l0 = 2;
constexpr int l1 = 2;
constexpr int n0 = 2 * l0 + 1;
constexpr int n1 = 2 * l1 + 1;
std::vector<Shell> obs{
Shell{{1.0, 3.0}, {{2, true, {1.0, 0.3}}}, {{0.0, 0.0, 0.0}}},
Shell{{2.0, 5.0}, {{2, true, {1.0, 0.2}}}, {{1.0, 1.0, 1.0}}}};
Shell{{1.0, 3.0}, {{l0, true, {1.0, 0.3}}}, {{0.0, 0.0, 0.0}}},
Shell{{2.0, 5.0}, {{l1, true, {1.0, 0.2}}}, {{1.0, 1.0, 1.0}}}};
{
const auto lmax = std::min(3, LIBINT2_MAX_AM_elecpot);
if (lmax >= 2) {
auto engine = Engine(Operator::nuclear, 2, lmax);
engine.set_params(make_point_charges(atoms));

const auto scale = 2.3;
engine.prescale_by(scale);
engine.compute(obs[0], obs[0]);
{
// All reference values are pulled from L2.
std::vector<double> shellset_ref = {
-1.238239259091998e+01, 0.000000000000000e+00,
0.000000000000000e+00, -5.775996163160049e-02,
0.000000000000000e+00, 0.000000000000000e+00,
-1.301230978657952e+01, -6.796143730068988e-02,
0.000000000000000e+00, 1.139389632827834e-01,
0.000000000000000e+00, -6.796143730068988e-02,
-1.343732979153083e+01, 0.000000000000000e+00,
-1.478824785355970e-02, -5.775996163160049e-02,
0.000000000000000e+00, 0.000000000000000e+00,
-1.284475452992947e+01, 0.000000000000000e+00,
0.000000000000000e+00, 1.139389632827834e-01,
-1.478824785355970e-02, 0.000000000000000e+00,
-1.241040347301479e+01};
for (int i = 0; i != 25; ++i) {
REQUIRE(engine.results()[0][i]/scale == Approx(shellset_ref[i]));
}
}

engine.prescale_by(1);
engine.compute(obs[0], obs[1]);
{
std::vector<double> shellset_ref = {
// this is laid out in standard solids order
std::vector<double> shellset_ref_standard = {
-4.769186621041819e-01, -9.303619356400431e-01,
-1.559058302243514e+00, -9.290824121864600e-01,
-5.835786921473129e-04, -1.159266418436018e+00,
Expand All @@ -152,12 +144,9 @@ TEST_CASE_METHOD(libint2::unit::DefaultFixture, "erf correctness", "[engine][1-b
-1.120272634615116e-03, -1.385603731947886e+00,
-2.105750177166632e-03, 1.380654897976564e+00,
2.115041199099945e+00};
for (int i = 0; i != 25; ++i) {
REQUIRE(engine.results()[0][i] == Approx(shellset_ref[i]));
}
LIBINT2_TEST_ONEBODY(1.0);
}
}
}
#endif // LIBINT2_SUPPORT_ONEBODY
#endif // LIBINT2_SUPPORT_ONEBODY
}

29 changes: 27 additions & 2 deletions tests/unit/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,35 @@
int main( int argc, char* argv[] )
{
Catch::Session session;

// add custom command line option to specify solid harmonics order

std::string sho_str = "standard";

// Build a new parser on top of Catch2's
using namespace Catch::clara;
auto cli
= session.cli() // Get Catch2's command line parser
| Opt( sho_str, "shgshell-order" ) // bind variable to a new option, with a hint string
["--shgshell-order"] // the option names it will respond to
("solid harmonic order, valid values are \"standard\" (default) and \"gaussian\""); // description string for the help output
// Now pass the new composite back to Catch2 so it uses that
session.cli( cli );

// Let Catch2 (using Clara) parse the command line
int returnCode = session.applyCommandLine( argc, argv );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;

// global setup...
libint2::SHGShellOrdering sho = libint2::SHGShellOrdering_Standard;
if (sho_str == "gaussian")
sho = libint2::SHGShellOrdering_Gaussian;
libint2::set_solid_harmonics_ordering(sho);

// initializes the Libint integrals library ... now ready to compute
libint2::initialize();
libint2::set_solid_harmonics_ordering(libint2::SHGShellOrdering_Standard); // redundant

printf("Configuration S: sho=%d components=%s\n", libint2::solid_harmonics_ordering(), libint2::configuration_accessor().c_str());
printf("Supports: dddd=%d mmmm=%d FF=%d\n", libint2::supports("eri_dddd_d0"), libint2::supports("eri_mmmm_d0"), libint2::supports("eri_FF_d0"));

Expand All @@ -41,7 +66,7 @@ int main( int argc, char* argv[] )
mpf_set_default_prec(256);
#endif

int result = session.run( argc, argv );
int result = session.run();

libint2::finalize(); // done with libint

Expand Down
48 changes: 0 additions & 48 deletions tests/unit/test_g.cc

This file was deleted.