From 3561114d3ff274df755b84090dc6788efda6dbaa Mon Sep 17 00:00:00 2001 From: "Jonathan M. Waldrop" Date: Wed, 12 Feb 2025 15:23:42 -0600 Subject: [PATCH 1/8] backup --- src/integrals/ao_integrals/ao_integrals.hpp | 39 +++++++ .../ao_integrals/ao_integrals_driver.cpp | 106 ++++++++++++++++++ src/integrals/ao_integrals/j_four_center.cpp | 83 ++++++++++++++ src/integrals/ao_integrals/k_four_center.cpp | 84 ++++++++++++++ src/integrals/integrals_mm.cpp | 10 +- src/integrals/libint/libint.cpp | 6 +- src/integrals/libint/libint.hpp | 4 +- .../ao_integrals/ao_integrals_driver.cpp | 100 +++++++++++++++++ .../integrals/ao_integrals/j_four_center.cpp | 47 ++++++++ .../integrals/ao_integrals/k_four_center.cpp | 47 ++++++++ .../detail_/test_make_libint_basis_set.cpp | 3 +- .../libint/test_arbitrary_operator.cpp | 2 +- tests/cxx/unit/integrals/libint/test_eri2.cpp | 2 +- tests/cxx/unit/integrals/libint/test_eri3.cpp | 2 +- tests/cxx/unit/integrals/libint/test_eri4.cpp | 2 +- .../unit/integrals/libint/test_kinetic.cpp | 2 +- .../cxx/unit/integrals/libint/test_libint.hpp | 42 ------- .../unit/integrals/libint/test_nuclear.cpp | 2 +- .../unit/integrals/libint/test_overlap.cpp | 2 +- .../{water_sto3g.hpp => testing.hpp} | 77 +++++++++++++ 20 files changed, 604 insertions(+), 58 deletions(-) create mode 100644 src/integrals/ao_integrals/ao_integrals.hpp create mode 100644 src/integrals/ao_integrals/ao_integrals_driver.cpp create mode 100644 src/integrals/ao_integrals/j_four_center.cpp create mode 100644 src/integrals/ao_integrals/k_four_center.cpp create mode 100644 tests/cxx/unit/integrals/ao_integrals/ao_integrals_driver.cpp create mode 100644 tests/cxx/unit/integrals/ao_integrals/j_four_center.cpp create mode 100644 tests/cxx/unit/integrals/ao_integrals/k_four_center.cpp delete mode 100644 tests/cxx/unit/integrals/libint/test_libint.hpp rename tests/cxx/unit/integrals/{water_sto3g.hpp => testing.hpp} (51%) diff --git a/src/integrals/ao_integrals/ao_integrals.hpp b/src/integrals/ao_integrals/ao_integrals.hpp new file mode 100644 index 00000000..692221b2 --- /dev/null +++ b/src/integrals/ao_integrals/ao_integrals.hpp @@ -0,0 +1,39 @@ +/* + * Copyright 2024 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include + +namespace integrals::ao_integrals { + +DECLARE_MODULE(AOIntegralsDriver); +DECLARE_MODULE(JFourCenter); +DECLARE_MODULE(KFourCenter); + +inline void set_defaults(pluginplay::ModuleManager& mm) { + const auto ao_driver = "AO integral driver"; + mm.change_submod(ao_driver, "Coulomb matrix", "Four center J builder"); + mm.change_submod(ao_driver, "Exchange matrix", "Four center K builder"); +} + +inline void load_modules(pluginplay::ModuleManager& mm) { + mm.add_module("AO integral driver"); + mm.add_module("Four center J builder"); + mm.add_module("Four center K builder"); + set_defaults(mm); +} + +} // namespace scf::matrix_builder \ No newline at end of file diff --git a/src/integrals/ao_integrals/ao_integrals_driver.cpp b/src/integrals/ao_integrals/ao_integrals_driver.cpp new file mode 100644 index 00000000..1bbbe9ef --- /dev/null +++ b/src/integrals/ao_integrals/ao_integrals_driver.cpp @@ -0,0 +1,106 @@ +/* + * Copyright 2024 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ao_integrals.hpp" + +namespace integrals::ao_integrals { + +namespace { + +const auto desc = R"( +AO Integrals Driver +------------------- +)"; + +} + +using pluginplay::type::submodule_map; +using simde::type::aos; +using simde::type::tensor; + +using pt = simde::aos_op_base_aos; +using t_e_pt = simde::aos_t_e_aos; +using v_en_pt = simde::aos_v_en_aos; +using j_e_pt = simde::aos_j_e_aos; +using k_e_pt = simde::aos_k_e_aos; + +class AODispatcher : public chemist::qm_operator::OperatorVisitor { +public: + using t_e_type = simde::type::t_e_type; + using v_en_type = simde::type::v_en_type; + using j_e_type = simde::type::j_e_type; + using k_e_type = simde::type::k_e_type; + + using submods_type = pluginplay::type::submodule_map; + + AODispatcher(const aos& bra, const aos& ket, submodule_map& submods, + tensor& t) : + m_pbra_(&bra), m_pket_(&ket), m_psubmods_(&submods), m_ptensor_(&t) {} + + void run(const t_e_type& t_e) { + chemist::braket::BraKet input(*m_pbra_, t_e, *m_pket_); + *m_ptensor_ = m_psubmods_->at("Kinetic").run_as(input); + } + + void run(const v_en_type& v_en) { + chemist::braket::BraKet input(*m_pbra_, v_en, *m_pket_); + const auto key = "Electron-Nuclear attraction"; + *m_ptensor_ = m_psubmods_->at(key).run_as(input); + } + + void run(const j_e_type& j_e) { + chemist::braket::BraKet input(*m_pbra_, j_e, *m_pket_); + const auto key = "Coulomb matrix"; + *m_ptensor_ = m_psubmods_->at(key).run_as(input); + } + + void run(const k_e_type& k_e) { + chemist::braket::BraKet input(*m_pbra_, k_e, *m_pket_); + const auto key = "Exchange matrix"; + *m_ptensor_ = m_psubmods_->at(key).run_as(input); + } + +private: + const aos* m_pbra_; + const aos* m_pket_; + submodule_map* m_psubmods_; + tensor* m_ptensor_; +}; + +MODULE_CTOR(AOIntegralsDriver) { + description(desc); + satisfies_property_type(); + add_submodule("Kinetic"); + add_submodule("Electron-Nuclear attraction"); + add_submodule("Coulomb matrix"); + add_submodule("Exchange matrix"); +} + +MODULE_RUN(AOIntegralsDriver) { + const auto&& [braket] = pt::unwrap_inputs(inputs); + const auto& bra = braket.bra(); + const auto& op = braket.op(); + const auto& ket = braket.ket(); + + tensor t; + AODispatcher visitor(bra, ket, submods, t); + op.visit(visitor); + + auto rv = results(); + return pt::wrap_results(rv, std::move(t)); +} + +} // namespace integrals::ao_integrals \ No newline at end of file diff --git a/src/integrals/ao_integrals/j_four_center.cpp b/src/integrals/ao_integrals/j_four_center.cpp new file mode 100644 index 00000000..1c90fc87 --- /dev/null +++ b/src/integrals/ao_integrals/j_four_center.cpp @@ -0,0 +1,83 @@ +/* + * Copyright 2024 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ao_integrals.hpp" + +namespace integrals::ao_integrals { + +using pt = simde::aos_j_e_aos; +using pt_4c = simde::ERI4; + +namespace { + +auto desc = R"( +Four-Center J Builder +--------------------- +)"; + +} +MODULE_CTOR(JFourCenter) { + description(desc); + satisfies_property_type(); + add_submodule("Four-center ERI"); +} + +MODULE_RUN(JFourCenter) { + const auto&& [braket] = pt::unwrap_inputs(inputs); + // TODO: avoid copying AOs + simde::type::aos bra_e0 = braket.bra(); + const auto& j_hat = braket.op(); + simde::type::aos ket_e0 = braket.ket(); + const auto& rho = j_hat.rhs_particle(); + simde::type::aos aos_e1 = rho.basis_set(); + const auto& p = rho.value(); + auto& eri_mod = submods.at("Four-center ERI"); + + // auto aos2_v_aos2 = (bra_e0 * ket_e0 | v_ee | aos_e1 * aos_e1); + simde::type::v_ee_type v_ee; + simde::type::aos_squared e0_pair(bra_e0, ket_e0); + simde::type::aos_squared e1_pair(aos_e1, aos_e1); + chemist::braket::BraKet aos2_v_aos2(e0_pair, v_ee, e1_pair); + const auto& I = eri_mod.run_as(std::move(aos2_v_aos2)); + + // This goes away when j("m,n") = p("l,s")*I("m,n,s,l") works + // { + using eri_alloc = tensorwrapper::allocator::Eigen; + using rho_alloc = tensorwrapper::allocator::Eigen; + using index_pair = Eigen::IndexPair; + using array_t = Eigen::array; + + const auto& I_eigen = eri_alloc::rebind(I.buffer()).value(); + const auto& p_buffer = rho_alloc::rebind(p.buffer()); + const auto& p_eigen = p_buffer.value(); + + array_t contract_modes{index_pair{0, 3}, index_pair(1, 2)}; + using eigen_buffer_type = typename rho_alloc::eigen_buffer_type; + using eigen_tensor_type = typename eigen_buffer_type::data_type; + + eigen_tensor_type j_eigen = p_eigen.contract(I_eigen, contract_modes); + auto j_buffer = std::make_unique(std::move(j_eigen), + p_buffer.layout()); + + using logical_type = tensorwrapper::layout::Logical; + auto playout = p.logical_layout().clone_as(); + simde::type::tensor j(std::move(playout), std::move(j_buffer)); + //} + auto rv = results(); + return pt::wrap_results(rv, std::move(j)); +} + +} // namespace integrals::ao_integrals \ No newline at end of file diff --git a/src/integrals/ao_integrals/k_four_center.cpp b/src/integrals/ao_integrals/k_four_center.cpp new file mode 100644 index 00000000..1d8de586 --- /dev/null +++ b/src/integrals/ao_integrals/k_four_center.cpp @@ -0,0 +1,84 @@ +/* + * Copyright 2024 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ao_integrals.hpp" + +namespace integrals::ao_integrals { + +using pt = simde::aos_k_e_aos; +using pt_4c = simde::ERI4; + +namespace { + +auto desc = R"( +Four-Center K Builder +--------------------- +)"; + +} + +MODULE_CTOR(KFourCenter) { + description(desc); + satisfies_property_type(); + add_submodule("Four-center ERI"); +} + +MODULE_RUN(KFourCenter) { + const auto&& [braket] = pt::unwrap_inputs(inputs); + // TODO: avoid copying AOs + simde::type::aos bra_e0 = braket.bra(); + const auto& k_hat = braket.op(); + simde::type::aos ket_e0 = braket.ket(); + const auto& rho = k_hat.rhs_particle(); + simde::type::aos aos_e1 = rho.basis_set(); + const auto& p = rho.value(); + auto& eri_mod = submods.at("Four-center ERI"); + + // auto aos2_v_aos2 = (bra_e0 * aos_e1 | v_ee | aos_e1 * ket_e0); + simde::type::v_ee_type v_ee; + simde::type::aos_squared e0_pair(bra_e0, aos_e1); + simde::type::aos_squared e1_pair(aos_e1, ket_e0); + chemist::braket::BraKet aos2_v_aos2(e0_pair, v_ee, e1_pair); + const auto& I = eri_mod.run_as(std::move(aos2_v_aos2)); + + // This goes away when k("m,n") = p("l,s")*I("m,l,s,n") works + // { + using eri_alloc = tensorwrapper::allocator::Eigen; + using rho_alloc = tensorwrapper::allocator::Eigen; + using index_pair = Eigen::IndexPair; + using array_t = Eigen::array; + + const auto& I_eigen = eri_alloc::rebind(I.buffer()).value(); + const auto& p_buffer = rho_alloc::rebind(p.buffer()); + const auto& p_eigen = p_buffer.value(); + + array_t contract_modes{index_pair{0, 1}, index_pair(1, 2)}; + using eigen_buffer_type = typename rho_alloc::eigen_buffer_type; + using eigen_tensor_type = typename eigen_buffer_type::data_type; + + eigen_tensor_type k_eigen = p_eigen.contract(I_eigen, contract_modes); + auto k_buffer = std::make_unique(std::move(k_eigen), + p_buffer.layout()); + + using logical_type = tensorwrapper::layout::Logical; + auto playout = p.logical_layout().clone_as(); + simde::type::tensor k(std::move(playout), std::move(k_buffer)); + //} + auto rv = results(); + return pt::wrap_results(rv, std::move(k)); +} + +} // namespace integrals::ao_integrals \ No newline at end of file diff --git a/src/integrals/integrals_mm.cpp b/src/integrals/integrals_mm.cpp index 936e8c16..4b3a1ab6 100644 --- a/src/integrals/integrals_mm.cpp +++ b/src/integrals/integrals_mm.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include "ao_integrals/ao_integrals.hpp" #include "libint/libint.hpp" #include @@ -26,11 +27,16 @@ namespace integrals { * @throw none No throw guarantee */ void set_defaults(pluginplay::ModuleManager& mm) { - // Defaults go here + const auto ao_driver = "AO integral driver"; + mm.change_submod(ao_driver, "Kinetic", "Kinetic"); + mm.change_submod(ao_driver, "Electron-Nuclear attraction", "Nuclear"); + mm.change_submod("Four center J builder", "Four-center ERI", "ERI4"); + mm.change_submod("Four center K builder", "Four-center ERI", "ERI4"); } void load_modules(pluginplay::ModuleManager& mm) { - libint::load_libint(mm); + ao_integrals::load_modules(mm); + libint::load_modules(mm); set_defaults(mm); } diff --git a/src/integrals/libint/libint.cpp b/src/integrals/libint/libint.cpp index cad962dd..2f3639c4 100644 --- a/src/integrals/libint/libint.cpp +++ b/src/integrals/libint/libint.cpp @@ -157,13 +157,13 @@ EXTERN_LIBINT(aos_squared, v_ee_type, aos_squared); #undef EXTERN_LIBINT -void libint_set_defaults(pluginplay::ModuleManager& mm) { +void set_defaults(pluginplay::ModuleManager& mm) { // Set any default associations } #define LOAD_LIBINT(bra, op, ket, key) mm.add_module(key) -void load_libint(pluginplay::ModuleManager& mm) { +void load_modules(pluginplay::ModuleManager& mm) { LOAD_LIBINT(aos, op_base_type, aos, "Evaluate 2-Index BraKet"); LOAD_LIBINT(aos, op_base_type, aos_squared, "Evaluate 3-Index BraKet"); LOAD_LIBINT(aos_squared, op_base_type, aos_squared, @@ -174,7 +174,7 @@ void load_libint(pluginplay::ModuleManager& mm) { LOAD_LIBINT(aos, v_ee_type, aos, "ERI2"); LOAD_LIBINT(aos, v_ee_type, aos_squared, "ERI3"); LOAD_LIBINT(aos_squared, v_ee_type, aos_squared, "ERI4"); - libint_set_defaults(mm); + set_defaults(mm); } #undef LOAD_LIBINT diff --git a/src/integrals/libint/libint.hpp b/src/integrals/libint/libint.hpp index b3f172ce..d05968fb 100644 --- a/src/integrals/libint/libint.hpp +++ b/src/integrals/libint/libint.hpp @@ -48,7 +48,7 @@ DECLARE_MODULE(Libint); * * @throw none No throw guarantee */ -void load_libint(pluginplay::ModuleManager& mm); +void load_modules(pluginplay::ModuleManager& mm); /** @brief Set default module relationships * @@ -56,7 +56,7 @@ void load_libint(pluginplay::ModuleManager& mm); * * @throw none No throw guarantee */ -void libint_set_defaults(pluginplay::ModuleManager& mm); +void set_defaults(pluginplay::ModuleManager& mm); // Forward External Template Declarations #define EXTERN_LIBINT extern template struct Libint diff --git a/tests/cxx/unit/integrals/ao_integrals/ao_integrals_driver.cpp b/tests/cxx/unit/integrals/ao_integrals/ao_integrals_driver.cpp new file mode 100644 index 00000000..6d6a1247 --- /dev/null +++ b/tests/cxx/unit/integrals/ao_integrals/ao_integrals_driver.cpp @@ -0,0 +1,100 @@ +/* + * Copyright 2024 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "../testing.hpp" + +using simde::type::tensor; + +namespace { + +void compare_matrices(const tensor& A, const tensor& A_corr) { + using alloc_type = tensorwrapper::allocator::Eigen; + const auto& A_buffer = alloc_type::rebind(A.buffer()); + const auto& A_corr_buffer = alloc_type::rebind(A_corr.buffer()); + const auto& A_eigen = A_buffer.value(); + const auto& A_corr_eigen = A_corr_buffer.value(); + + const auto tol = 1E-6; + REQUIRE(A_eigen(0, 0) == Catch::Approx(A_corr_eigen(0, 0)).margin(tol)); + REQUIRE(A_eigen(0, 1) == Catch::Approx(A_corr_eigen(0, 1)).margin(tol)); + REQUIRE(A_eigen(1, 0) == Catch::Approx(A_corr_eigen(1, 0)).margin(tol)); + REQUIRE(A_eigen(1, 1) == Catch::Approx(A_corr_eigen(1, 1)).margin(tol)); +} + +} // namespace + +TEST_CASE("AOIntegralsDriver") { + using pt = simde::aos_op_base_aos; + using erased_type = + chemist::braket::BraKet; + + pluginplay::ModuleManager mm; + integrals::load_modules(mm); + REQUIRE(mm.count("AO integral driver")); + auto& mod = mm.at("AO integral driver"); + + // Get basis set + auto mol = test::h2_molecule(); + auto aobs = test::h2_sto3g_basis_set(); + + // Make AOS object + simde::type::aos aos(aobs); + + // Operator Inputs + simde::type::electron e; + auto rho = test::h2_density(); + + SECTION("Calling Kinetic") { + auto& tmod = mm.at("Kinetic"); + simde::type::t_e_type t_e(e); + chemist::braket::BraKet braket(aos, t_e, aos); + erased_type copy_braket(braket); + const auto& T = mod.run_as(copy_braket); + const auto& T_corr = tmod.run_as(braket); + compare_matrices(T, T_corr); + } + + SECTION("Calling Electron-Nuclear Attraction") { + auto& tmod = mm.at("Nuclear"); + simde::type::v_en_type v_en(e, mol.nuclei().as_nuclei()); + chemist::braket::BraKet braket(aos, v_en, aos); + erased_type copy_braket(braket); + const auto& V = mod.run_as(copy_braket); + const auto& V_corr = tmod.run_as(braket); + compare_matrices(V, V_corr); + } + + SECTION("Calling J Matrix") { + auto& jmod = mm.at("Four center J builder"); + simde::type::j_e_type j_e(e, rho); + chemist::braket::BraKet braket(aos, j_e, aos); + erased_type copy_braket(braket); + const auto& J = mod.run_as(copy_braket); + const auto& J_corr = jmod.run_as(braket); + compare_matrices(J, J_corr); + } + + SECTION("Calling K Matrix") { + auto& kmod = mm.at("Four center K builder"); + simde::type::k_e_type k_e(e, rho); + chemist::braket::BraKet braket(aos, k_e, aos); + erased_type copy_braket(braket); + const auto& K = mod.run_as(copy_braket); + const auto& K_corr = kmod.run_as(braket); + compare_matrices(K, K_corr); + } +} \ No newline at end of file diff --git a/tests/cxx/unit/integrals/ao_integrals/j_four_center.cpp b/tests/cxx/unit/integrals/ao_integrals/j_four_center.cpp new file mode 100644 index 00000000..2ab76343 --- /dev/null +++ b/tests/cxx/unit/integrals/ao_integrals/j_four_center.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2024 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "../testing.hpp" + +TEST_CASE("Four center J builder") { + using pt = simde::aos_j_e_aos; + + pluginplay::ModuleManager mm; + integrals::load_modules(mm); + REQUIRE(mm.count("Four center J builder")); + + // Get basis set + auto mol = test::h2_molecule(); + auto aobs = test::h2_sto3g_basis_set(); + + // Make AOS object + simde::type::aos aos(aobs); + + // Make Operator + simde::type::j_e_type op(simde::type::electron{}, test::h2_density()); + + // Make BraKet Input + chemist::braket::BraKet braket(aos, op, aos); + + // Call module + const auto& T = mm.at("Four center J builder").run_as(braket); + + auto t = test::eigen_buffer<2>(T.buffer()); + REQUIRE(t.value()(0, 0) == Catch::Approx(0.71438149).margin(1E-6)); + REQUIRE(t.value()(0, 1) == Catch::Approx(0.47471072).margin(1E-6)); + REQUIRE(t.value()(1, 0) == Catch::Approx(0.47471072).margin(1E-6)); + REQUIRE(t.value()(1, 1) == Catch::Approx(0.71438149).margin(1E-6)); +} \ No newline at end of file diff --git a/tests/cxx/unit/integrals/ao_integrals/k_four_center.cpp b/tests/cxx/unit/integrals/ao_integrals/k_four_center.cpp new file mode 100644 index 00000000..7ca28148 --- /dev/null +++ b/tests/cxx/unit/integrals/ao_integrals/k_four_center.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2024 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "../testing.hpp" + +TEST_CASE("Four center K builder") { + using pt = simde::aos_k_e_aos; + + pluginplay::ModuleManager mm; + integrals::load_modules(mm); + REQUIRE(mm.count("Four center K builder")); + + // Get basis set + auto mol = test::h2_molecule(); + auto aobs = test::h2_sto3g_basis_set(); + + // Make AOS object + simde::type::aos aos(aobs); + + // Make Operator + simde::type::k_e_type op(simde::type::electron{}, test::h2_density()); + + // Make BraKet Input + chemist::braket::BraKet braket(aos, op, aos); + + // Call module + const auto& T = mm.at("Four center K builder").run_as(braket); + + auto t = test::eigen_buffer<2>(T.buffer()); + REQUIRE(t.value()(0, 0) == Catch::Approx(0.627264).margin(1E-6)); + REQUIRE(t.value()(0, 1) == Catch::Approx(0.561828).margin(1E-6)); + REQUIRE(t.value()(1, 0) == Catch::Approx(0.561828).margin(1E-6)); + REQUIRE(t.value()(1, 1) == Catch::Approx(0.627264).margin(1E-6)); +} \ No newline at end of file diff --git a/tests/cxx/unit/integrals/libint/detail_/test_make_libint_basis_set.cpp b/tests/cxx/unit/integrals/libint/detail_/test_make_libint_basis_set.cpp index a1a85110..cee03ffd 100644 --- a/tests/cxx/unit/integrals/libint/detail_/test_make_libint_basis_set.cpp +++ b/tests/cxx/unit/integrals/libint/detail_/test_make_libint_basis_set.cpp @@ -14,10 +14,9 @@ * limitations under the License. */ -#include "../../water_sto3g.hpp" +#include "../../testing.hpp" #include "integrals/libint/detail_/make_libint_basis_set.hpp" #include "libint_basis_set_water.hpp" -#include TEST_CASE("make_libint_basis_set") { using integrals::libint::detail_::make_libint_basis_set; diff --git a/tests/cxx/unit/integrals/libint/test_arbitrary_operator.cpp b/tests/cxx/unit/integrals/libint/test_arbitrary_operator.cpp index 1f78c0aa..71d0eda4 100644 --- a/tests/cxx/unit/integrals/libint/test_arbitrary_operator.cpp +++ b/tests/cxx/unit/integrals/libint/test_arbitrary_operator.cpp @@ -15,7 +15,7 @@ */ #include "integrals/uncertain_types.hpp" -#include "test_libint.hpp" +#include "../testing.hpp" using udouble = integrals::type::uncertain_double; constexpr bool has_sigma = integrals::type::has_sigma(); diff --git a/tests/cxx/unit/integrals/libint/test_eri2.cpp b/tests/cxx/unit/integrals/libint/test_eri2.cpp index d1a61bbb..4b1e8c09 100644 --- a/tests/cxx/unit/integrals/libint/test_eri2.cpp +++ b/tests/cxx/unit/integrals/libint/test_eri2.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "test_libint.hpp" +#include "../testing.hpp" TEST_CASE("ERI2") { using test_pt = simde::ERI2; diff --git a/tests/cxx/unit/integrals/libint/test_eri3.cpp b/tests/cxx/unit/integrals/libint/test_eri3.cpp index ae16ebea..ebca158e 100644 --- a/tests/cxx/unit/integrals/libint/test_eri3.cpp +++ b/tests/cxx/unit/integrals/libint/test_eri3.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "test_libint.hpp" +#include "../testing.hpp" TEST_CASE("ERI3") { using test_pt = simde::ERI3; diff --git a/tests/cxx/unit/integrals/libint/test_eri4.cpp b/tests/cxx/unit/integrals/libint/test_eri4.cpp index c82a0628..58268edd 100644 --- a/tests/cxx/unit/integrals/libint/test_eri4.cpp +++ b/tests/cxx/unit/integrals/libint/test_eri4.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "test_libint.hpp" +#include "../testing.hpp" TEST_CASE("ERI4") { using test_pt = simde::ERI4; diff --git a/tests/cxx/unit/integrals/libint/test_kinetic.cpp b/tests/cxx/unit/integrals/libint/test_kinetic.cpp index 15bed72f..9d9d93f2 100644 --- a/tests/cxx/unit/integrals/libint/test_kinetic.cpp +++ b/tests/cxx/unit/integrals/libint/test_kinetic.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "test_libint.hpp" +#include "../testing.hpp" TEST_CASE("Kinetic") { using test_pt = simde::aos_t_e_aos; diff --git a/tests/cxx/unit/integrals/libint/test_libint.hpp b/tests/cxx/unit/integrals/libint/test_libint.hpp deleted file mode 100644 index 7a51fccc..00000000 --- a/tests/cxx/unit/integrals/libint/test_libint.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2024 NWChemEx-Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../water_sto3g.hpp" -#include -#include -#include - -namespace test { - -template -auto eigen_buffer(const tensorwrapper::buffer::BufferBase& buffer) { - return static_cast&>( - buffer); -} - -template -auto trace(const tensorwrapper::buffer::Eigen& t) { - Eigen::Tensor trace = t.value().trace(); - return trace.coeff(); -} - -template -auto norm(const tensorwrapper::buffer::Eigen& t) { - Eigen::Tensor norm = - t.value().square().sum().sqrt(); - return norm.coeff(); -} -} // namespace test \ No newline at end of file diff --git a/tests/cxx/unit/integrals/libint/test_nuclear.cpp b/tests/cxx/unit/integrals/libint/test_nuclear.cpp index 9cb163da..26c34a93 100644 --- a/tests/cxx/unit/integrals/libint/test_nuclear.cpp +++ b/tests/cxx/unit/integrals/libint/test_nuclear.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "test_libint.hpp" +#include "../testing.hpp" TEST_CASE("Nuclear") { using test_pt = simde::aos_v_en_aos; diff --git a/tests/cxx/unit/integrals/libint/test_overlap.cpp b/tests/cxx/unit/integrals/libint/test_overlap.cpp index 190b7f2c..535c9afc 100644 --- a/tests/cxx/unit/integrals/libint/test_overlap.cpp +++ b/tests/cxx/unit/integrals/libint/test_overlap.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "test_libint.hpp" +#include "../testing.hpp" TEST_CASE("Overlap") { using test_pt = simde::aos_s_e_aos; diff --git a/tests/cxx/unit/integrals/water_sto3g.hpp b/tests/cxx/unit/integrals/testing.hpp similarity index 51% rename from tests/cxx/unit/integrals/water_sto3g.hpp rename to tests/cxx/unit/integrals/testing.hpp index 797a87e2..402dbc50 100644 --- a/tests/cxx/unit/integrals/water_sto3g.hpp +++ b/tests/cxx/unit/integrals/testing.hpp @@ -15,10 +15,38 @@ */ #pragma once +#include + +// For common inputs #include +// Common Catch2 includes +#include +#include + namespace test { +// Checking eigen outputs +template +auto eigen_buffer(const tensorwrapper::buffer::BufferBase& buffer) { + return static_cast&>( + buffer); +} + +template +auto trace(const tensorwrapper::buffer::Eigen& t) { + Eigen::Tensor trace = t.value().trace(); + return trace.coeff(); +} + +template +auto norm(const tensorwrapper::buffer::Eigen& t) { + Eigen::Tensor norm = + t.value().square().sum().sqrt(); + return norm.coeff(); +} + +// Inputs for Water tests inline simde::type::molecule water_molecule() { using atom_t = simde::type::atom; using molecule_t = simde::type::molecule; @@ -70,4 +98,53 @@ inline simde::type::ao_basis_set water_sto3g_basis_set() { return bs; } +// Inputs for H2 tests +inline simde::type::molecule h2_molecule() { + using atom_t = simde::type::atom; + using molecule_t = simde::type::molecule; + atom_t H0("H", 1ul, 1836.15, 0.0, 0.0, 0.0); + atom_t H1("H", 1ul, 1836.15, 0.0, 0.0, 1.3984); + return molecule_t{H0, H1}; +} + +inline simde::type::ao_basis_set h2_sto3g_basis_set() { + using ao_basis_t = simde::type::ao_basis_set; + using atomic_basis_t = simde::type::atomic_basis_set; + using cg_t = simde::type::contracted_gaussian; + using point_t = simde::type::point; + using doubles_t = std::vector; + + auto mol = water_molecule(); + point_t r0 = mol[0].as_nucleus(); + point_t r1 = mol[1].as_nucleus(); + + doubles_t cs{0.1543289673, 0.5353281423, 0.4446345422}; + doubles_t es{3.425250914, 0.6239137298, 0.1688554040}; + cg_t cg0(cs.begin(), cs.end(), es.begin(), es.end(), r0); + cg_t cg1(cs.begin(), cs.end(), es.begin(), es.end(), r1); + atomic_basis_t h0("sto-3g", 1, r0); + atomic_basis_t h1("sto-3g", 1, r1); + h0.add_shell(chemist::ShellType::cartesian, 0, cg0); + h1.add_shell(chemist::ShellType::cartesian, 0, cg1); + + ao_basis_t bs; + bs.add_center(h0); + bs.add_center(h1); + return bs; +} + +inline auto h2_mos() { + using mos_type = simde::type::mos; + using tensor_type = typename mos_type::transform_type; + tensor_type c({{-0.565516, -1.07019}, {-0.565516, 1.07019}}); + return mos_type(simde::type::aos(h2_sto3g_basis_set()), std::move(c)); +} + +inline auto h2_density() { + using density_type = simde::type::decomposable_e_density; + typename density_type::value_type rho( + {{0.31980835, 0.31980835}, {0.31980835, 0.31980835}}); + return density_type(rho, h2_mos()); +} + } // namespace test From 4fb27ac3399049c4b19b5e88210dd31c26902198 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Waldrop" Date: Wed, 12 Feb 2025 16:02:25 -0600 Subject: [PATCH 2/8] AO Integrals moved and tests passing --- tests/cxx/unit/integrals/ao_integrals/j_four_center.cpp | 8 ++++---- tests/cxx/unit/integrals/ao_integrals/k_four_center.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/cxx/unit/integrals/ao_integrals/j_four_center.cpp b/tests/cxx/unit/integrals/ao_integrals/j_four_center.cpp index 2ab76343..da0d66b2 100644 --- a/tests/cxx/unit/integrals/ao_integrals/j_four_center.cpp +++ b/tests/cxx/unit/integrals/ao_integrals/j_four_center.cpp @@ -40,8 +40,8 @@ TEST_CASE("Four center J builder") { const auto& T = mm.at("Four center J builder").run_as(braket); auto t = test::eigen_buffer<2>(T.buffer()); - REQUIRE(t.value()(0, 0) == Catch::Approx(0.71438149).margin(1E-6)); - REQUIRE(t.value()(0, 1) == Catch::Approx(0.47471072).margin(1E-6)); - REQUIRE(t.value()(1, 0) == Catch::Approx(0.47471072).margin(1E-6)); - REQUIRE(t.value()(1, 1) == Catch::Approx(0.71438149).margin(1E-6)); + REQUIRE(t.value()(0, 0) == Catch::Approx(0.56044143).margin(1E-6)); + REQUIRE(t.value()(0, 1) == Catch::Approx(0.24704427).margin(1E-6)); + REQUIRE(t.value()(1, 0) == Catch::Approx(0.24704427).margin(1E-6)); + REQUIRE(t.value()(1, 1) == Catch::Approx(0.56044143).margin(1E-6)); } \ No newline at end of file diff --git a/tests/cxx/unit/integrals/ao_integrals/k_four_center.cpp b/tests/cxx/unit/integrals/ao_integrals/k_four_center.cpp index 7ca28148..f001ea16 100644 --- a/tests/cxx/unit/integrals/ao_integrals/k_four_center.cpp +++ b/tests/cxx/unit/integrals/ao_integrals/k_four_center.cpp @@ -40,8 +40,8 @@ TEST_CASE("Four center K builder") { const auto& T = mm.at("Four center K builder").run_as(braket); auto t = test::eigen_buffer<2>(T.buffer()); - REQUIRE(t.value()(0, 0) == Catch::Approx(0.627264).margin(1E-6)); - REQUIRE(t.value()(0, 1) == Catch::Approx(0.561828).margin(1E-6)); - REQUIRE(t.value()(1, 0) == Catch::Approx(0.561828).margin(1E-6)); - REQUIRE(t.value()(1, 1) == Catch::Approx(0.627264).margin(1E-6)); + REQUIRE(t.value()(0, 0) == Catch::Approx(0.45617623).margin(1E-6)); + REQUIRE(t.value()(0, 1) == Catch::Approx(0.35130947).margin(1E-6)); + REQUIRE(t.value()(1, 0) == Catch::Approx(0.35130947).margin(1E-6)); + REQUIRE(t.value()(1, 1) == Catch::Approx(0.45617623).margin(1E-6)); } \ No newline at end of file From 323b496b8336cf800a39c700f9afd63a4c683579 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 12 Feb 2025 22:05:19 +0000 Subject: [PATCH 3/8] Committing clang-format changes --- src/integrals/ao_integrals/ao_integrals.hpp | 2 +- .../ao_integrals/ao_integrals_driver.cpp | 18 +++++++++--------- .../libint/test_arbitrary_operator.cpp | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/integrals/ao_integrals/ao_integrals.hpp b/src/integrals/ao_integrals/ao_integrals.hpp index 692221b2..f7b1a8a5 100644 --- a/src/integrals/ao_integrals/ao_integrals.hpp +++ b/src/integrals/ao_integrals/ao_integrals.hpp @@ -36,4 +36,4 @@ inline void load_modules(pluginplay::ModuleManager& mm) { set_defaults(mm); } -} // namespace scf::matrix_builder \ No newline at end of file +} // namespace integrals::ao_integrals \ No newline at end of file diff --git a/src/integrals/ao_integrals/ao_integrals_driver.cpp b/src/integrals/ao_integrals/ao_integrals_driver.cpp index 1bbbe9ef..16879a65 100644 --- a/src/integrals/ao_integrals/ao_integrals_driver.cpp +++ b/src/integrals/ao_integrals/ao_integrals_driver.cpp @@ -31,18 +31,18 @@ using pluginplay::type::submodule_map; using simde::type::aos; using simde::type::tensor; -using pt = simde::aos_op_base_aos; -using t_e_pt = simde::aos_t_e_aos; -using v_en_pt = simde::aos_v_en_aos; -using j_e_pt = simde::aos_j_e_aos; -using k_e_pt = simde::aos_k_e_aos; +using pt = simde::aos_op_base_aos; +using t_e_pt = simde::aos_t_e_aos; +using v_en_pt = simde::aos_v_en_aos; +using j_e_pt = simde::aos_j_e_aos; +using k_e_pt = simde::aos_k_e_aos; class AODispatcher : public chemist::qm_operator::OperatorVisitor { public: - using t_e_type = simde::type::t_e_type; - using v_en_type = simde::type::v_en_type; - using j_e_type = simde::type::j_e_type; - using k_e_type = simde::type::k_e_type; + using t_e_type = simde::type::t_e_type; + using v_en_type = simde::type::v_en_type; + using j_e_type = simde::type::j_e_type; + using k_e_type = simde::type::k_e_type; using submods_type = pluginplay::type::submodule_map; diff --git a/tests/cxx/unit/integrals/libint/test_arbitrary_operator.cpp b/tests/cxx/unit/integrals/libint/test_arbitrary_operator.cpp index 71d0eda4..1bf408eb 100644 --- a/tests/cxx/unit/integrals/libint/test_arbitrary_operator.cpp +++ b/tests/cxx/unit/integrals/libint/test_arbitrary_operator.cpp @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "integrals/uncertain_types.hpp" #include "../testing.hpp" +#include "integrals/uncertain_types.hpp" using udouble = integrals::type::uncertain_double; constexpr bool has_sigma = integrals::type::has_sigma(); From c389021fba91fae6dcbd9f0f590319247a0ba000 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Waldrop" Date: Thu, 13 Feb 2025 12:23:51 -0600 Subject: [PATCH 4/8] simplify four-center J and K --- src/integrals/ao_integrals/j_four_center.cpp | 24 ++------------------ src/integrals/ao_integrals/k_four_center.cpp | 24 ++------------------ 2 files changed, 4 insertions(+), 44 deletions(-) diff --git a/src/integrals/ao_integrals/j_four_center.cpp b/src/integrals/ao_integrals/j_four_center.cpp index 1c90fc87..49c13814 100644 --- a/src/integrals/ao_integrals/j_four_center.cpp +++ b/src/integrals/ao_integrals/j_four_center.cpp @@ -53,29 +53,9 @@ MODULE_RUN(JFourCenter) { chemist::braket::BraKet aos2_v_aos2(e0_pair, v_ee, e1_pair); const auto& I = eri_mod.run_as(std::move(aos2_v_aos2)); - // This goes away when j("m,n") = p("l,s")*I("m,n,s,l") works - // { - using eri_alloc = tensorwrapper::allocator::Eigen; - using rho_alloc = tensorwrapper::allocator::Eigen; - using index_pair = Eigen::IndexPair; - using array_t = Eigen::array; + simde::type::tensor j; + j.multiplication_assignment("i,j", p("k,l"), I("i,j,k,l")); - const auto& I_eigen = eri_alloc::rebind(I.buffer()).value(); - const auto& p_buffer = rho_alloc::rebind(p.buffer()); - const auto& p_eigen = p_buffer.value(); - - array_t contract_modes{index_pair{0, 3}, index_pair(1, 2)}; - using eigen_buffer_type = typename rho_alloc::eigen_buffer_type; - using eigen_tensor_type = typename eigen_buffer_type::data_type; - - eigen_tensor_type j_eigen = p_eigen.contract(I_eigen, contract_modes); - auto j_buffer = std::make_unique(std::move(j_eigen), - p_buffer.layout()); - - using logical_type = tensorwrapper::layout::Logical; - auto playout = p.logical_layout().clone_as(); - simde::type::tensor j(std::move(playout), std::move(j_buffer)); - //} auto rv = results(); return pt::wrap_results(rv, std::move(j)); } diff --git a/src/integrals/ao_integrals/k_four_center.cpp b/src/integrals/ao_integrals/k_four_center.cpp index 1d8de586..e246f131 100644 --- a/src/integrals/ao_integrals/k_four_center.cpp +++ b/src/integrals/ao_integrals/k_four_center.cpp @@ -54,29 +54,9 @@ MODULE_RUN(KFourCenter) { chemist::braket::BraKet aos2_v_aos2(e0_pair, v_ee, e1_pair); const auto& I = eri_mod.run_as(std::move(aos2_v_aos2)); - // This goes away when k("m,n") = p("l,s")*I("m,l,s,n") works - // { - using eri_alloc = tensorwrapper::allocator::Eigen; - using rho_alloc = tensorwrapper::allocator::Eigen; - using index_pair = Eigen::IndexPair; - using array_t = Eigen::array; + simde::type::tensor k; + k.multiplication_assignment("i,j", p("k,l"), I("i,k,j,l")); - const auto& I_eigen = eri_alloc::rebind(I.buffer()).value(); - const auto& p_buffer = rho_alloc::rebind(p.buffer()); - const auto& p_eigen = p_buffer.value(); - - array_t contract_modes{index_pair{0, 1}, index_pair(1, 2)}; - using eigen_buffer_type = typename rho_alloc::eigen_buffer_type; - using eigen_tensor_type = typename eigen_buffer_type::data_type; - - eigen_tensor_type k_eigen = p_eigen.contract(I_eigen, contract_modes); - auto k_buffer = std::make_unique(std::move(k_eigen), - p_buffer.layout()); - - using logical_type = tensorwrapper::layout::Logical; - auto playout = p.logical_layout().clone_as(); - simde::type::tensor k(std::move(playout), std::move(k_buffer)); - //} auto rv = results(); return pt::wrap_results(rv, std::move(k)); } From 56ab5983eb8f9c0d6529eab14afb0129bf85b372 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Waldrop" Date: Thu, 13 Feb 2025 13:37:30 -0600 Subject: [PATCH 5/8] reorganize four center J and K --- src/integrals/ao_integrals/j_four_center.cpp | 26 +++++++++----------- src/integrals/ao_integrals/k_four_center.cpp | 26 +++++++++----------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/integrals/ao_integrals/j_four_center.cpp b/src/integrals/ao_integrals/j_four_center.cpp index 49c13814..7d09eefd 100644 --- a/src/integrals/ao_integrals/j_four_center.cpp +++ b/src/integrals/ao_integrals/j_four_center.cpp @@ -37,21 +37,19 @@ MODULE_CTOR(JFourCenter) { MODULE_RUN(JFourCenter) { const auto&& [braket] = pt::unwrap_inputs(inputs); - // TODO: avoid copying AOs - simde::type::aos bra_e0 = braket.bra(); - const auto& j_hat = braket.op(); - simde::type::aos ket_e0 = braket.ket(); - const auto& rho = j_hat.rhs_particle(); - simde::type::aos aos_e1 = rho.basis_set(); - const auto& p = rho.value(); - auto& eri_mod = submods.at("Four-center ERI"); - - // auto aos2_v_aos2 = (bra_e0 * ket_e0 | v_ee | aos_e1 * aos_e1); + auto bra = braket.bra(); + auto ket = braket.ket(); + const auto& j_hat = braket.op(); + const auto& rho = j_hat.rhs_particle(); + const auto& p = rho.value(); + auto rho_aos = rho.basis_set(); + auto& eri_mod = submods.at("Four-center ERI"); + simde::type::v_ee_type v_ee; - simde::type::aos_squared e0_pair(bra_e0, ket_e0); - simde::type::aos_squared e1_pair(aos_e1, aos_e1); - chemist::braket::BraKet aos2_v_aos2(e0_pair, v_ee, e1_pair); - const auto& I = eri_mod.run_as(std::move(aos2_v_aos2)); + simde::type::aos_squared ij_pair(bra, ket); + simde::type::aos_squared kl_pair(rho_aos, rho_aos); + chemist::braket::BraKet ij_v_kl(ij_pair, v_ee, kl_pair); + const auto& I = eri_mod.run_as(std::move(ij_v_kl)); simde::type::tensor j; j.multiplication_assignment("i,j", p("k,l"), I("i,j,k,l")); diff --git a/src/integrals/ao_integrals/k_four_center.cpp b/src/integrals/ao_integrals/k_four_center.cpp index e246f131..651c18fc 100644 --- a/src/integrals/ao_integrals/k_four_center.cpp +++ b/src/integrals/ao_integrals/k_four_center.cpp @@ -38,24 +38,22 @@ MODULE_CTOR(KFourCenter) { MODULE_RUN(KFourCenter) { const auto&& [braket] = pt::unwrap_inputs(inputs); - // TODO: avoid copying AOs - simde::type::aos bra_e0 = braket.bra(); - const auto& k_hat = braket.op(); - simde::type::aos ket_e0 = braket.ket(); - const auto& rho = k_hat.rhs_particle(); - simde::type::aos aos_e1 = rho.basis_set(); - const auto& p = rho.value(); - auto& eri_mod = submods.at("Four-center ERI"); + auto bra = braket.bra(); + auto ket = braket.ket(); + const auto& j_hat = braket.op(); + const auto& rho = j_hat.rhs_particle(); + const auto& p = rho.value(); + auto rho_aos = rho.basis_set(); + auto& eri_mod = submods.at("Four-center ERI"); - // auto aos2_v_aos2 = (bra_e0 * aos_e1 | v_ee | aos_e1 * ket_e0); simde::type::v_ee_type v_ee; - simde::type::aos_squared e0_pair(bra_e0, aos_e1); - simde::type::aos_squared e1_pair(aos_e1, ket_e0); - chemist::braket::BraKet aos2_v_aos2(e0_pair, v_ee, e1_pair); - const auto& I = eri_mod.run_as(std::move(aos2_v_aos2)); + simde::type::aos_squared ik_pair(bra, rho_aos); + simde::type::aos_squared lj_pair(rho_aos, ket); + chemist::braket::BraKet ik_v_lj(ik_pair, v_ee, ik_pair); + const auto& I = eri_mod.run_as(std::move(ik_v_lj)); simde::type::tensor k; - k.multiplication_assignment("i,j", p("k,l"), I("i,k,j,l")); + k.multiplication_assignment("i,j", p("k,l"), I("i,k,l,j")); auto rv = results(); return pt::wrap_results(rv, std::move(k)); From 71a21208f23b1cebae30322f6d58802e7054a0e3 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Waldrop" Date: Thu, 13 Feb 2025 14:56:50 -0600 Subject: [PATCH 6/8] Density fitting modules outlined, nothing works [skip ci] --- src/integrals/ao_integrals/ao_integrals.hpp | 21 +++++- src/integrals/ao_integrals/coulomb_metric.cpp | 51 ++++++++++++++ src/integrals/ao_integrals/df_integral.cpp | 60 ++++++++++++++++ .../ao_integrals/j_density_fitted.cpp | 69 ++++++++++++++++++ .../ao_integrals/k_density_fitted.cpp | 70 +++++++++++++++++++ src/integrals/integrals_mm.cpp | 8 ++- .../integrals/ao_integrals/coulomb_metric.cpp | 44 ++++++++++++ .../integrals/ao_integrals/df_integral.cpp | 45 ++++++++++++ .../ao_integrals/j_density_fitted.cpp | 44 ++++++++++++ .../ao_integrals/k_density_fitted.cpp | 44 ++++++++++++ 10 files changed, 450 insertions(+), 6 deletions(-) create mode 100644 src/integrals/ao_integrals/coulomb_metric.cpp create mode 100644 src/integrals/ao_integrals/df_integral.cpp create mode 100644 src/integrals/ao_integrals/j_density_fitted.cpp create mode 100644 src/integrals/ao_integrals/k_density_fitted.cpp create mode 100644 tests/cxx/unit/integrals/ao_integrals/coulomb_metric.cpp create mode 100644 tests/cxx/unit/integrals/ao_integrals/df_integral.cpp create mode 100644 tests/cxx/unit/integrals/ao_integrals/j_density_fitted.cpp create mode 100644 tests/cxx/unit/integrals/ao_integrals/k_density_fitted.cpp diff --git a/src/integrals/ao_integrals/ao_integrals.hpp b/src/integrals/ao_integrals/ao_integrals.hpp index f7b1a8a5..029cda17 100644 --- a/src/integrals/ao_integrals/ao_integrals.hpp +++ b/src/integrals/ao_integrals/ao_integrals.hpp @@ -22,17 +22,32 @@ namespace integrals::ao_integrals { DECLARE_MODULE(AOIntegralsDriver); DECLARE_MODULE(JFourCenter); DECLARE_MODULE(KFourCenter); +DECLARE_MODULE(JDensityFitted); +DECLARE_MODULE(KDensityFitted); +DECLARE_MODULE(DFIntegral); +DECLARE_MODULE(CoulombMetric); inline void set_defaults(pluginplay::ModuleManager& mm) { - const auto ao_driver = "AO integral driver"; - mm.change_submod(ao_driver, "Coulomb matrix", "Four center J builder"); - mm.change_submod(ao_driver, "Exchange matrix", "Four center K builder"); + mm.change_submod("AO integral driver", "Coulomb matrix", + "Four center J builder"); + mm.change_submod("AO integral driver", "Exchange matrix", + "Four center K builder"); + mm.change_submod("Density Fitted J builder", "DF ERI", + "Density Fitting Integral"); + mm.change_submod("Density Fitted K builder", "DF ERI", + "Density Fitting Integral"); + mm.change_submod("Density Fitting Integral", "Coulomb Metric", + "Coulomb Metric"); } inline void load_modules(pluginplay::ModuleManager& mm) { mm.add_module("AO integral driver"); mm.add_module("Four center J builder"); mm.add_module("Four center K builder"); + mm.add_module("Density Fitted J builder"); + mm.add_module("Density Fitted K builder"); + mm.add_module("Density Fitting Integral"); + mm.add_module("Coulomb Metric"); set_defaults(mm); } diff --git a/src/integrals/ao_integrals/coulomb_metric.cpp b/src/integrals/ao_integrals/coulomb_metric.cpp new file mode 100644 index 00000000..404d03bb --- /dev/null +++ b/src/integrals/ao_integrals/coulomb_metric.cpp @@ -0,0 +1,51 @@ +/* + * Copyright 2025 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ao_integrals.hpp" + +namespace integrals::ao_integrals { + +using pt = simde::ERI2; + +namespace { + +auto desc = R"( +Inverse Coulomb Metric +--------------------- +)"; + +} + +MODULE_CTOR(CoulombMetric) { + description(desc); + satisfies_property_type(); + add_submodule("Two-center ERI"); +} + +MODULE_RUN(CoulombMetric) { + const auto& [braket] = pt::unwrap_inputs(inputs); + auto& eri2_mod = submods.at("Two-center ERI"); + + const auto& M = eri2_mod.run_as(braket); + + // Cholesky Decomp + + + auto rv = results(); + return pt::wrap_results(rv, M); +} + +} // namespace integrals::ao_integrals \ No newline at end of file diff --git a/src/integrals/ao_integrals/df_integral.cpp b/src/integrals/ao_integrals/df_integral.cpp new file mode 100644 index 00000000..70fcb83a --- /dev/null +++ b/src/integrals/ao_integrals/df_integral.cpp @@ -0,0 +1,60 @@ +/* + * Copyright 2025 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ao_integrals.hpp" + +namespace integrals::ao_integrals { + +using pt = simde::ERI3; +using pt_2c = simde::ERI2; + +namespace { + +auto desc = R"( +Three-index ERI with Coulomb metric transformation +--------------------- +)"; + +} + +MODULE_CTOR(DFIntegral) { + description(desc); + satisfies_property_type(); + add_submodule("Three-center ERI"); + add_submodule("Coulomb Metric"); +} + +MODULE_RUN(DFIntegral) { + const auto& [braket] = pt::unwrap_inputs(inputs); + auto bra = braket.bra(); + auto ket = braket.ket(); + auto& op = braket.op(); + auto& eri2_mod = submods.at("Coulomb Metric"); + auto& eri3_mod = submods.at("Three-center ERI"); + + chemist::braket::BraKet aux_v_aux(bra, op, bra); + const auto& M = eri2_mod.run_as(aux_v_aux); + const auto& I = eri3_mod.run_as(braket); + + // Failing at the moment + simde::type::tensor L; + // L.multiplication_assignment("i,k,l", M("i,j"), I("j,k,l")); + + auto rv = results(); + return pt::wrap_results(rv, std::move(L)); +} + +} // namespace integrals::ao_integrals \ No newline at end of file diff --git a/src/integrals/ao_integrals/j_density_fitted.cpp b/src/integrals/ao_integrals/j_density_fitted.cpp new file mode 100644 index 00000000..234e4b3f --- /dev/null +++ b/src/integrals/ao_integrals/j_density_fitted.cpp @@ -0,0 +1,69 @@ +/* + * Copyright 2024 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ao_integrals.hpp" + +namespace integrals::ao_integrals { + +using pt = simde::aos_j_e_aos; +using pt_3c = simde::ERI3; +using aos_t = simde::type::aos; + +namespace { + +auto desc = R"( +Density Fitted J Builder +--------------------- +)"; + +} +MODULE_CTOR(JDensityFitted) { + description(desc); + satisfies_property_type(); + add_submodule("DF ERI"); + add_input("Auxiliary Basis Set"); +} + +MODULE_RUN(JDensityFitted) { + const auto&& [braket] = pt::unwrap_inputs(inputs); + + auto bra = braket.bra(); + auto ket = braket.ket(); + const auto& j_hat = braket.op(); + const auto& rho = j_hat.rhs_particle(); + const auto& p = rho.value(); + auto rho_aos = rho.basis_set(); + auto aux = inputs.at("Auxiliary Basis Set").value(); + auto& eri_mod = submods.at("DF ERI"); + + simde::type::v_ee_type v_ee; + simde::type::aos_squared ij_pair(bra, ket); + simde::type::aos_squared kl_pair(rho_aos, rho_aos); + chemist::braket::BraKet aux_v_ij(aux, v_ee, ij_pair); + chemist::braket::BraKet aux_v_kl(aux, v_ee, kl_pair); + const auto& I_akl = eri_mod.run_as(std::move(aux_v_kl)); + const auto& I_aij = eri_mod.run_as(std::move(aux_v_ij)); + + simde::type::tensor temp, j; + // Failing at the moment + // temp.multiplication_assignment("a", p("k,l"), I_akl("a,k,l")); + // j.multiplication_assignment("i,j", temp("a"), I_aij("a,i,j")); + + auto rv = results(); + return pt::wrap_results(rv, std::move(j)); +} + +} // namespace integrals::ao_integrals \ No newline at end of file diff --git a/src/integrals/ao_integrals/k_density_fitted.cpp b/src/integrals/ao_integrals/k_density_fitted.cpp new file mode 100644 index 00000000..cde1e4c3 --- /dev/null +++ b/src/integrals/ao_integrals/k_density_fitted.cpp @@ -0,0 +1,70 @@ +/* + * Copyright 2024 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ao_integrals.hpp" + +namespace integrals::ao_integrals { + +using pt = simde::aos_k_e_aos; +using pt_3c = simde::ERI3; +using aos_t = simde::type::aos; + +namespace { + +auto desc = R"( +Density Fitted K Builder +--------------------- +)"; + +} + +MODULE_CTOR(KDensityFitted) { + description(desc); + satisfies_property_type(); + add_submodule("DF ERI"); + add_input("Auxiliary Basis Set"); +} + +MODULE_RUN(KDensityFitted) { + const auto&& [braket] = pt::unwrap_inputs(inputs); + + auto bra = braket.bra(); + auto ket = braket.ket(); + const auto& j_hat = braket.op(); + const auto& rho = j_hat.rhs_particle(); + const auto& p = rho.value(); + auto rho_aos = rho.basis_set(); + auto aux = inputs.at("Auxiliary Basis Set").value(); + auto& eri_mod = submods.at("DF ERI"); + + simde::type::v_ee_type v_ee; + simde::type::aos_squared ik_pair(bra, rho_aos); + simde::type::aos_squared jl_pair(ket, rho_aos); + chemist::braket::BraKet aux_v_ik(aux, v_ee, ik_pair); + chemist::braket::BraKet aux_v_jl(aux, v_ee, jl_pair); + const auto& I_aik = eri_mod.run_as(std::move(aux_v_ik)); + const auto& I_ajl = eri_mod.run_as(std::move(aux_v_jl)); + + simde::type::tensor temp, k; + // Failing at the moment + // temp.multiplication_assignment("a,i,l", p("k,l"), I_aik("a,i,k")); + // k.multiplication_assignment("i,j", temp("a,i,l"), I_ajl("a,j,l")); + + auto rv = results(); + return pt::wrap_results(rv, std::move(k)); +} + +} // namespace integrals::ao_integrals \ No newline at end of file diff --git a/src/integrals/integrals_mm.cpp b/src/integrals/integrals_mm.cpp index 4b3a1ab6..cd1471b2 100644 --- a/src/integrals/integrals_mm.cpp +++ b/src/integrals/integrals_mm.cpp @@ -27,11 +27,13 @@ namespace integrals { * @throw none No throw guarantee */ void set_defaults(pluginplay::ModuleManager& mm) { - const auto ao_driver = "AO integral driver"; - mm.change_submod(ao_driver, "Kinetic", "Kinetic"); - mm.change_submod(ao_driver, "Electron-Nuclear attraction", "Nuclear"); + mm.change_submod("AO integral driver", "Kinetic", "Kinetic"); + mm.change_submod("AO integral driver", "Electron-Nuclear attraction", + "Nuclear"); mm.change_submod("Four center J builder", "Four-center ERI", "ERI4"); mm.change_submod("Four center K builder", "Four-center ERI", "ERI4"); + mm.change_submod("Density Fitting Integral", "Three-center ERI", "ERI3"); + mm.change_submod("Coulomb Metric", "Two-center ERI", "ERI2"); } void load_modules(pluginplay::ModuleManager& mm) { diff --git a/tests/cxx/unit/integrals/ao_integrals/coulomb_metric.cpp b/tests/cxx/unit/integrals/ao_integrals/coulomb_metric.cpp new file mode 100644 index 00000000..fa8da5ca --- /dev/null +++ b/tests/cxx/unit/integrals/ao_integrals/coulomb_metric.cpp @@ -0,0 +1,44 @@ +/* + * Copyright 2022 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "../testing.hpp" + +TEST_CASE("Coulomb Metric") { + using test_pt = simde::ERI2; + + pluginplay::ModuleManager mm; + integrals::load_modules(mm); + REQUIRE(mm.count("Coulomb Metric")); + + // Get basis set + auto mol = test::h2_molecule(); + auto aobs = test::h2_sto3g_basis_set(); + + // Make AOS object + simde::type::aos aos(aobs); + + // Make Operator + simde::type::v_ee_type op{}; + + // Make BraKet Input + chemist::braket::BraKet braket(aos, op, aos); + + // Call module + auto T = mm.at("Coulomb Metric").run_as(braket); + + // Check output + auto t = test::eigen_buffer<2>(T.buffer()); +} diff --git a/tests/cxx/unit/integrals/ao_integrals/df_integral.cpp b/tests/cxx/unit/integrals/ao_integrals/df_integral.cpp new file mode 100644 index 00000000..c3e3698c --- /dev/null +++ b/tests/cxx/unit/integrals/ao_integrals/df_integral.cpp @@ -0,0 +1,45 @@ +/* + * Copyright 2025 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "../testing.hpp" + +TEST_CASE("Density Fitting Integral") { + using test_pt = simde::ERI3; + + pluginplay::ModuleManager mm; + integrals::load_modules(mm); + REQUIRE(mm.count("Density Fitting Integral")); + + // Get basis set + auto mol = test::h2_molecule(); + auto aobs = test::h2_sto3g_basis_set(); + + // Make AOS object + simde::type::aos aos(aobs); + simde::type::aos_squared aos_squared(aos, aos); + + // Make Operator + simde::type::v_ee_type op{}; + + // Make BraKet Input + chemist::braket::BraKet braket(aos, op, aos_squared); + + // Call module + auto T = mm.at("Density Fitting Integral").run_as(braket); + + // Check output + // auto t = test::eigen_buffer<3>(T.buffer()); +} \ No newline at end of file diff --git a/tests/cxx/unit/integrals/ao_integrals/j_density_fitted.cpp b/tests/cxx/unit/integrals/ao_integrals/j_density_fitted.cpp new file mode 100644 index 00000000..5f015548 --- /dev/null +++ b/tests/cxx/unit/integrals/ao_integrals/j_density_fitted.cpp @@ -0,0 +1,44 @@ +/* + * Copyright 2024 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "../testing.hpp" + +TEST_CASE("Density Fitted J builder") { + using pt = simde::aos_j_e_aos; + + pluginplay::ModuleManager mm; + integrals::load_modules(mm); + REQUIRE(mm.count("Density Fitted J builder")); + + // Get basis set + auto mol = test::h2_molecule(); + auto aobs = test::h2_sto3g_basis_set(); + + // Make AOS object + simde::type::aos aos(aobs); + + // Make Operator + simde::type::j_e_type op(simde::type::electron{}, test::h2_density()); + + // Make BraKet Input + chemist::braket::BraKet braket(aos, op, aos); + + // Call module + mm.change_input("Density Fitted J builder", "Auxiliary Basis Set", aos); + const auto& T = mm.at("Density Fitted J builder").run_as(braket); + + // auto t = test::eigen_buffer<2>(T.buffer()); +} \ No newline at end of file diff --git a/tests/cxx/unit/integrals/ao_integrals/k_density_fitted.cpp b/tests/cxx/unit/integrals/ao_integrals/k_density_fitted.cpp new file mode 100644 index 00000000..febdd0df --- /dev/null +++ b/tests/cxx/unit/integrals/ao_integrals/k_density_fitted.cpp @@ -0,0 +1,44 @@ +/* + * Copyright 2024 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "../testing.hpp" + +TEST_CASE("Density Fitted K builder") { + using pt = simde::aos_k_e_aos; + + pluginplay::ModuleManager mm; + integrals::load_modules(mm); + REQUIRE(mm.count("Density Fitted K builder")); + + // Get basis set + auto mol = test::h2_molecule(); + auto aobs = test::h2_sto3g_basis_set(); + + // Make AOS object + simde::type::aos aos(aobs); + + // Make Operator + simde::type::k_e_type op(simde::type::electron{}, test::h2_density()); + + // Make BraKet Input + chemist::braket::BraKet braket(aos, op, aos); + + // Call module + mm.change_input("Density Fitted K builder", "Auxiliary Basis Set", aos); + const auto& T = mm.at("Density Fitted K builder").run_as(braket); + + // auto t = test::eigen_buffer<2>(T.buffer()); +} \ No newline at end of file From 1f7e9e6b842ce593e381e053abe14c4c887969f7 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Waldrop" Date: Fri, 14 Feb 2025 12:10:44 -0600 Subject: [PATCH 7/8] Revert "Density fitting modules outlined, nothing works [skip ci]" This reverts commit 71a21208f23b1cebae30322f6d58802e7054a0e3. --- src/integrals/ao_integrals/ao_integrals.hpp | 21 +----- src/integrals/ao_integrals/coulomb_metric.cpp | 51 -------------- src/integrals/ao_integrals/df_integral.cpp | 60 ---------------- .../ao_integrals/j_density_fitted.cpp | 69 ------------------ .../ao_integrals/k_density_fitted.cpp | 70 ------------------- src/integrals/integrals_mm.cpp | 8 +-- .../integrals/ao_integrals/coulomb_metric.cpp | 44 ------------ .../integrals/ao_integrals/df_integral.cpp | 45 ------------ .../ao_integrals/j_density_fitted.cpp | 44 ------------ .../ao_integrals/k_density_fitted.cpp | 44 ------------ 10 files changed, 6 insertions(+), 450 deletions(-) delete mode 100644 src/integrals/ao_integrals/coulomb_metric.cpp delete mode 100644 src/integrals/ao_integrals/df_integral.cpp delete mode 100644 src/integrals/ao_integrals/j_density_fitted.cpp delete mode 100644 src/integrals/ao_integrals/k_density_fitted.cpp delete mode 100644 tests/cxx/unit/integrals/ao_integrals/coulomb_metric.cpp delete mode 100644 tests/cxx/unit/integrals/ao_integrals/df_integral.cpp delete mode 100644 tests/cxx/unit/integrals/ao_integrals/j_density_fitted.cpp delete mode 100644 tests/cxx/unit/integrals/ao_integrals/k_density_fitted.cpp diff --git a/src/integrals/ao_integrals/ao_integrals.hpp b/src/integrals/ao_integrals/ao_integrals.hpp index 029cda17..f7b1a8a5 100644 --- a/src/integrals/ao_integrals/ao_integrals.hpp +++ b/src/integrals/ao_integrals/ao_integrals.hpp @@ -22,32 +22,17 @@ namespace integrals::ao_integrals { DECLARE_MODULE(AOIntegralsDriver); DECLARE_MODULE(JFourCenter); DECLARE_MODULE(KFourCenter); -DECLARE_MODULE(JDensityFitted); -DECLARE_MODULE(KDensityFitted); -DECLARE_MODULE(DFIntegral); -DECLARE_MODULE(CoulombMetric); inline void set_defaults(pluginplay::ModuleManager& mm) { - mm.change_submod("AO integral driver", "Coulomb matrix", - "Four center J builder"); - mm.change_submod("AO integral driver", "Exchange matrix", - "Four center K builder"); - mm.change_submod("Density Fitted J builder", "DF ERI", - "Density Fitting Integral"); - mm.change_submod("Density Fitted K builder", "DF ERI", - "Density Fitting Integral"); - mm.change_submod("Density Fitting Integral", "Coulomb Metric", - "Coulomb Metric"); + const auto ao_driver = "AO integral driver"; + mm.change_submod(ao_driver, "Coulomb matrix", "Four center J builder"); + mm.change_submod(ao_driver, "Exchange matrix", "Four center K builder"); } inline void load_modules(pluginplay::ModuleManager& mm) { mm.add_module("AO integral driver"); mm.add_module("Four center J builder"); mm.add_module("Four center K builder"); - mm.add_module("Density Fitted J builder"); - mm.add_module("Density Fitted K builder"); - mm.add_module("Density Fitting Integral"); - mm.add_module("Coulomb Metric"); set_defaults(mm); } diff --git a/src/integrals/ao_integrals/coulomb_metric.cpp b/src/integrals/ao_integrals/coulomb_metric.cpp deleted file mode 100644 index 404d03bb..00000000 --- a/src/integrals/ao_integrals/coulomb_metric.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2025 NWChemEx-Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ao_integrals.hpp" - -namespace integrals::ao_integrals { - -using pt = simde::ERI2; - -namespace { - -auto desc = R"( -Inverse Coulomb Metric ---------------------- -)"; - -} - -MODULE_CTOR(CoulombMetric) { - description(desc); - satisfies_property_type(); - add_submodule("Two-center ERI"); -} - -MODULE_RUN(CoulombMetric) { - const auto& [braket] = pt::unwrap_inputs(inputs); - auto& eri2_mod = submods.at("Two-center ERI"); - - const auto& M = eri2_mod.run_as(braket); - - // Cholesky Decomp - - - auto rv = results(); - return pt::wrap_results(rv, M); -} - -} // namespace integrals::ao_integrals \ No newline at end of file diff --git a/src/integrals/ao_integrals/df_integral.cpp b/src/integrals/ao_integrals/df_integral.cpp deleted file mode 100644 index 70fcb83a..00000000 --- a/src/integrals/ao_integrals/df_integral.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2025 NWChemEx-Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ao_integrals.hpp" - -namespace integrals::ao_integrals { - -using pt = simde::ERI3; -using pt_2c = simde::ERI2; - -namespace { - -auto desc = R"( -Three-index ERI with Coulomb metric transformation ---------------------- -)"; - -} - -MODULE_CTOR(DFIntegral) { - description(desc); - satisfies_property_type(); - add_submodule("Three-center ERI"); - add_submodule("Coulomb Metric"); -} - -MODULE_RUN(DFIntegral) { - const auto& [braket] = pt::unwrap_inputs(inputs); - auto bra = braket.bra(); - auto ket = braket.ket(); - auto& op = braket.op(); - auto& eri2_mod = submods.at("Coulomb Metric"); - auto& eri3_mod = submods.at("Three-center ERI"); - - chemist::braket::BraKet aux_v_aux(bra, op, bra); - const auto& M = eri2_mod.run_as(aux_v_aux); - const auto& I = eri3_mod.run_as(braket); - - // Failing at the moment - simde::type::tensor L; - // L.multiplication_assignment("i,k,l", M("i,j"), I("j,k,l")); - - auto rv = results(); - return pt::wrap_results(rv, std::move(L)); -} - -} // namespace integrals::ao_integrals \ No newline at end of file diff --git a/src/integrals/ao_integrals/j_density_fitted.cpp b/src/integrals/ao_integrals/j_density_fitted.cpp deleted file mode 100644 index 234e4b3f..00000000 --- a/src/integrals/ao_integrals/j_density_fitted.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2024 NWChemEx-Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ao_integrals.hpp" - -namespace integrals::ao_integrals { - -using pt = simde::aos_j_e_aos; -using pt_3c = simde::ERI3; -using aos_t = simde::type::aos; - -namespace { - -auto desc = R"( -Density Fitted J Builder ---------------------- -)"; - -} -MODULE_CTOR(JDensityFitted) { - description(desc); - satisfies_property_type(); - add_submodule("DF ERI"); - add_input("Auxiliary Basis Set"); -} - -MODULE_RUN(JDensityFitted) { - const auto&& [braket] = pt::unwrap_inputs(inputs); - - auto bra = braket.bra(); - auto ket = braket.ket(); - const auto& j_hat = braket.op(); - const auto& rho = j_hat.rhs_particle(); - const auto& p = rho.value(); - auto rho_aos = rho.basis_set(); - auto aux = inputs.at("Auxiliary Basis Set").value(); - auto& eri_mod = submods.at("DF ERI"); - - simde::type::v_ee_type v_ee; - simde::type::aos_squared ij_pair(bra, ket); - simde::type::aos_squared kl_pair(rho_aos, rho_aos); - chemist::braket::BraKet aux_v_ij(aux, v_ee, ij_pair); - chemist::braket::BraKet aux_v_kl(aux, v_ee, kl_pair); - const auto& I_akl = eri_mod.run_as(std::move(aux_v_kl)); - const auto& I_aij = eri_mod.run_as(std::move(aux_v_ij)); - - simde::type::tensor temp, j; - // Failing at the moment - // temp.multiplication_assignment("a", p("k,l"), I_akl("a,k,l")); - // j.multiplication_assignment("i,j", temp("a"), I_aij("a,i,j")); - - auto rv = results(); - return pt::wrap_results(rv, std::move(j)); -} - -} // namespace integrals::ao_integrals \ No newline at end of file diff --git a/src/integrals/ao_integrals/k_density_fitted.cpp b/src/integrals/ao_integrals/k_density_fitted.cpp deleted file mode 100644 index cde1e4c3..00000000 --- a/src/integrals/ao_integrals/k_density_fitted.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2024 NWChemEx-Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ao_integrals.hpp" - -namespace integrals::ao_integrals { - -using pt = simde::aos_k_e_aos; -using pt_3c = simde::ERI3; -using aos_t = simde::type::aos; - -namespace { - -auto desc = R"( -Density Fitted K Builder ---------------------- -)"; - -} - -MODULE_CTOR(KDensityFitted) { - description(desc); - satisfies_property_type(); - add_submodule("DF ERI"); - add_input("Auxiliary Basis Set"); -} - -MODULE_RUN(KDensityFitted) { - const auto&& [braket] = pt::unwrap_inputs(inputs); - - auto bra = braket.bra(); - auto ket = braket.ket(); - const auto& j_hat = braket.op(); - const auto& rho = j_hat.rhs_particle(); - const auto& p = rho.value(); - auto rho_aos = rho.basis_set(); - auto aux = inputs.at("Auxiliary Basis Set").value(); - auto& eri_mod = submods.at("DF ERI"); - - simde::type::v_ee_type v_ee; - simde::type::aos_squared ik_pair(bra, rho_aos); - simde::type::aos_squared jl_pair(ket, rho_aos); - chemist::braket::BraKet aux_v_ik(aux, v_ee, ik_pair); - chemist::braket::BraKet aux_v_jl(aux, v_ee, jl_pair); - const auto& I_aik = eri_mod.run_as(std::move(aux_v_ik)); - const auto& I_ajl = eri_mod.run_as(std::move(aux_v_jl)); - - simde::type::tensor temp, k; - // Failing at the moment - // temp.multiplication_assignment("a,i,l", p("k,l"), I_aik("a,i,k")); - // k.multiplication_assignment("i,j", temp("a,i,l"), I_ajl("a,j,l")); - - auto rv = results(); - return pt::wrap_results(rv, std::move(k)); -} - -} // namespace integrals::ao_integrals \ No newline at end of file diff --git a/src/integrals/integrals_mm.cpp b/src/integrals/integrals_mm.cpp index cd1471b2..4b3a1ab6 100644 --- a/src/integrals/integrals_mm.cpp +++ b/src/integrals/integrals_mm.cpp @@ -27,13 +27,11 @@ namespace integrals { * @throw none No throw guarantee */ void set_defaults(pluginplay::ModuleManager& mm) { - mm.change_submod("AO integral driver", "Kinetic", "Kinetic"); - mm.change_submod("AO integral driver", "Electron-Nuclear attraction", - "Nuclear"); + const auto ao_driver = "AO integral driver"; + mm.change_submod(ao_driver, "Kinetic", "Kinetic"); + mm.change_submod(ao_driver, "Electron-Nuclear attraction", "Nuclear"); mm.change_submod("Four center J builder", "Four-center ERI", "ERI4"); mm.change_submod("Four center K builder", "Four-center ERI", "ERI4"); - mm.change_submod("Density Fitting Integral", "Three-center ERI", "ERI3"); - mm.change_submod("Coulomb Metric", "Two-center ERI", "ERI2"); } void load_modules(pluginplay::ModuleManager& mm) { diff --git a/tests/cxx/unit/integrals/ao_integrals/coulomb_metric.cpp b/tests/cxx/unit/integrals/ao_integrals/coulomb_metric.cpp deleted file mode 100644 index fa8da5ca..00000000 --- a/tests/cxx/unit/integrals/ao_integrals/coulomb_metric.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2022 NWChemEx-Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../testing.hpp" - -TEST_CASE("Coulomb Metric") { - using test_pt = simde::ERI2; - - pluginplay::ModuleManager mm; - integrals::load_modules(mm); - REQUIRE(mm.count("Coulomb Metric")); - - // Get basis set - auto mol = test::h2_molecule(); - auto aobs = test::h2_sto3g_basis_set(); - - // Make AOS object - simde::type::aos aos(aobs); - - // Make Operator - simde::type::v_ee_type op{}; - - // Make BraKet Input - chemist::braket::BraKet braket(aos, op, aos); - - // Call module - auto T = mm.at("Coulomb Metric").run_as(braket); - - // Check output - auto t = test::eigen_buffer<2>(T.buffer()); -} diff --git a/tests/cxx/unit/integrals/ao_integrals/df_integral.cpp b/tests/cxx/unit/integrals/ao_integrals/df_integral.cpp deleted file mode 100644 index c3e3698c..00000000 --- a/tests/cxx/unit/integrals/ao_integrals/df_integral.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2025 NWChemEx-Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../testing.hpp" - -TEST_CASE("Density Fitting Integral") { - using test_pt = simde::ERI3; - - pluginplay::ModuleManager mm; - integrals::load_modules(mm); - REQUIRE(mm.count("Density Fitting Integral")); - - // Get basis set - auto mol = test::h2_molecule(); - auto aobs = test::h2_sto3g_basis_set(); - - // Make AOS object - simde::type::aos aos(aobs); - simde::type::aos_squared aos_squared(aos, aos); - - // Make Operator - simde::type::v_ee_type op{}; - - // Make BraKet Input - chemist::braket::BraKet braket(aos, op, aos_squared); - - // Call module - auto T = mm.at("Density Fitting Integral").run_as(braket); - - // Check output - // auto t = test::eigen_buffer<3>(T.buffer()); -} \ No newline at end of file diff --git a/tests/cxx/unit/integrals/ao_integrals/j_density_fitted.cpp b/tests/cxx/unit/integrals/ao_integrals/j_density_fitted.cpp deleted file mode 100644 index 5f015548..00000000 --- a/tests/cxx/unit/integrals/ao_integrals/j_density_fitted.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2024 NWChemEx-Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../testing.hpp" - -TEST_CASE("Density Fitted J builder") { - using pt = simde::aos_j_e_aos; - - pluginplay::ModuleManager mm; - integrals::load_modules(mm); - REQUIRE(mm.count("Density Fitted J builder")); - - // Get basis set - auto mol = test::h2_molecule(); - auto aobs = test::h2_sto3g_basis_set(); - - // Make AOS object - simde::type::aos aos(aobs); - - // Make Operator - simde::type::j_e_type op(simde::type::electron{}, test::h2_density()); - - // Make BraKet Input - chemist::braket::BraKet braket(aos, op, aos); - - // Call module - mm.change_input("Density Fitted J builder", "Auxiliary Basis Set", aos); - const auto& T = mm.at("Density Fitted J builder").run_as(braket); - - // auto t = test::eigen_buffer<2>(T.buffer()); -} \ No newline at end of file diff --git a/tests/cxx/unit/integrals/ao_integrals/k_density_fitted.cpp b/tests/cxx/unit/integrals/ao_integrals/k_density_fitted.cpp deleted file mode 100644 index febdd0df..00000000 --- a/tests/cxx/unit/integrals/ao_integrals/k_density_fitted.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2024 NWChemEx-Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "../testing.hpp" - -TEST_CASE("Density Fitted K builder") { - using pt = simde::aos_k_e_aos; - - pluginplay::ModuleManager mm; - integrals::load_modules(mm); - REQUIRE(mm.count("Density Fitted K builder")); - - // Get basis set - auto mol = test::h2_molecule(); - auto aobs = test::h2_sto3g_basis_set(); - - // Make AOS object - simde::type::aos aos(aobs); - - // Make Operator - simde::type::k_e_type op(simde::type::electron{}, test::h2_density()); - - // Make BraKet Input - chemist::braket::BraKet braket(aos, op, aos); - - // Call module - mm.change_input("Density Fitted K builder", "Auxiliary Basis Set", aos); - const auto& T = mm.at("Density Fitted K builder").run_as(braket); - - // auto t = test::eigen_buffer<2>(T.buffer()); -} \ No newline at end of file From 2ddd44f7d696fc83876bea5ec4e57337e5a7324a Mon Sep 17 00:00:00 2001 From: "Jonathan M. Waldrop" Date: Fri, 14 Feb 2025 12:44:27 -0600 Subject: [PATCH 8/8] Ryan's suggested changes --- src/integrals/ao_integrals/j_four_center.cpp | 2 +- src/integrals/ao_integrals/k_four_center.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/integrals/ao_integrals/j_four_center.cpp b/src/integrals/ao_integrals/j_four_center.cpp index 7d09eefd..f262f44a 100644 --- a/src/integrals/ao_integrals/j_four_center.cpp +++ b/src/integrals/ao_integrals/j_four_center.cpp @@ -52,7 +52,7 @@ MODULE_RUN(JFourCenter) { const auto& I = eri_mod.run_as(std::move(ij_v_kl)); simde::type::tensor j; - j.multiplication_assignment("i,j", p("k,l"), I("i,j,k,l")); + j("i,j") = p("k,l") * I("i,j,k,l"); auto rv = results(); return pt::wrap_results(rv, std::move(j)); diff --git a/src/integrals/ao_integrals/k_four_center.cpp b/src/integrals/ao_integrals/k_four_center.cpp index 651c18fc..96fcea05 100644 --- a/src/integrals/ao_integrals/k_four_center.cpp +++ b/src/integrals/ao_integrals/k_four_center.cpp @@ -53,7 +53,7 @@ MODULE_RUN(KFourCenter) { const auto& I = eri_mod.run_as(std::move(ik_v_lj)); simde::type::tensor k; - k.multiplication_assignment("i,j", p("k,l"), I("i,k,l,j")); + k("i,j") = p("k,l") * I("i,k,l,j"); auto rv = results(); return pt::wrap_results(rv, std::move(k));