From b96e12ed578be71fff33051ddf467d43db3cf0cf Mon Sep 17 00:00:00 2001 From: Jens Wehner Date: Tue, 20 Oct 2020 13:51:49 +0200 Subject: [PATCH 01/17] incremental fmatrix and option changes --- include/votca/xtp/dftengine.h | 2 +- share/xtp/data/qmpackage_defaults.xml | 57 +++++++++--------- share/xtp/xml/dftgwbse.xml | 2 +- share/xtp/xml/neighborlist.xml | 39 +++++++++++-- src/libxtp/dftengine/ERIs.cc | 1 + src/libxtp/dftengine/dftengine.cc | 84 ++++++++++++++++++++++----- src/libxtp/qmpackage.cc | 3 +- src/libxtp/qmpackages/xtpdft.cc | 2 +- src/tests/test_dftengine.cc | 2 +- 9 files changed, 138 insertions(+), 54 deletions(-) diff --git a/include/votca/xtp/dftengine.h b/include/votca/xtp/dftengine.h index 6f64279c79..e3fe2e2622 100644 --- a/include/votca/xtp/dftengine.h +++ b/include/votca/xtp/dftengine.h @@ -118,7 +118,7 @@ class DFTEngine { std::string _four_center_method; // direct | cache // Pre-screening - bool _with_screening; + Index _fock_matrix_reset; double _screening_eps; // numerical integration Vxc diff --git a/share/xtp/data/qmpackage_defaults.xml b/share/xtp/data/qmpackage_defaults.xml index cf0ea2940a..2ca2a6d1a3 100644 --- a/share/xtp/data/qmpackage_defaults.xml +++ b/share/xtp/data/qmpackage_defaults.xml @@ -1,44 +1,43 @@ - xtp - 0 - 1 - def2-tzvp - - aux-def2-tzvp + + + + + - false - XC_HYB_GGA_XC_PBEH - /tmp/qmpackage + + + false - 0.1 - false - false - tight - + + + + + - true 1e-9 - RI + + - 1e-7 - DIIS - 0.002 - 0.8 - 20 - false - 0.0 - 0.2 - 100 - 1e-7 - 0.7 + + + + + + + + + + + - atom - medium + + diff --git a/share/xtp/xml/dftgwbse.xml b/share/xtp/xml/dftgwbse.xml index 0176649df9..9cd77d59ac 100644 --- a/share/xtp/xml/dftgwbse.xml +++ b/share/xtp/xml/dftgwbse.xml @@ -18,7 +18,7 @@ - + diff --git a/share/xtp/xml/neighborlist.xml b/share/xtp/xml/neighborlist.xml index 006a0c61e8..2404306e3e 100644 --- a/share/xtp/xml/neighborlist.xml +++ b/share/xtp/xml/neighborlist.xml @@ -1,11 +1,38 @@ - - - - - - + + + + + + + + + + +3.5 + + + a B + + + + +3.5 + + + a C + + + + +5 + + + a D + + + diff --git a/src/libxtp/dftengine/ERIs.cc b/src/libxtp/dftengine/ERIs.cc index 5594777fce..51f40c415c 100644 --- a/src/libxtp/dftengine/ERIs.cc +++ b/src/libxtp/dftengine/ERIs.cc @@ -144,6 +144,7 @@ std::array ERIs::Compute4c(const Eigen::MatrixXd& dmat, std::vector engines(nthreads); engines[0] = libint2::Engine(libint2::Operator::coulomb, int(maxnprim_), int(maxL_), 0); + std::cout << fock_precision << std::endl; engines[0].set_precision(engine_precision); // shellset-dependent precision // control will likely break // positive definiteness diff --git a/src/libxtp/dftengine/dftengine.cc b/src/libxtp/dftengine/dftengine.cc index ba20200b10..fd5c23dafb 100644 --- a/src/libxtp/dftengine/dftengine.cc +++ b/src/libxtp/dftengine/dftengine.cc @@ -46,6 +46,7 @@ namespace xtp { void DFTEngine::Initialize(Property& options) { + std::cout << options << std::endl; string key = "package"; const string key_xtpdft = "package.xtpdft"; _dftbasis_name = options.get(key + ".basisset").as(); @@ -58,8 +59,9 @@ void DFTEngine::Initialize(Property& options) { options.get(key_xtpdft + ".four_center_method").as(); if (_four_center_method != "RI") { - _with_screening = options.get(key_xtpdft + ".with_screening").as(); _screening_eps = options.get(key_xtpdft + ".screening_eps").as(); + _fock_matrix_reset = + options.get(key_xtpdft + ".fock_matrix_reset").as(); } if (options.get(key + ".use_ecp").as()) { @@ -241,6 +243,23 @@ bool DFTEngine::Evaluate(Orbitals& orb) { "----------------------------" << flush; + Eigen::MatrixXd J = Eigen::MatrixXd::Zero(Dmat.rows(), Dmat.cols()); + Eigen::MatrixXd Ddiff = Dmat; + Eigen::MatrixXd Dlast = Dmat; + Eigen::MatrixXd K; + if (_ScaHFX > 0) { + K = Eigen::MatrixXd::Zero(Dmat.rows(), Dmat.cols()); + } + + bool reset_incremental_fock_formation = false; + bool incremental_Fbuild_started = false; + double start_incremental_F_threshold = 1e-5; + double next_reset_threshold = 0.0; + Index last_reset_iteration = 0; + if (_four_center_method == "RI") { + start_incremental_F_threshold = 0.0; + } + for (Index this_iter = 0; this_iter < _max_iter; this_iter++) { XTP_LOG(Log::error, *_pLog) << flush; XTP_LOG(Log::error, *_pLog) << TimeStamp() << " Iteration " << this_iter + 1 @@ -255,20 +274,48 @@ bool DFTEngine::Evaluate(Orbitals& orb) { double Etwo = e_vxc.energy(); double exx = 0.0; + if (!incremental_Fbuild_started && + _conv_accelerator.getDIIsError() < start_incremental_F_threshold) { + incremental_Fbuild_started = true; + reset_incremental_fock_formation = false; + last_reset_iteration = this_iter - 1; + next_reset_threshold = _conv_accelerator.getDIIsError() / 1e3; + XTP_LOG(Log::info, *_pLog) + << TimeStamp() << " Using incremental 4c build" << flush; + } + if (reset_incremental_fock_formation || !incremental_Fbuild_started) { + J = Eigen::MatrixXd::Zero(Dmat.rows(), Dmat.cols()); + if (_ScaHFX > 0) { + K = Eigen::MatrixXd::Zero(Dmat.rows(), Dmat.cols()); + } + Ddiff = Dmat; + } + if (reset_incremental_fock_formation && incremental_Fbuild_started) { + reset_incremental_fock_formation = false; + last_reset_iteration = this_iter; + next_reset_threshold = _conv_accelerator.getDIIsError() / 1e1; + XTP_LOG(Log::info, *_pLog) + << TimeStamp() << "== reset incremental 4c build" << std::endl; + } + + double integral_error = + std::min(_conv_accelerator.getDIIsError() * 1e-5, 1e-5); if (_ScaHFX > 0) { std::array both = - CalcERIs_EXX(MOs.eigenvectors(), Dmat, 1e-12); - H += both[0]; - Etwo += 0.5 * Dmat.cwiseProduct(both[0]).sum(); - H += 0.5 * _ScaHFX * both[1]; - exx = _ScaHFX / 4 * Dmat.cwiseProduct(both[1]).sum(); + CalcERIs_EXX(MOs.eigenvectors(), Ddiff, integral_error); + J += both[0]; + H += J; + Etwo += 0.5 * Dmat.cwiseProduct(J).sum(); + K += both[1]; + H += 0.5 * _ScaHFX * K; + exx = _ScaHFX / 4 * Dmat.cwiseProduct(K).sum(); XTP_LOG(Log::info, *_pLog) << TimeStamp() << " Filled F+K matrix " << flush; } else { - Eigen::MatrixXd Hartree = CalcERIs(Dmat, 1e-12); + J += CalcERIs(Ddiff, integral_error); XTP_LOG(Log::info, *_pLog) << TimeStamp() << " Filled F matrix " << flush; - H += Hartree; - Etwo += 0.5 * Dmat.cwiseProduct(Hartree).sum(); + H += J; + Etwo += 0.5 * Dmat.cwiseProduct(J).sum(); } Etwo += exx; @@ -289,7 +336,12 @@ bool DFTEngine::Evaluate(Orbitals& orb) { << std::setprecision(12) << totenergy << flush; Dmat = _conv_accelerator.Iterate(Dmat, H, MOs, totenergy); - + if (_conv_accelerator.getDIIsError() < next_reset_threshold || + this_iter - last_reset_iteration >= _fock_matrix_reset) { + reset_incremental_fock_formation = true; + } + Ddiff = Dmat - Dlast; + Dlast = Dmat; PrintMOs(MOs.eigenvalues(), Log::info); XTP_LOG(Log::info, *_pLog) << "\t\tGAP " @@ -559,12 +611,16 @@ Eigen::MatrixXd DFTEngine::RunAtomicDFT_unrestricted( double E_two_alpha = 0.0; double E_two_beta = 0.0; + double integral_error = std::min(1e-5 * 0.5 * + (Convergence_alpha.getDIIsError() + + Convergence_beta.getDIIsError()), + 1e-5); if (_ScaHFX > 0) { std::array both_alpha = - ERIs_atom.CalculateERIs_EXX_4c(dftAOdmat_alpha, 1e-15); + ERIs_atom.CalculateERIs_EXX_4c(dftAOdmat_alpha, integral_error); std::array both_beta = - ERIs_atom.CalculateERIs_EXX_4c(dftAOdmat_beta, 1e-15); + ERIs_atom.CalculateERIs_EXX_4c(dftAOdmat_beta, integral_error); Eigen::MatrixXd Hartree = both_alpha[0] + both_beta[0]; E_two_alpha += Hartree.cwiseProduct(dftAOdmat_alpha).sum(); E_two_beta += Hartree.cwiseProduct(dftAOdmat_beta).sum(); @@ -574,8 +630,8 @@ Eigen::MatrixXd DFTEngine::RunAtomicDFT_unrestricted( H_beta += Hartree + _ScaHFX * both_beta[1]; } else { - Eigen::MatrixXd Hartree = - ERIs_atom.CalculateERIs_4c(dftAOdmat_alpha + dftAOdmat_beta, 1e-15); + Eigen::MatrixXd Hartree = ERIs_atom.CalculateERIs_4c( + dftAOdmat_alpha + dftAOdmat_beta, integral_error); E_two_alpha += Hartree.cwiseProduct(dftAOdmat_alpha).sum(); E_two_beta += Hartree.cwiseProduct(dftAOdmat_beta).sum(); H_alpha += Hartree; diff --git a/src/libxtp/qmpackage.cc b/src/libxtp/qmpackage.cc index 5528fb7941..bb67f8040b 100644 --- a/src/libxtp/qmpackage.cc +++ b/src/libxtp/qmpackage.cc @@ -34,7 +34,7 @@ using std::flush; tools::Property QMPackage::ParseCommonOptions(const tools::Property& options) { std::string key = "package"; - + std::cout << options << std::endl; _settings.read_property(options, key); if (tools::VotcaShareSet()) { @@ -57,6 +57,7 @@ tools::Property QMPackage::ParseCommonOptions(const tools::Property& options) { if (getPackageName() != "xtp") { _scratch_dir = _settings.get("scratch"); } + std::cout << _settings.to_property("package") << std::endl; return _settings.to_property("package"); } diff --git a/src/libxtp/qmpackages/xtpdft.cc b/src/libxtp/qmpackages/xtpdft.cc index ba8e147f3d..b24e55c9d2 100644 --- a/src/libxtp/qmpackages/xtpdft.cc +++ b/src/libxtp/qmpackages/xtpdft.cc @@ -37,7 +37,7 @@ namespace xtp { using namespace std; void XTPDFT::Initialize(const tools::Property& options) { - const std::string& job_name = + const std::string job_name = options.ifExistsReturnElseReturnDefault("job_name", "votca"); _log_file_name = job_name + ".orb"; _mo_file_name = _log_file_name; diff --git a/src/tests/test_dftengine.cc b/src/tests/test_dftengine.cc index 0dbe5def89..28a017c3ed 100644 --- a/src/tests/test_dftengine.cc +++ b/src/tests/test_dftengine.cc @@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(density_guess) { xml << "false" << std::endl; xml << "true\n"; xml << "1e-9\n"; - xml << "cache\n"; + xml << "direct\n"; xml << "" << std::endl; xml << " 1e-7" << std::endl; xml << " DIIS" << std::endl; From d46e445d394eeb069bf14263e71e076a8a3c9ee0 Mon Sep 17 00:00:00 2001 From: jenswehner Date: Sat, 16 Jan 2021 18:12:46 +0100 Subject: [PATCH 02/17] fixed settings --- src/libxtp/dftengine/dftengine.cc | 1 - src/tests/test_dftengine.cc | 12 +++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/libxtp/dftengine/dftengine.cc b/src/libxtp/dftengine/dftengine.cc index 73c0fe76e4..cb03177ba9 100644 --- a/src/libxtp/dftengine/dftengine.cc +++ b/src/libxtp/dftengine/dftengine.cc @@ -46,7 +46,6 @@ namespace xtp { void DFTEngine::Initialize(Property& options) { - std::cout << options << std::endl; string key = "package"; const string key_xtpdft = "package.xtpdft"; _dftbasis_name = options.get(key + ".basisset").as(); diff --git a/src/tests/test_dftengine.cc b/src/tests/test_dftengine.cc index 28a017c3ed..0a587af045 100644 --- a/src/tests/test_dftengine.cc +++ b/src/tests/test_dftengine.cc @@ -31,14 +31,6 @@ using namespace votca::xtp; BOOST_AUTO_TEST_SUITE(dftengine_test) QMMolecule Water() { - std::ofstream xyzfile("molecule.xyz"); - xyzfile << "3" << std::endl; - xyzfile << "Water molecule" << std::endl; - xyzfile << "O 0.00000 0.00000 0.11779" << std::endl; - xyzfile << "H 0.00000 0.75545 -0.47116" << std::endl; - xyzfile << "H 0.00000 -0.75545 -0.47116" << std::endl; - - xyzfile.close(); QMMolecule mol(" ", 1); mol.LoadFromFile(std::string(XTP_TEST_DATA_FOLDER) + "/espfit/molecule.xyz"); return mol; @@ -134,7 +126,8 @@ BOOST_AUTO_TEST_CASE(dft_full) { xml << "false" << std::endl; xml << "true\n"; xml << "1e-9\n"; - xml << "cache\n"; + xml << "direct\n"; + xml << "5\n"; xml << "" << std::endl; xml << " 1e-7" << std::endl; xml << " DIIS" << std::endl; @@ -235,6 +228,7 @@ BOOST_AUTO_TEST_CASE(density_guess) { xml << "true\n"; xml << "1e-9\n"; xml << "direct\n"; + xml << "5\n"; xml << "" << std::endl; xml << " 1e-7" << std::endl; xml << " DIIS" << std::endl; From c9bbc20b1858ed4266df5d068c92473031e135ee Mon Sep 17 00:00:00 2001 From: jenswehner Date: Mon, 28 Jun 2021 15:27:26 +0200 Subject: [PATCH 03/17] refactored incremental fock --- include/votca/xtp/IncrementalFockBuilder.h | 104 +++++++++++++++++++++ share/xtp/data/qmpackage_defaults.xml | 57 +++++------ share/xtp/xml/dftgwbse.xml | 2 +- share/xtp/xml/neighborlist.xml | 35 +------ src/libxtp/dftengine/dftengine.cc | 63 ++++--------- src/libxtp/qmpackage.cc | 1 - 6 files changed, 155 insertions(+), 107 deletions(-) create mode 100644 include/votca/xtp/IncrementalFockBuilder.h diff --git a/include/votca/xtp/IncrementalFockBuilder.h b/include/votca/xtp/IncrementalFockBuilder.h new file mode 100644 index 0000000000..1564aca01a --- /dev/null +++ b/include/votca/xtp/IncrementalFockBuilder.h @@ -0,0 +1,104 @@ +/* + * Copyright 2009-2020 The VOTCA Development Team + * (http://www.votca.org) + * + * 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 +#ifndef VOTCA_XTP_INCREMENTALFOCKBUILDER_H +#define VOTCA_XTP_INCREMENTALFOCKBUILDER_H + +#include "votca/xtp/logger.h" +#include +namespace votca { +namespace xtp { + +// Small Wrapper class to build incremental fock matrix +class IncrementalFockBuilder { + public: + IncrementalFockBuilder(Logger& log, double start_threshold, + Index fock_matrix_reset) + : log_(log),start_incremental_F_threshold_(start_threshold), + fock_matrix_reset_(fock_matrix_reset) {} + + void Configure(const Eigen::MatrixXd& dmat) { + Ddiff_ = dmat; + Dlast_ = dmat; + } + + void Start(Index iteration, double DiisError) { + if (!incremental_Fbuild_started_ && + DiisError < start_incremental_F_threshold_) { + incremental_Fbuild_started_ = true; + reset_incremental_fock_formation_ = false; + last_reset_iteration_ = iteration - 1; + next_reset_threshold_ = DiisError * 1e-3; + XTP_LOG(Log::info, log_) + << TimeStamp() << " Using incremental 4c build" << std::flush; + } + } + + void resetMatrices(Eigen::MatrixXd& J, Eigen::MatrixXd& K, + const Eigen::MatrixXd& dmat) { + if (reset_incremental_fock_formation_ || !incremental_Fbuild_started_) { + J.setZero(); + K.setZero(); + Ddiff_ = dmat; + } + } + + const Eigen::MatrixXd& getDmat_diff() const { return Ddiff_; } + + void UpdateCriteria(double DiisError, Index Iteration) { + if (reset_incremental_fock_formation_ && incremental_Fbuild_started_) { + reset_incremental_fock_formation_ = false; + last_reset_iteration_ = Iteration; + next_reset_threshold_ = DiisError / 10.0; + XTP_LOG(Log::info, log_) + << TimeStamp() << "== reset incremental 4c build" << std::endl; + } + } + + void UpdateDmats(const Eigen::MatrixXd& dmat, double DiisError, + Index Iteration) { + if (DiisError < next_reset_threshold_ || + Iteration - last_reset_iteration_ >= fock_matrix_reset_) { + reset_incremental_fock_formation_ = true; + } + Ddiff_ = dmat - Dlast_; + Dlast_ = dmat; + } + + private: + Logger& log_; + double start_incremental_F_threshold_ = + 1e-5; // Diis error from which to start using incremental builds + Index fock_matrix_reset_; // After how many iterations the fock matrix should + // be reset regardless + + Eigen::MatrixXd Ddiff_; + Eigen::MatrixXd Dlast_; + + bool reset_incremental_fock_formation_ = false; + bool incremental_Fbuild_started_ = false; + double next_reset_threshold_ = 0.0; + Index last_reset_iteration_ = 0; +}; // namespace xtp + +} // namespace xtp +} // namespace votca + +#endif // VOTCA_XTP_INCREMENTALFOCKBUILDER_H diff --git a/share/xtp/data/qmpackage_defaults.xml b/share/xtp/data/qmpackage_defaults.xml index 19b105cfb8..e457cb0196 100644 --- a/share/xtp/data/qmpackage_defaults.xml +++ b/share/xtp/data/qmpackage_defaults.xml @@ -1,44 +1,45 @@ - - - - - + xtp + 0 + 1 + def2-tzvp + + aux-def2-tzvp - - - + false + XC_HYB_GGA_XC_PBEH + /tmp/qmpackage false - - - - - + 0.1 + false + false + tight + + true 1e-9 - - + RI - - - - - - - - - - - + 1e-7 + DIIS + 0.002 + 0.8 + 20 + false + 0.0 + 0.2 + 100 + 1e-7 + 0.7 - - + atom + medium diff --git a/share/xtp/xml/dftgwbse.xml b/share/xtp/xml/dftgwbse.xml index d79ee42340..3104ceb676 100644 --- a/share/xtp/xml/dftgwbse.xml +++ b/share/xtp/xml/dftgwbse.xml @@ -20,7 +20,7 @@ - + diff --git a/share/xtp/xml/neighborlist.xml b/share/xtp/xml/neighborlist.xml index 0dc26beaf0..b6439cb265 100644 --- a/share/xtp/xml/neighborlist.xml +++ b/share/xtp/xml/neighborlist.xml @@ -5,36 +5,9 @@ - - - - - - - - -3.5 - - - a B - - - - -3.5 - - - a C - - - - -5 - - - a D - - - + + + + diff --git a/src/libxtp/dftengine/dftengine.cc b/src/libxtp/dftengine/dftengine.cc index 1452a3b1d3..6af0168e44 100644 --- a/src/libxtp/dftengine/dftengine.cc +++ b/src/libxtp/dftengine/dftengine.cc @@ -26,6 +26,7 @@ #include // Local VOTCA includes +#include "votca/xtp/IncrementalFockBuilder.h" #include "votca/xtp/aomatrix.h" #include "votca/xtp/aopotential.h" #include "votca/xtp/density_integration.h" @@ -34,7 +35,6 @@ #include "votca/xtp/logger.h" #include "votca/xtp/mmregion.h" #include "votca/xtp/orbitals.h" - using boost::format; using namespace boost::filesystem; using namespace std; @@ -57,12 +57,10 @@ void DFTEngine::Initialize(Property& options) { four_center_method_ = options.get(key_xtpdft + ".four_center_method").as(); - - if (four_center_method_!= "RI") { + if (four_center_method_ != "RI") { screening_eps_ = options.get(key_xtpdft + ".screening_eps").as(); fock_matrix_reset_ = options.get(key_xtpdft + ".fock_matrix_reset").as(); - } if (options.get(key + ".use_ecp").as()) { ecp_name_ = options.get(key + ".ecp").as(); @@ -244,21 +242,18 @@ bool DFTEngine::Evaluate(Orbitals& orb) { << flush; Eigen::MatrixXd J = Eigen::MatrixXd::Zero(Dmat.rows(), Dmat.cols()); - Eigen::MatrixXd Ddiff = Dmat; - Eigen::MatrixXd Dlast = Dmat; Eigen::MatrixXd K; if (ScaHFX_ > 0) { K = Eigen::MatrixXd::Zero(Dmat.rows(), Dmat.cols()); } - bool reset_incremental_fock_formation = false; - bool incremental_Fbuild_started = false; - double start_incremental_F_threshold = 1e-5; - double next_reset_threshold = 0.0; - Index last_reset_iteration = 0; + double start_incremental_F_threshold = 1e-5; // Valeev libint if (four_center_method_ == "RI") { - start_incremental_F_threshold = 0.0; + start_incremental_F_threshold = 0.0; // Disable if RI is used } + IncrementalFockBuilder incremental_fock(*pLog_, start_incremental_F_threshold, + fock_matrix_reset_); + incremental_fock.Configure(Dmat); for (Index this_iter = 0; this_iter < max_iter_; this_iter++) { XTP_LOG(Log::error, *pLog_) << flush; @@ -274,45 +269,26 @@ bool DFTEngine::Evaluate(Orbitals& orb) { double Etwo = e_vxc.energy(); double exx = 0.0; - if (!incremental_Fbuild_started && - conv_accelerator_.getDIIsError() < start_incremental_F_threshold) { - incremental_Fbuild_started = true; - reset_incremental_fock_formation = false; - last_reset_iteration = this_iter - 1; - next_reset_threshold = conv_accelerator_.getDIIsError() / 1e3; - XTP_LOG(Log::info, *pLog_) - << TimeStamp() << " Using incremental 4c build" << flush; - } - if (reset_incremental_fock_formation || !incremental_Fbuild_started) { - J = Eigen::MatrixXd::Zero(Dmat.rows(), Dmat.cols()); - if (ScaHFX_ > 0) { - K = Eigen::MatrixXd::Zero(Dmat.rows(), Dmat.cols()); - } - Ddiff = Dmat; - } - if (reset_incremental_fock_formation && incremental_Fbuild_started) { - reset_incremental_fock_formation = false; - last_reset_iteration = this_iter; - next_reset_threshold = conv_accelerator_.getDIIsError() / 1e1; - XTP_LOG(Log::info, *pLog_) - << TimeStamp() << "== reset incremental 4c build" << std::endl; - } + incremental_fock.Start(this_iter, conv_accelerator_.getDIIsError()); + incremental_fock.resetMatrices(J, K, Dmat); + incremental_fock.UpdateCriteria(conv_accelerator_.getDIIsError(), + this_iter); double integral_error = std::min(conv_accelerator_.getDIIsError() * 1e-5, 1e-5); if (ScaHFX_ > 0) { - std::array both = - CalcERIs_EXX(MOs.eigenvectors(), Ddiff, integral_error); + std::array both = CalcERIs_EXX( + MOs.eigenvectors(), incremental_fock.getDmat_diff(), integral_error); J += both[0]; H += J; Etwo += 0.5 * Dmat.cwiseProduct(J).sum(); K += both[1]; H += 0.5 * ScaHFX_ * K; - exx = ScaHFX_ / 4 * Dmat.cwiseProduct(K).sum(); + exx = 0.25* ScaHFX_ * Dmat.cwiseProduct(K).sum(); XTP_LOG(Log::info, *pLog_) << TimeStamp() << " Filled F+K matrix " << flush; } else { - J += CalcERIs(Ddiff, integral_error); + J += CalcERIs(incremental_fock.getDmat_diff(), integral_error); XTP_LOG(Log::info, *pLog_) << TimeStamp() << " Filled F matrix " << flush; H += J; Etwo += 0.5 * Dmat.cwiseProduct(J).sum(); @@ -335,14 +311,9 @@ bool DFTEngine::Evaluate(Orbitals& orb) { XTP_LOG(Log::error, *pLog_) << TimeStamp() << " Total Energy " << std::setprecision(12) << totenergy << flush; - Dmat = conv_accelerator_.Iterate(Dmat, H, MOs, totenergy); - if (conv_accelerator_.getDIIsError() < next_reset_threshold || - this_iter - last_reset_iteration >= fock_matrix_reset_) { - reset_incremental_fock_formation = true; - } - Ddiff = Dmat - Dlast; - Dlast = Dmat; + incremental_fock.UpdateDmats(Dmat, conv_accelerator_.getDIIsError(), + this_iter); PrintMOs(MOs.eigenvalues(), Log::info); diff --git a/src/libxtp/qmpackage.cc b/src/libxtp/qmpackage.cc index 694fb53328..8e9b22469b 100644 --- a/src/libxtp/qmpackage.cc +++ b/src/libxtp/qmpackage.cc @@ -35,7 +35,6 @@ using std::flush; tools::Property QMPackage::ParseCommonOptions(const tools::Property& options) { std::string key = "package"; - std::cout << options << std::endl; settings_.read_property(options, key); if (tools::VotcaShareSet()) { From 7e97e5873b6922536ff0079a771fe599c0aea133 Mon Sep 17 00:00:00 2001 From: Votca Bot Date: Mon, 28 Jun 2021 13:56:25 +0000 Subject: [PATCH 04/17] Update CHANGELOG.rst --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 43e7b55ab5..1073d746dd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -41,6 +41,7 @@ Version 2022-dev - updated benchmark (#714) - reworked commandline options (#715) - renamed cmd line arguments in xtp_parallel (#718) +- added incremental Fokc matrix building (#716) Version 2021.1 (released XX.03.21) ================================== From fcf4fcf276dc691856443fdf1aac78f3420b6ed7 Mon Sep 17 00:00:00 2001 From: Votca Bot Date: Mon, 28 Jun 2021 19:03:20 +0000 Subject: [PATCH 05/17] Format code using clang-format version 12.0.0 (Fedora 12.0.0-2.fc34) --- include/votca/xtp/IncrementalFockBuilder.h | 3 ++- src/libxtp/dftengine/dftengine.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/votca/xtp/IncrementalFockBuilder.h b/include/votca/xtp/IncrementalFockBuilder.h index 1564aca01a..bed822e1d9 100644 --- a/include/votca/xtp/IncrementalFockBuilder.h +++ b/include/votca/xtp/IncrementalFockBuilder.h @@ -31,7 +31,8 @@ class IncrementalFockBuilder { public: IncrementalFockBuilder(Logger& log, double start_threshold, Index fock_matrix_reset) - : log_(log),start_incremental_F_threshold_(start_threshold), + : log_(log), + start_incremental_F_threshold_(start_threshold), fock_matrix_reset_(fock_matrix_reset) {} void Configure(const Eigen::MatrixXd& dmat) { diff --git a/src/libxtp/dftengine/dftengine.cc b/src/libxtp/dftengine/dftengine.cc index 6af0168e44..2c80f0babf 100644 --- a/src/libxtp/dftengine/dftengine.cc +++ b/src/libxtp/dftengine/dftengine.cc @@ -284,7 +284,7 @@ bool DFTEngine::Evaluate(Orbitals& orb) { Etwo += 0.5 * Dmat.cwiseProduct(J).sum(); K += both[1]; H += 0.5 * ScaHFX_ * K; - exx = 0.25* ScaHFX_ * Dmat.cwiseProduct(K).sum(); + exx = 0.25 * ScaHFX_ * Dmat.cwiseProduct(K).sum(); XTP_LOG(Log::info, *pLog_) << TimeStamp() << " Filled F+K matrix " << flush; } else { From deb606300be62850b18410a80bf3bb5b7878563c Mon Sep 17 00:00:00 2001 From: jenswehner Date: Mon, 28 Jun 2021 21:42:12 +0200 Subject: [PATCH 06/17] added tests --- src/tests/CMakeLists.txt | 1 + src/tests/test_incrementalfockbuilder.cc | 94 ++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 src/tests/test_incrementalfockbuilder.cc diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index e525485e56..c92e1b7bdb 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -79,6 +79,7 @@ if(ENABLE_TESTING) list(APPEND test_cases test_orbreorder) list(APPEND test_cases test_molden) list(APPEND test_cases test_gaussianwriter) + list(APPEND test_cases test_incrementalfockbuilder) if(USE_CUDA) list(APPEND test_cases test_cudapipeline) list(APPEND test_cases test_cudamatrix) diff --git a/src/tests/test_incrementalfockbuilder.cc b/src/tests/test_incrementalfockbuilder.cc new file mode 100644 index 0000000000..ecddff5679 --- /dev/null +++ b/src/tests/test_incrementalfockbuilder.cc @@ -0,0 +1,94 @@ +/* + * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * 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 +#define BOOST_TEST_MAIN + +#define BOOST_TEST_MODULE incrementalfockbuilder_test + +// Third party includes +#include + +// Local VOTCA includes +#include "votca/xtp/IncrementalFockBuilder.h" + +using namespace votca::xtp; + +BOOST_AUTO_TEST_SUITE(incrementalfockbuilder) + +BOOST_AUTO_TEST_CASE(off_test) { +Logger log; + +//switched off +IncrementalFockBuilder fb(log,0.0,3); + +Eigen::MatrixXd dmat=Eigen::MatrixXd::Random(10,10); +fb.Configure(dmat); +fb.Start(2, 1e-5); + +Eigen::MatrixXd J=Eigen::MatrixXd::Random(10,10); +Eigen::MatrixXd K=Eigen::MatrixXd::Random(10,10); +fb.resetMatrices(J, K, dmat); +BOOST_CHECK(J.isApproxToConstant(0.0)); +BOOST_CHECK(K.isApproxToConstant(0.0)); + +BOOST_CHECK(fb.getDmat_diff().isApprox(dmat)); + +fb.UpdateDmats(dmat, 1e-5, 2); + +//basically checks that using the same dmat twice leads to a diff of zero +BOOST_CHECK(fb.getDmat_diff().isApproxToConstant(0.0)); + +} + +BOOST_AUTO_TEST_CASE(on_test) { +Logger log; + +//switched on +IncrementalFockBuilder fb(log,1e-5,3); + +Eigen::MatrixXd dmat=Eigen::MatrixXd::Random(10,10); +fb.Configure(dmat); +votca::Index iteration=2; +fb.Start(iteration, 1e-6); + +Eigen::MatrixXd J=Eigen::MatrixXd::Random(10,10); +Eigen::MatrixXd J2=J; +Eigen::MatrixXd K=Eigen::MatrixXd::Random(10,10); +Eigen::MatrixXd K2=K; + +fb.resetMatrices(J, K, dmat); +BOOST_CHECK(J.isApprox(J2)); +BOOST_CHECK(K.isApprox(K2)); + +fb.UpdateCriteria(1e-6, iteration); +fb.UpdateDmats(dmat, 1e-6, iteration); +//basically checks that using the same dmat twice leads to a diff of zero +BOOST_CHECK(fb.getDmat_diff().isApproxToConstant(0.0)); +iteration++; +fb.UpdateCriteria(1e-6, iteration); +fb.UpdateDmats(dmat, 1e-6, iteration); +iteration++; +fb.UpdateCriteria(1e-6, iteration); +fb.UpdateDmats(dmat, 1e-6, iteration); + +//now reset should trigger +fb.resetMatrices(J, K, dmat); +BOOST_CHECK(J.isApproxToConstant(0.0)); +BOOST_CHECK(K.isApproxToConstant(0.0)); + +} + +BOOST_AUTO_TEST_SUITE_END() From 810d24258bd836a0b9e6a08b9d01097f264b33bc Mon Sep 17 00:00:00 2001 From: jenswehner Date: Mon, 28 Jun 2021 21:47:56 +0200 Subject: [PATCH 07/17] added defaults --- share/xtp/data/qmpackage_defaults.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/share/xtp/data/qmpackage_defaults.xml b/share/xtp/data/qmpackage_defaults.xml index e457cb0196..c4c4abc76c 100644 --- a/share/xtp/data/qmpackage_defaults.xml +++ b/share/xtp/data/qmpackage_defaults.xml @@ -25,7 +25,8 @@ true 1e-9 - RI + RI + 5 1e-7 DIIS From 72ce36505a7b06783792f241e6be5a214f24b873 Mon Sep 17 00:00:00 2001 From: Votca Bot Date: Mon, 28 Jun 2021 22:03:30 +0000 Subject: [PATCH 08/17] Format code using clang-format version 12.0.0 (Fedora 12.0.0-2.fc34) --- src/tests/test_incrementalfockbuilder.cc | 100 +++++++++++------------ 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/src/tests/test_incrementalfockbuilder.cc b/src/tests/test_incrementalfockbuilder.cc index ecddff5679..e100aacd20 100644 --- a/src/tests/test_incrementalfockbuilder.cc +++ b/src/tests/test_incrementalfockbuilder.cc @@ -29,66 +29,64 @@ using namespace votca::xtp; BOOST_AUTO_TEST_SUITE(incrementalfockbuilder) BOOST_AUTO_TEST_CASE(off_test) { -Logger log; + Logger log; -//switched off -IncrementalFockBuilder fb(log,0.0,3); + // switched off + IncrementalFockBuilder fb(log, 0.0, 3); -Eigen::MatrixXd dmat=Eigen::MatrixXd::Random(10,10); -fb.Configure(dmat); -fb.Start(2, 1e-5); + Eigen::MatrixXd dmat = Eigen::MatrixXd::Random(10, 10); + fb.Configure(dmat); + fb.Start(2, 1e-5); -Eigen::MatrixXd J=Eigen::MatrixXd::Random(10,10); -Eigen::MatrixXd K=Eigen::MatrixXd::Random(10,10); -fb.resetMatrices(J, K, dmat); -BOOST_CHECK(J.isApproxToConstant(0.0)); -BOOST_CHECK(K.isApproxToConstant(0.0)); + Eigen::MatrixXd J = Eigen::MatrixXd::Random(10, 10); + Eigen::MatrixXd K = Eigen::MatrixXd::Random(10, 10); + fb.resetMatrices(J, K, dmat); + BOOST_CHECK(J.isApproxToConstant(0.0)); + BOOST_CHECK(K.isApproxToConstant(0.0)); -BOOST_CHECK(fb.getDmat_diff().isApprox(dmat)); + BOOST_CHECK(fb.getDmat_diff().isApprox(dmat)); -fb.UpdateDmats(dmat, 1e-5, 2); - -//basically checks that using the same dmat twice leads to a diff of zero -BOOST_CHECK(fb.getDmat_diff().isApproxToConstant(0.0)); + fb.UpdateDmats(dmat, 1e-5, 2); + // basically checks that using the same dmat twice leads to a diff of zero + BOOST_CHECK(fb.getDmat_diff().isApproxToConstant(0.0)); } BOOST_AUTO_TEST_CASE(on_test) { -Logger log; - -//switched on -IncrementalFockBuilder fb(log,1e-5,3); - -Eigen::MatrixXd dmat=Eigen::MatrixXd::Random(10,10); -fb.Configure(dmat); -votca::Index iteration=2; -fb.Start(iteration, 1e-6); - -Eigen::MatrixXd J=Eigen::MatrixXd::Random(10,10); -Eigen::MatrixXd J2=J; -Eigen::MatrixXd K=Eigen::MatrixXd::Random(10,10); -Eigen::MatrixXd K2=K; - -fb.resetMatrices(J, K, dmat); -BOOST_CHECK(J.isApprox(J2)); -BOOST_CHECK(K.isApprox(K2)); - -fb.UpdateCriteria(1e-6, iteration); -fb.UpdateDmats(dmat, 1e-6, iteration); -//basically checks that using the same dmat twice leads to a diff of zero -BOOST_CHECK(fb.getDmat_diff().isApproxToConstant(0.0)); -iteration++; -fb.UpdateCriteria(1e-6, iteration); -fb.UpdateDmats(dmat, 1e-6, iteration); -iteration++; -fb.UpdateCriteria(1e-6, iteration); -fb.UpdateDmats(dmat, 1e-6, iteration); - -//now reset should trigger -fb.resetMatrices(J, K, dmat); -BOOST_CHECK(J.isApproxToConstant(0.0)); -BOOST_CHECK(K.isApproxToConstant(0.0)); - + Logger log; + + // switched on + IncrementalFockBuilder fb(log, 1e-5, 3); + + Eigen::MatrixXd dmat = Eigen::MatrixXd::Random(10, 10); + fb.Configure(dmat); + votca::Index iteration = 2; + fb.Start(iteration, 1e-6); + + Eigen::MatrixXd J = Eigen::MatrixXd::Random(10, 10); + Eigen::MatrixXd J2 = J; + Eigen::MatrixXd K = Eigen::MatrixXd::Random(10, 10); + Eigen::MatrixXd K2 = K; + + fb.resetMatrices(J, K, dmat); + BOOST_CHECK(J.isApprox(J2)); + BOOST_CHECK(K.isApprox(K2)); + + fb.UpdateCriteria(1e-6, iteration); + fb.UpdateDmats(dmat, 1e-6, iteration); + // basically checks that using the same dmat twice leads to a diff of zero + BOOST_CHECK(fb.getDmat_diff().isApproxToConstant(0.0)); + iteration++; + fb.UpdateCriteria(1e-6, iteration); + fb.UpdateDmats(dmat, 1e-6, iteration); + iteration++; + fb.UpdateCriteria(1e-6, iteration); + fb.UpdateDmats(dmat, 1e-6, iteration); + + // now reset should trigger + fb.resetMatrices(J, K, dmat); + BOOST_CHECK(J.isApproxToConstant(0.0)); + BOOST_CHECK(K.isApproxToConstant(0.0)); } BOOST_AUTO_TEST_SUITE_END() From 8d8606b862d4f3bea31909bd75ffdf1bb4eb1c3e Mon Sep 17 00:00:00 2001 From: jenswehner Date: Tue, 29 Jun 2021 00:36:53 +0200 Subject: [PATCH 09/17] made options clearer --- include/votca/xtp/dftengine.h | 4 +--- share/xtp/data/qmpackage_defaults.xml | 2 -- src/libxtp/dftengine/dftengine.cc | 17 ++++++++--------- src/tests/test_dftengine.cc | 8 +++++--- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/include/votca/xtp/dftengine.h b/include/votca/xtp/dftengine.h index 727f92fae2..085c511652 100644 --- a/include/votca/xtp/dftengine.h +++ b/include/votca/xtp/dftengine.h @@ -115,10 +115,8 @@ class DFTEngine { bool with_ecp_; - std::string four_center_method_; - - // Pre-screening Index fock_matrix_reset_; + // Pre-screening double screening_eps_; // numerical integration Vxc diff --git a/share/xtp/data/qmpackage_defaults.xml b/share/xtp/data/qmpackage_defaults.xml index c4c4abc76c..89fbf37a6c 100644 --- a/share/xtp/data/qmpackage_defaults.xml +++ b/share/xtp/data/qmpackage_defaults.xml @@ -22,10 +22,8 @@ - true 1e-9 - RI 5 1e-7 diff --git a/src/libxtp/dftengine/dftengine.cc b/src/libxtp/dftengine/dftengine.cc index 2c80f0babf..c52e12f3c8 100644 --- a/src/libxtp/dftengine/dftengine.cc +++ b/src/libxtp/dftengine/dftengine.cc @@ -54,10 +54,9 @@ void DFTEngine::Initialize(Property& options) { auxbasis_name_ = options.get(key + ".auxbasisset").as(); } - four_center_method_ = - options.get(key_xtpdft + ".four_center_method").as(); - if (four_center_method_ != "RI") { + + if (!auxbasis_name_.empty()) { screening_eps_ = options.get(key_xtpdft + ".screening_eps").as(); fock_matrix_reset_ = options.get(key_xtpdft + ".fock_matrix_reset").as(); @@ -154,7 +153,7 @@ void DFTEngine::CalcElDipole(const Orbitals& orb) const { std::array DFTEngine::CalcERIs_EXX( const Eigen::MatrixXd& MOCoeff, const Eigen::MatrixXd& Dmat, double error) const { - if (four_center_method_ == "RI") { + if (!auxbasis_name_.empty()) { if (conv_accelerator_.getUseMixing() || MOCoeff.rows() == 0) { return ERIs_.CalculateERIs_EXX_3c(Eigen::MatrixXd::Zero(0, 0), Dmat); } else { @@ -169,7 +168,7 @@ std::array DFTEngine::CalcERIs_EXX( Eigen::MatrixXd DFTEngine::CalcERIs(const Eigen::MatrixXd& Dmat, double error) const { - if (four_center_method_ == "RI") { + if (!auxbasis_name_.empty()) { return ERIs_.CalculateERIs_3c(Dmat); } else { return ERIs_.CalculateERIs_4c(Dmat, error); @@ -248,7 +247,7 @@ bool DFTEngine::Evaluate(Orbitals& orb) { } double start_incremental_F_threshold = 1e-5; // Valeev libint - if (four_center_method_ == "RI") { + if (!auxbasis_name_.empty()) { start_incremental_F_threshold = 0.0; // Disable if RI is used } IncrementalFockBuilder incremental_fock(*pLog_, start_incremental_F_threshold, @@ -465,7 +464,7 @@ void DFTEngine::SetupInvariantMatrices() { conv_accelerator_.setOverlap(dftAOoverlap_, 1e-8); conv_accelerator_.PrintConfigOptions(); - if (four_center_method_ == "RI") { + if (!auxbasis_name_.empty()) { // prepare invariant part of electron repulsion integrals ERIs_.Initialize(dftbasis_, auxbasis_); XTP_LOG(Log::info, *pLog_) @@ -738,7 +737,7 @@ void DFTEngine::ConfigOrbfile(Orbitals& orb) { if (with_ecp_) { orb.setECPName(ecp_name_); } - if (four_center_method_ == "RI") { + if (!auxbasis_name_.empty()) { orb.setAuxbasisName(auxbasis_name_); } @@ -802,7 +801,7 @@ void DFTEngine::Prepare(QMMolecule& mol) { << TimeStamp() << " Loaded DFT Basis Set " << dftbasis_name_ << " with " << dftbasis_.AOBasisSize() << " functions" << flush; - if (four_center_method_ == "RI") { + if (!auxbasis_name_.empty()) { BasisSet auxbasisset; auxbasisset.Load(auxbasis_name_); auxbasis_.Fill(auxbasisset, mol); diff --git a/src/tests/test_dftengine.cc b/src/tests/test_dftengine.cc index ecd6138b3b..045b0885e1 100644 --- a/src/tests/test_dftengine.cc +++ b/src/tests/test_dftengine.cc @@ -1,3 +1,6 @@ + + + /* * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org) * @@ -111,7 +114,7 @@ BOOST_AUTO_TEST_CASE(dft_full) { Orbitals orb; orb.QMAtoms() = Water(); - std::ofstream xml("dftengine.xml"); + std::ofstream xml("dftengine2.xml"); xml << "" << std::endl; xml << "1" << std::endl; xml << "xtp" << std::endl; @@ -126,7 +129,6 @@ BOOST_AUTO_TEST_CASE(dft_full) { xml << "false" << std::endl; xml << "true\n"; xml << "1e-9\n"; - xml << "direct\n"; xml << "5\n"; xml << "" << std::endl; xml << " 1e-7" << std::endl; @@ -149,7 +151,7 @@ BOOST_AUTO_TEST_CASE(dft_full) { xml << "" << std::endl; xml.close(); votca::tools::Property prop; - prop.LoadFromXML("dftengine.xml"); + prop.LoadFromXML("dftengine2.xml"); Logger log; dft.setLogger(&log); From 6a12080262586cb1b2fc2cebacc0d9bfe26f1581 Mon Sep 17 00:00:00 2001 From: jenswehner Date: Tue, 29 Jun 2021 00:39:42 +0200 Subject: [PATCH 10/17] updated logging output --- include/votca/xtp/IncrementalFockBuilder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/votca/xtp/IncrementalFockBuilder.h b/include/votca/xtp/IncrementalFockBuilder.h index bed822e1d9..07a9ca11d8 100644 --- a/include/votca/xtp/IncrementalFockBuilder.h +++ b/include/votca/xtp/IncrementalFockBuilder.h @@ -69,7 +69,7 @@ class IncrementalFockBuilder { last_reset_iteration_ = Iteration; next_reset_threshold_ = DiisError / 10.0; XTP_LOG(Log::info, log_) - << TimeStamp() << "== reset incremental 4c build" << std::endl; + << TimeStamp() << " Reset incremental 4c build" << std::endl; } } From bfa20e81da4fb03e1d74898bd95c98d4f7335044 Mon Sep 17 00:00:00 2001 From: Votca Bot Date: Mon, 28 Jun 2021 23:11:56 +0000 Subject: [PATCH 11/17] Format code using clang-format version 12.0.0 (Fedora 12.0.0-2.fc34) --- src/libxtp/dftengine/dftengine.cc | 2 -- src/tests/test_dftengine.cc | 1 - 2 files changed, 3 deletions(-) diff --git a/src/libxtp/dftengine/dftengine.cc b/src/libxtp/dftengine/dftengine.cc index c52e12f3c8..c00d94c9e4 100644 --- a/src/libxtp/dftengine/dftengine.cc +++ b/src/libxtp/dftengine/dftengine.cc @@ -54,8 +54,6 @@ void DFTEngine::Initialize(Property& options) { auxbasis_name_ = options.get(key + ".auxbasisset").as(); } - - if (!auxbasis_name_.empty()) { screening_eps_ = options.get(key_xtpdft + ".screening_eps").as(); fock_matrix_reset_ = diff --git a/src/tests/test_dftengine.cc b/src/tests/test_dftengine.cc index 045b0885e1..1e4aab2143 100644 --- a/src/tests/test_dftengine.cc +++ b/src/tests/test_dftengine.cc @@ -1,6 +1,5 @@ - /* * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org) * From 206daf77eddf9580057709bae89f89a1b0fec99f Mon Sep 17 00:00:00 2001 From: jenswehner Date: Tue, 29 Jun 2021 09:52:28 +0200 Subject: [PATCH 12/17] remove cout --- include/votca/xtp/IncrementalFockBuilder.h | 18 ++++++++++-------- src/libxtp/dftengine/dftengine.cc | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/votca/xtp/IncrementalFockBuilder.h b/include/votca/xtp/IncrementalFockBuilder.h index 07a9ca11d8..f0f5cfa83a 100644 --- a/include/votca/xtp/IncrementalFockBuilder.h +++ b/include/votca/xtp/IncrementalFockBuilder.h @@ -34,6 +34,7 @@ class IncrementalFockBuilder { : log_(log), start_incremental_F_threshold_(start_threshold), fock_matrix_reset_(fock_matrix_reset) {} + void Configure(const Eigen::MatrixXd& dmat) { Ddiff_ = dmat; @@ -46,9 +47,10 @@ class IncrementalFockBuilder { incremental_Fbuild_started_ = true; reset_incremental_fock_formation_ = false; last_reset_iteration_ = iteration - 1; - next_reset_threshold_ = DiisError * 1e-3; - XTP_LOG(Log::info, log_) - << TimeStamp() << " Using incremental 4c build" << std::flush; + next_reset_threshold_ = DiisError / 10.0; + XTP_LOG(Log::error, log_) + << TimeStamp() << " Using incremental 4c build from here" + << std::flush; } } @@ -68,15 +70,15 @@ class IncrementalFockBuilder { reset_incremental_fock_formation_ = false; last_reset_iteration_ = Iteration; next_reset_threshold_ = DiisError / 10.0; - XTP_LOG(Log::info, log_) - << TimeStamp() << " Reset incremental 4c build" << std::endl; + XTP_LOG(Log::error, log_) + << TimeStamp() << " Reset incremental 4c build" << std::flush; } } void UpdateDmats(const Eigen::MatrixXd& dmat, double DiisError, Index Iteration) { if (DiisError < next_reset_threshold_ || - Iteration - last_reset_iteration_ >= fock_matrix_reset_) { + Iteration - last_reset_iteration_ > fock_matrix_reset_) { reset_incremental_fock_formation_ = true; } Ddiff_ = dmat - Dlast_; @@ -85,8 +87,8 @@ class IncrementalFockBuilder { private: Logger& log_; - double start_incremental_F_threshold_ = - 1e-5; // Diis error from which to start using incremental builds + double start_incremental_F_threshold_; // Diis error from which to start + // using incremental builds Index fock_matrix_reset_; // After how many iterations the fock matrix should // be reset regardless diff --git a/src/libxtp/dftengine/dftengine.cc b/src/libxtp/dftengine/dftengine.cc index c52e12f3c8..0c4c19b1ed 100644 --- a/src/libxtp/dftengine/dftengine.cc +++ b/src/libxtp/dftengine/dftengine.cc @@ -246,7 +246,7 @@ bool DFTEngine::Evaluate(Orbitals& orb) { K = Eigen::MatrixXd::Zero(Dmat.rows(), Dmat.cols()); } - double start_incremental_F_threshold = 1e-5; // Valeev libint + double start_incremental_F_threshold = 1e-4; if (!auxbasis_name_.empty()) { start_incremental_F_threshold = 0.0; // Disable if RI is used } From 9c6aa7a0b8b44c44f178f50fc3ad96fb456de316 Mon Sep 17 00:00:00 2001 From: Votca Bot Date: Tue, 29 Jun 2021 08:19:25 +0000 Subject: [PATCH 13/17] Format code using clang-format version 12.0.0 (Fedora 12.0.0-2.fc34) --- include/votca/xtp/IncrementalFockBuilder.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/votca/xtp/IncrementalFockBuilder.h b/include/votca/xtp/IncrementalFockBuilder.h index f0f5cfa83a..d3c13d3168 100644 --- a/include/votca/xtp/IncrementalFockBuilder.h +++ b/include/votca/xtp/IncrementalFockBuilder.h @@ -34,7 +34,6 @@ class IncrementalFockBuilder { : log_(log), start_incremental_F_threshold_(start_threshold), fock_matrix_reset_(fock_matrix_reset) {} - void Configure(const Eigen::MatrixXd& dmat) { Ddiff_ = dmat; From bafeab8155cda0753d0e215fed887852b6aa21d6 Mon Sep 17 00:00:00 2001 From: jenswehner Date: Tue, 29 Jun 2021 13:12:31 +0200 Subject: [PATCH 14/17] fixed test --- src/tests/test_incrementalfockbuilder.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tests/test_incrementalfockbuilder.cc b/src/tests/test_incrementalfockbuilder.cc index e100aacd20..534a8de31b 100644 --- a/src/tests/test_incrementalfockbuilder.cc +++ b/src/tests/test_incrementalfockbuilder.cc @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(on_test) { Logger log; // switched on - IncrementalFockBuilder fb(log, 1e-5, 3); + IncrementalFockBuilder fb(log, 1e-5, 2); Eigen::MatrixXd dmat = Eigen::MatrixXd::Random(10, 10); fb.Configure(dmat); @@ -81,7 +81,8 @@ BOOST_AUTO_TEST_CASE(on_test) { fb.UpdateDmats(dmat, 1e-6, iteration); iteration++; fb.UpdateCriteria(1e-6, iteration); - fb.UpdateDmats(dmat, 1e-6, iteration); + fb.UpdateDmats(dmat, 1e-6, iteration);\ + // now reset should trigger fb.resetMatrices(J, K, dmat); From 7efdb4e175ec1ed028cb4570c8f742168a769a83 Mon Sep 17 00:00:00 2001 From: jenswehner Date: Tue, 29 Jun 2021 14:43:00 +0200 Subject: [PATCH 15/17] large fingers --- src/tests/test_incrementalfockbuilder.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/test_incrementalfockbuilder.cc b/src/tests/test_incrementalfockbuilder.cc index 534a8de31b..b344833c3a 100644 --- a/src/tests/test_incrementalfockbuilder.cc +++ b/src/tests/test_incrementalfockbuilder.cc @@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(on_test) { fb.UpdateDmats(dmat, 1e-6, iteration); iteration++; fb.UpdateCriteria(1e-6, iteration); - fb.UpdateDmats(dmat, 1e-6, iteration);\ + fb.UpdateDmats(dmat, 1e-6, iteration); // now reset should trigger From 2ef45e22478a8b0b12f76107789e3b905d41e8de Mon Sep 17 00:00:00 2001 From: Votca Bot Date: Tue, 29 Jun 2021 14:15:58 +0000 Subject: [PATCH 16/17] Format code using clang-format version 12.0.0 (Fedora 12.0.0-2.fc34) --- src/tests/test_incrementalfockbuilder.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tests/test_incrementalfockbuilder.cc b/src/tests/test_incrementalfockbuilder.cc index b344833c3a..9aadab7741 100644 --- a/src/tests/test_incrementalfockbuilder.cc +++ b/src/tests/test_incrementalfockbuilder.cc @@ -82,7 +82,6 @@ BOOST_AUTO_TEST_CASE(on_test) { iteration++; fb.UpdateCriteria(1e-6, iteration); fb.UpdateDmats(dmat, 1e-6, iteration); - // now reset should trigger fb.resetMatrices(J, K, dmat); From 519786187e81ad1f60e69423562db300e2ff96bf Mon Sep 17 00:00:00 2001 From: Jens Date: Wed, 30 Jun 2021 19:28:08 +0200 Subject: [PATCH 17/17] Update CHANGELOG.rst --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1073d746dd..e99dc07a96 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -41,7 +41,7 @@ Version 2022-dev - updated benchmark (#714) - reworked commandline options (#715) - renamed cmd line arguments in xtp_parallel (#718) -- added incremental Fokc matrix building (#716) +- added incremental Fock matrix building (#716) Version 2021.1 (released XX.03.21) ==================================