diff --git a/src/scf/matrix_builder/j_four_center.cpp b/src/scf/matrix_builder/j_four_center.cpp deleted file mode 100644 index 909e246..0000000 --- a/src/scf/matrix_builder/j_four_center.cpp +++ /dev/null @@ -1,83 +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 "matrix_builder.hpp" - -namespace scf::matrix_builder { - -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 scf::matrix_builder \ No newline at end of file diff --git a/src/scf/matrix_builder/k_four_center.cpp b/src/scf/matrix_builder/k_four_center.cpp deleted file mode 100644 index 19f9b9f..0000000 --- a/src/scf/matrix_builder/k_four_center.cpp +++ /dev/null @@ -1,84 +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 "matrix_builder.hpp" - -namespace scf::matrix_builder { - -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 scf::matrix_builder \ No newline at end of file diff --git a/src/scf/matrix_builder/matrix_builder.hpp b/src/scf/matrix_builder/matrix_builder.hpp index e4467df..b8da0aa 100644 --- a/src/scf/matrix_builder/matrix_builder.hpp +++ b/src/scf/matrix_builder/matrix_builder.hpp @@ -19,34 +19,25 @@ namespace scf::matrix_builder { -DECLARE_MODULE(AOIntegralsDriver); +DECLARE_MODULE(SCFIntegralsDriver); DECLARE_MODULE(DensityMatrix); DECLARE_MODULE(DeterminantDriver); DECLARE_MODULE(ElectronicEnergy); DECLARE_MODULE(Fock); -DECLARE_MODULE(JFourCenter); -DECLARE_MODULE(KFourCenter); inline void load_modules(pluginplay::ModuleManager& mm) { - mm.add_module("AO integral driver"); + mm.add_module("SCF integral driver"); mm.add_module("Density matrix builder"); mm.add_module("Determinant driver"); mm.add_module("Electronic energy"); mm.add_module("Fock matrix builder"); - mm.add_module("Four center J builder"); - mm.add_module("Four center K builder"); } 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"); - // TODO: Re-enable when PluginPlay doesn't choke on loops in modules - // mm.change_submod(ao_driver, "Fock matrix", "Fock Matrix Builder"); + const auto ao_driver = "SCF integral driver"; + mm.change_submod(ao_driver, "Fock matrix", "Fock Matrix Builder"); mm.change_submod(ao_driver, "Density matrix", "Density matrix builder"); - mm.change_submod("Fock matrix builder", "Two center evaluator", ao_driver); - const auto det_driver = "Determinant driver"; mm.change_submod(det_driver, "Two center evaluator", ao_driver); mm.change_submod(det_driver, "Fock matrix", "Fock matrix builder"); diff --git a/src/scf/matrix_builder/ao_integrals_driver.cpp b/src/scf/matrix_builder/scf_integrals_driver.cpp similarity index 60% rename from src/scf/matrix_builder/ao_integrals_driver.cpp rename to src/scf/matrix_builder/scf_integrals_driver.cpp index bc7b296..1314f34 100644 --- a/src/scf/matrix_builder/ao_integrals_driver.cpp +++ b/src/scf/matrix_builder/scf_integrals_driver.cpp @@ -32,19 +32,14 @@ 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 f_e_pt = simde::aos_f_e_aos; using rho_e_pt = simde::aos_rho_e_aos; class AODispatcher : public chemist::qm_operator::OperatorVisitor { +private: + using base_type = 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 f_e_type = simde::type::fock; using rho_e_type = simde::type::rho_e; @@ -52,62 +47,45 @@ class AODispatcher : public chemist::qm_operator::OperatorVisitor { 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); - } + base_type(false), + m_pbra_(&bra), + m_pket_(&ket), + m_psubmods_(&submods), + m_ptensor_(&t) {} // void run(const f_e_type& f_e) { // chemist::braket::BraKet input(*m_pbra_, f_e, *m_pket_); // const auto key = "Fock matrix"; // *m_ptensor_ = m_psubmods_->at(key).run_as(input); + // m_evaluated_ = true; // } void run(const rho_e_type& rho_e) { chemist::braket::BraKet input(*m_pbra_, rho_e, *m_pket_); const auto key = "Density matrix"; *m_ptensor_ = m_psubmods_->at(key).run_as(input); + m_evaluated_ = true; } + bool evaluated() const noexcept { return m_evaluated_; } + private: const aos* m_pbra_; const aos* m_pket_; + bool m_evaluated_ = false; submodule_map* m_psubmods_; tensor* m_ptensor_; }; -MODULE_CTOR(AOIntegralsDriver) { +MODULE_CTOR(SCFIntegralsDriver) { description(desc); satisfies_property_type(); - add_submodule("Kinetic"); - add_submodule("Electron-Nuclear attraction"); - add_submodule("Coulomb matrix"); - add_submodule("Exchange matrix"); - // add_submodule("Fock matrix"); + add_submodule("Fundamental matrices"); + add_submodule("Fock matrix"); add_submodule("Density matrix"); } -MODULE_RUN(AOIntegralsDriver) { +MODULE_RUN(SCFIntegralsDriver) { const auto&& [braket] = pt::unwrap_inputs(inputs); const auto& bra = braket.bra(); const auto& op = braket.op(); @@ -116,6 +94,9 @@ MODULE_RUN(AOIntegralsDriver) { tensor t; AODispatcher visitor(bra, ket, submods, t); op.visit(visitor); + if(!visitor.evaluated()) { + t = submods.at("Fundamental matrices").run_as(braket); + } auto rv = results(); return pt::wrap_results(rv, std::move(t)); diff --git a/tests/cxx/integration_tests/integration_tests.hpp b/tests/cxx/integration_tests/integration_tests.hpp index ead0faa..36ed094 100644 --- a/tests/cxx/integration_tests/integration_tests.hpp +++ b/tests/cxx/integration_tests/integration_tests.hpp @@ -25,7 +25,8 @@ namespace test_scf { /// Factors out setting submodules for SCF plugin from other plugins inline auto load_modules() { - pluginplay::ModuleManager mm; + auto rv = std::make_shared(); + pluginplay::ModuleManager mm(rv, nullptr); scf::load_modules(mm); integrals::load_modules(mm); nux::load_modules(mm); @@ -33,12 +34,12 @@ inline auto load_modules() { mm.change_submod("SCF Driver", "Hamiltonian", "Born-Oppenheimer approximation"); - mm.change_submod("Four center J builder", "Four-center ERI", "ERI4"); - mm.change_submod("Four center K builder", "Four-center ERI", "ERI4"); + const auto ao_driver_key = "SCF integral driver"; + mm.change_submod(ao_driver_key, "Fundamental matrices", + "AO integral driver"); - const auto ao_driver_key = "AO integral driver"; - mm.change_submod(ao_driver_key, "Kinetic", "Kinetic"); - mm.change_submod(ao_driver_key, "Electron-Nuclear attraction", "Nuclear"); + mm.change_submod("Fock Matrix Builder", "Two center evaluator", + "AO integral driver"); mm.change_submod("Diagonalization Fock update", "Overlap matrix builder", "Overlap"); diff --git a/tests/cxx/integration_tests/matrix_builder/j_four_center.cpp b/tests/cxx/integration_tests/matrix_builder/j_four_center.cpp deleted file mode 100644 index ea7edf3..0000000 --- a/tests/cxx/integration_tests/matrix_builder/j_four_center.cpp +++ /dev/null @@ -1,36 +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 "../integration_tests.hpp" - -using pt = simde::aos_j_e_aos; - -TEST_CASE("JFourCenter") { - auto mm = test_scf::load_modules(); - auto& mod = mm.at("Four center J builder"); - auto aos = test_scf::h2_aos(); - - simde::type::j_e_type j_e(simde::type::electron{}, test_scf::h2_density()); - const auto& J = mod.run_as(chemist::braket::BraKet(aos, j_e, aos)); - - using alloc_type = tensorwrapper::allocator::Eigen; - const auto& J_eigen = alloc_type::rebind(J.buffer()); - using Catch::Matchers::WithinAbs; - REQUIRE_THAT(J_eigen.value()(0, 0), WithinAbs(0.71438149, 1E-6)); - REQUIRE_THAT(J_eigen.value()(0, 1), WithinAbs(0.47471072, 1E-6)); - REQUIRE_THAT(J_eigen.value()(1, 0), WithinAbs(0.47471072, 1E-6)); - REQUIRE_THAT(J_eigen.value()(1, 1), WithinAbs(0.71438149, 1E-6)); -} \ No newline at end of file diff --git a/tests/cxx/integration_tests/matrix_builder/k_four_center.cpp b/tests/cxx/integration_tests/matrix_builder/k_four_center.cpp deleted file mode 100644 index 73f3580..0000000 --- a/tests/cxx/integration_tests/matrix_builder/k_four_center.cpp +++ /dev/null @@ -1,36 +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 "../integration_tests.hpp" - -using pt = simde::aos_k_e_aos; - -TEST_CASE("KFourCenter") { - auto mm = test_scf::load_modules(); - auto& mod = mm.at("Four center K builder"); - auto aos = test_scf::h2_aos(); - - simde::type::k_e_type k_e(simde::type::electron{}, test_scf::h2_density()); - const auto& K = mod.run_as(chemist::braket::BraKet(aos, k_e, aos)); - - using alloc_type = tensorwrapper::allocator::Eigen; - const auto& K_eigen = alloc_type::rebind(K.buffer()); - using Catch::Matchers::WithinAbs; - REQUIRE_THAT(K_eigen.value()(0, 0), WithinAbs(0.627264, 1E-6)); - REQUIRE_THAT(K_eigen.value()(0, 1), WithinAbs(0.561828, 1E-6)); - REQUIRE_THAT(K_eigen.value()(1, 0), WithinAbs(0.561828, 1E-6)); - REQUIRE_THAT(K_eigen.value()(1, 1), WithinAbs(0.627264, 1E-6)); -} \ No newline at end of file diff --git a/tests/cxx/integration_tests/matrix_builder/ao_integrals_driver.cpp b/tests/cxx/integration_tests/matrix_builder/scf_integrals_driver.cpp similarity index 95% rename from tests/cxx/integration_tests/matrix_builder/ao_integrals_driver.cpp rename to tests/cxx/integration_tests/matrix_builder/scf_integrals_driver.cpp index 7cd63ce..cce4578 100644 --- a/tests/cxx/integration_tests/matrix_builder/ao_integrals_driver.cpp +++ b/tests/cxx/integration_tests/matrix_builder/scf_integrals_driver.cpp @@ -43,10 +43,10 @@ using erased_type = chemist::braket::BraKet; -TEST_CASE("AOIntegralsDriver") { +TEST_CASE("SCFIntegralsDriver") { auto mm = test_scf::load_modules(); auto aos = test_scf::h2_aos(); - auto mod = mm.at("AO integral driver"); + auto mod = mm.at("SCF integral driver"); simde::type::electron e; auto rho = test_scf::h2_density(); @@ -93,7 +93,6 @@ TEST_CASE("AOIntegralsDriver") { SECTION("Calling density matrix") { auto& pmod = mm.at("Density matrix builder"); - auto aos = test_scf::h2_aos(); auto cmos = test_scf::h2_cmos(); std::vector occs{1, 0}; simde::type::rho_e rho_hat(cmos, occs); @@ -105,7 +104,6 @@ TEST_CASE("AOIntegralsDriver") { compare_matrices(P, P_corr); } - // Re-enable when PluginPlay doesn't choke on loops in modules // SECTION("Calling Fock Matrix") { // auto& fmod = mm.at("Fock matrix builder"); // auto f_e = test_scf::h2_fock();