From 68d6af955e87e20a0c040d74206c5155e4be751a Mon Sep 17 00:00:00 2001 From: Thomas Kloss Date: Mon, 6 Jan 2025 06:35:26 +0100 Subject: [PATCH 1/3] add QTensorCI contructor which takes a tensor train --- include/xfac/tensor/tensor_ci_2.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/include/xfac/tensor/tensor_ci_2.h b/include/xfac/tensor/tensor_ci_2.h index 5dfee6c..ec2ca00 100644 --- a/include/xfac/tensor/tensor_ci_2.h +++ b/include/xfac/tensor/tensor_ci_2.h @@ -79,8 +79,8 @@ struct TensorCI2 { {} /// constructs a TensorCI2 from a given tensor train, and using the provided function f. - TensorCI2(function)> f_, TensorTrain tt_, TensorCI2Param param_={}) - : f {f_, param_.useCachedFunction} + TensorCI2(TensorFunction const& f_, TensorTrain tt_, TensorCI2Param param_={}) + : f {f_} , param(param_) , pivotError(1) , Iset {tt_.M.size()} @@ -124,6 +124,11 @@ struct TensorCI2 { iterate(1,0); // just to define tt, while reevaluating the original f in the pivots. } + /// constructs a TensorCI2 from a given tensor train, and using the provided function f. + TensorCI2(function)> f_, TensorTrain tt_, TensorCI2Param param_={}) + : TensorCI2(TensorFunction {f_, param_.useCachedFunction}, tt_, param_) + {} + /// constructs a TensorCI2 from a given tensor train. It takes the tt as a true function f. TensorCI2(TensorTrain const& tt_, TensorCI2Param param_={}) : TensorCI2(tt_, tt_, param_) {} @@ -387,6 +392,8 @@ class QTensorCI: public TensorCI2 { public: grid::Quantics grid; + QTensorCI() = default; + /// constructs a rank-1 QTensorCI from a function f:(u1,u2,...,un)->T and the given quantics grid QTensorCI(function)> f_, grid::Quantics grid_, TensorCI2Param par={}) : TensorCI2 {tensorFun(f_,grid_), grid_.tensorDims(), par} @@ -399,6 +406,12 @@ class QTensorCI: public TensorCI2 { , grid {grid_} {} + /// constructs a rank-1 QTensorCI from a function f:(u1,u2,...,un)->T, a tensor train and the given quantics grid + QTensorCI(function)> f_, grid::Quantics grid_, TensorTrain tt_, TensorCI2Param par={}) + : TensorCI2 {tensorFun(f_,grid_), tt_, par} + , grid {grid_} + {} + /// returns the underline quantics tensor train QTensorTrain get_qtt() const { return {this->tt, grid}; } From 672e75d2ffbce5e01616906a108d5f34673dce89 Mon Sep 17 00:00:00 2001 From: Thomas Kloss Date: Tue, 14 Jan 2025 11:38:09 +0100 Subject: [PATCH 2/3] add test for constructing QTensorCI from a tensor train --- include/xfac/tensor/tensor_ci_2.h | 2 -- test/test_tensor_ci_2.cpp | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/xfac/tensor/tensor_ci_2.h b/include/xfac/tensor/tensor_ci_2.h index ec2ca00..5e8f953 100644 --- a/include/xfac/tensor/tensor_ci_2.h +++ b/include/xfac/tensor/tensor_ci_2.h @@ -392,8 +392,6 @@ class QTensorCI: public TensorCI2 { public: grid::Quantics grid; - QTensorCI() = default; - /// constructs a rank-1 QTensorCI from a function f:(u1,u2,...,un)->T and the given quantics grid QTensorCI(function)> f_, grid::Quantics grid_, TensorCI2Param par={}) : TensorCI2 {tensorFun(f_,grid_), grid_.tensorDims(), par} diff --git a/test/test_tensor_ci_2.cpp b/test/test_tensor_ci_2.cpp index 03e1b80..8093223 100644 --- a/test/test_tensor_ci_2.cpp +++ b/test/test_tensor_ci_2.cpp @@ -143,6 +143,23 @@ TEST_CASE("quantics 2") cout << "true error=" << ci.trueError(1< cache; + auto f=[&](vector y) { double x = y[0]; return cache[x]=f2(x); }; + + auto ci=QTensorCI(f, grid::Quantics {0.0, 1.0, 30}, {.bondDim=20, .useCachedFunction=true}); + ci.iterate(3); + + auto ci_2=QTensorCI(f, grid::Quantics {0.0, 1.0, 30}, ci.get_qtt().tt, {.bondDim=20, .useCachedFunction=true}); + ci_2.iterate(); + auto res = ci_2.get_qtt().integral(); + REQUIRE(std::abs(res - exact)<1e-9); + } + SECTION( "copy pivots quantics" ) { function f2=[&](double x) { return pow(x+0.1,5)+pow(x-0.5,4); }; From 2810ce3f74db603c72bfc9b354189c82b2148d99 Mon Sep 17 00:00:00 2001 From: Yuriel Date: Thu, 16 Jan 2025 15:00:12 +0100 Subject: [PATCH 3/3] add test for quantics for complex valued function --- include/xfac/tensor/tensor_ci_2.h | 2 +- test/test_tensor_ci_2.cpp | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/xfac/tensor/tensor_ci_2.h b/include/xfac/tensor/tensor_ci_2.h index 5e8f953..0f1ba31 100644 --- a/include/xfac/tensor/tensor_ci_2.h +++ b/include/xfac/tensor/tensor_ci_2.h @@ -404,7 +404,7 @@ class QTensorCI: public TensorCI2 { , grid {grid_} {} - /// constructs a rank-1 QTensorCI from a function f:(u1,u2,...,un)->T, a tensor train and the given quantics grid + /// constructs a QTensorCI from a function f:(u1,u2,...,un)->T, a tensor train and the given quantics grid QTensorCI(function)> f_, grid::Quantics grid_, TensorTrain tt_, TensorCI2Param par={}) : TensorCI2 {tensorFun(f_,grid_), tt_, par} , grid {grid_} diff --git a/test/test_tensor_ci_2.cpp b/test/test_tensor_ci_2.cpp index 8093223..f0f6ed0 100644 --- a/test/test_tensor_ci_2.cpp +++ b/test/test_tensor_ci_2.cpp @@ -155,11 +155,28 @@ TEST_CASE("quantics 2") ci.iterate(3); auto ci_2=QTensorCI(f, grid::Quantics {0.0, 1.0, 30}, ci.get_qtt().tt, {.bondDim=20, .useCachedFunction=true}); - ci_2.iterate(); + //ci_2.iterate(); auto res = ci_2.get_qtt().integral(); REQUIRE(std::abs(res - exact)<1e-9); } + SECTION( "restart from tensor train complex" ) + { + function f2=[&](double x) { return pow(x+0.1,5)+pow(x-0.5,4); }; + auto exact = pow(1.1,6)/6-pow(0.1,6)/6 + pow(0.5,5)/5+pow(0.5,5)/5; + + auto f=[&](vector y) { return cmpx(f2(y[0]),f2(y[1])); }; + + auto ci=QTensorCI(f, grid::Quantics {0.0, 1.0, 40, 2, true}); + ci.iterate(5); + ci.get_qtt().save("my_qtt.dat"); + + auto qtt=QTensorTrain::load("my_qtt.dat"); + auto ci_2=QTensorCI(f, qtt.grid, qtt.tt); + auto res = ci_2.get_qtt().integral(); + REQUIRE(std::abs(res - cmpx(exact,exact))<1e-9); + } + SECTION( "copy pivots quantics" ) { function f2=[&](double x) { return pow(x+0.1,5)+pow(x-0.5,4); };