This commit is contained in:
matthias@quintern.xyz 2025-03-09 22:01:31 +01:00
parent ac6feedba4
commit a1ddab1ce8
4 changed files with 13 additions and 10 deletions

View File

@ -1,6 +1,6 @@
#include "dmrg.hpp"
#include "lanczos.hpp"
#include "algorithm.hpp"
#include "type.hpp"
#include "util.hpp"
@ -70,14 +70,16 @@ namespace dmrg {
}
template<typename T>
void DMRGEngine<T>::sweep(MPS<T>& psi) {
void DMRGEngine<T>::sweep(MPS<T>& psi, postUpdateFunction_t<T> postUpdateFunc) {
// Sweep left to right
for (unsigned i = 0; i < psi.getL() - 2; ++i) {
update_bond(i, psi);
postUpdateFunc(psi, i);
}
// Sweep right to left
for (unsigned i = psi.getL() - 2; i > 0; --i) {
update_bond(i, psi);
postUpdateFunc(psi, i);
}
}
@ -273,16 +275,16 @@ namespace dmrg {
}
template<typename T>
void run(MPS<T>& psi, const std::vector<std::shared_ptr<e::Tensor<T, 4>>>& H_mpos, unsigned chiMax, T eps, unsigned nSweeps, postUpdateFunction_t<T> postUpdateFunc) {
void run(MPS<T>& psi, const std::vector<std::shared_ptr<e::Tensor<T, 4>>>& H_mpos, unsigned chiMax, T eps, unsigned nSweeps, postUpdateFunction_t<T> postSweepFunc, postUpdateFunction_t<T> postUpdateFunc) {
auto engine = DMRGEngine(psi, H_mpos, chiMax, eps);
for (unsigned i = 0; i < nSweeps; i++) {
engine.sweep(psi);
if (postUpdateFunc(psi, i)) break;
engine.sweep(psi, postUpdateFunc);
if (postSweepFunc(psi, i)) break;
}
}
template class dmrg::DMRGEngine<dtype>;
template void run<dtype>(MPS<dtype>& psi, const std::vector<std::shared_ptr<e::Tensor<dtype, 4>>>& H_mpos, unsigned chiMax, dtype eps, unsigned nSweeps, postUpdateFunction_t<dtype> postUpdateFunc);
template void run<dtype>(MPS<dtype>& psi, const std::vector<std::shared_ptr<e::Tensor<dtype, 4>>>& H_mpos, unsigned chiMax, dtype eps, unsigned nSweeps, postUpdateFunction_t<dtype>, postUpdateFunction_t<dtype>);
} // namespace dmrg

View File

@ -41,12 +41,13 @@ namespace dmrg {
unsigned chiMax = 100, T eps = 1e-12);
void initialize(MPS<T>& psi);
void sweep(MPS<T>& psi);
/// Post update function is called after each bond update, its only meant for emscripten_sleep!
void sweep(MPS<T>& psi, postUpdateFunction_t<T> postUpdateFunc=postUpdateNoop<T>);
void update_bond(int i, MPS<T>& psi);
void update_RP(int i, MPS<T>& psi);
void update_LP(int i, MPS<T>& psi);
};
template<typename T>
void run(MPS<T>& psi, const std::vector<std::shared_ptr<e::Tensor<T, 4>>>& H_mpos, unsigned chiMax, T eps, unsigned nSweeps, postUpdateFunction_t<T> postUpdateFunc);
void run(MPS<T>& psi, const std::vector<std::shared_ptr<e::Tensor<T, 4>>>& H_mpos, unsigned chiMax, T eps, unsigned nSweeps, postUpdateFunction_t<T> postSweepFunc, postUpdateFunction_t<T> postUpdateFunc=postUpdateNoop<T>);
}

View File

@ -29,7 +29,7 @@ std::vector<std::shared_ptr<OutType>> forEachUnique(std::function<OutType(const
namespace tebd {
template<typename T>
e::Tensor<T, 4> getTimeEvolutionMatrix(const e::MatrixX<T>& bond, T dt, unsigned localDim) {
e::MatrixX<T> U = (-bond * dt).exp();
e::MatrixX<T> U = (bond * (Imag*dt)).exp();
// std::cout << "U = \n" << U << "\n\n";
return bondMatrix2Tensor<T>(U, localDim);
}

View File

@ -20,7 +20,7 @@ namespace tebd {
/**
* @brief Apply time evolution on a bond
* @details
* \f[U = \exp{ B \, \partial t} \f]
* \f[U = \exp{ B \, i \partial t} \f]
*/
template<typename T>
e::Tensor<T, 4> getTimeEvolutionMatrix(const e::MatrixX<T>& bond, T dt, unsigned localDim);