Skip to content

Commit

Permalink
Added missing includes an inline statements for COMPILED_LIB support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Peschke committed Nov 15, 2024
1 parent c68f68a commit a673fcc
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 42 deletions.
2 changes: 1 addition & 1 deletion include/Xped/AD/ADTensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ operator*(const Tensor<Scalar, Rank, MiddleRank, Symmetry, true>& left, const Te

namespace std {

stan::math::var_value<double> real(const stan::math::var_value<double>& z) { return z; }
inline stan::math::var_value<double> real(const stan::math::var_value<double>& z) { return z; }

} // namespace std

Expand Down
3 changes: 2 additions & 1 deletion include/Xped/AD/complex_var.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define XPED_COMPLEX_VAR_HPP_

#include "Xped/AD/complex_vari.hpp"
#include "stan/math/rev/core/callback_vari.hpp"
#include "stan/math/rev/core/var.hpp"

namespace stan::math {
Expand Down Expand Up @@ -260,7 +261,7 @@ inline var_value<std::complex<double>> operator/(const var_value<std::complex<do

namespace std {

stan::math::var_value<double> real(const stan::math::var_value<std::complex<double>>& z)
inline stan::math::var_value<double> real(const stan::math::var_value<std::complex<double>>& z)
{
return stan::math::make_callback_var(z.val().real(), [z](auto&& vi) { z.adj() += vi.adj(); });
}
Expand Down
1 change: 1 addition & 0 deletions include/Xped/Physics/SiteOperator.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef XPED_SITEOPERATOR_HPP_
#define XPED_SITEOPERATOR_HPP_

#include "Xped/AD/ADTensor.hpp"
#include "Xped/Core/Tensor.hpp"

namespace Xped {
Expand Down
1 change: 0 additions & 1 deletion include/Xped/Symmetry/ZN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ struct ZN : public SymBase<ZN<Kind, N, Scalar_>>
if constexpr(IS_FERMIONIC[0]) {
bool parity = (ql[0] % 2 != 0) and (qr[0] % 2 != 0);
sign = parity ? -1. : 1.;
SPDLOG_INFO("ql,pl={},{}; qr,pr={},{}; sign={}\n", ql[0], ql[0] % 2 != 0, qr[0], qr[0] % 2 != 0, sign);
}
return triangle(ql, qr, qf) ? sign * Scalar(1.) : Scalar(0.);
};
Expand Down
5 changes: 5 additions & 0 deletions src/Core/FusionTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
#include "Xped/Core/ScalarTraits.hpp"
#include "Xped/Hash/hash.hpp"
#include "Xped/Interfaces/PlainInterface.hpp"

#include "Xped/Symmetry/CombSym.hpp"
#include "Xped/Symmetry/S1xS2.hpp"
#include "Xped/Symmetry/SU2.hpp"
#include "Xped/Symmetry/U0.hpp"
#include "Xped/Symmetry/U1.hpp"
#include "Xped/Symmetry/ZN.hpp"

#include "Xped/Symmetry/functions.hpp"
#include "Xped/Util/Macros.hpp"

Expand Down
3 changes: 3 additions & 0 deletions src/Core/Qbasis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "Xped/Symmetry/SU2.hpp"
#include "Xped/Symmetry/U0.hpp"
#include "Xped/Symmetry/U1.hpp"
#include "Xped/Symmetry/ZN.hpp"
#include "Xped/Symmetry/S1xS2.hpp"
#include "Xped/Symmetry/CombSym.hpp"

#include "Xped/Core/Qbasis.hpp"

Expand Down
3 changes: 3 additions & 0 deletions src/Core/Tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include "Xped/Symmetry/SU2.hpp"
#include "Xped/Symmetry/U0.hpp"
#include "Xped/Symmetry/U1.hpp"
#include "Xped/Symmetry/ZN.hpp"
#include "Xped/Symmetry/S1xS2.hpp"
#include "Xped/Symmetry/CombSym.hpp"

using std::cout;
using std::endl;
Expand Down
3 changes: 3 additions & 0 deletions src/Core/TensorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "Xped/Symmetry/SU2.hpp"
#include "Xped/Symmetry/U0.hpp"
#include "Xped/Symmetry/U1.hpp"
#include "Xped/Symmetry/ZN.hpp"
#include "Xped/Symmetry/S1xS2.hpp"
#include "Xped/Symmetry/CombSym.hpp"

#include "Xped/Core/AdjointOp.hpp"
#include "Xped/Core/BlockUnaryOp.hpp"
Expand Down
3 changes: 3 additions & 0 deletions src/Core/TensorHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "Xped/Symmetry/SU2.hpp"
#include "Xped/Symmetry/U0.hpp"
#include "Xped/Symmetry/U1.hpp"
#include "Xped/Symmetry/ZN.hpp"
#include "Xped/Symmetry/S1xS2.hpp"
#include "Xped/Symmetry/CombSym.hpp"

namespace Xped {

Expand Down
6 changes: 5 additions & 1 deletion src/Core/treepair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ using std::size_t;
#endif

#include "Xped/Core/FusionTree.hpp"
#include "Xped/Core/treepair.hpp"
#include "Xped/Core/ScalarTraits.hpp"
#include "Xped/Core/treepair.hpp"

#include "Xped/Symmetry/CombSym.hpp"
#include "Xped/Symmetry/S1xS2.hpp"
#include "Xped/Symmetry/SU2.hpp"
#include "Xped/Symmetry/U0.hpp"
#include "Xped/Symmetry/U1.hpp"
#include "Xped/Symmetry/ZN.hpp"

namespace Xped {

Expand Down
6 changes: 6 additions & 0 deletions src/Physics/SiteOperator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include "Xped/Physics/SiteOperator.hpp"
#include "Xped/Symmetry/functions.hpp"
#include "Xped/Symmetry/SU2.hpp"
#include "Xped/Symmetry/U1.hpp"
#include "Xped/Symmetry/U0.hpp"
#include "Xped/Symmetry/ZN.hpp"
#include "Xped/Symmetry/S1xS2.hpp"
#include "Xped/Symmetry/CombSym.hpp"

namespace Xped {

Expand Down
80 changes: 42 additions & 38 deletions tests/ad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,47 +320,51 @@ TEST_CASE("Testing backwards AD for permute().")
SUBCASE("SU2")
{
using Symmetry = Xped::Sym::SU2<Xped::Sym::SpinSU2>;
using Scalar = double;
// using Scalar = double;
// auto f = [](const auto& t) {
// constexpr auto ENABLE_AD = std::decay_t<decltype(t)>::IS_AD;
// auto tdag = t.adjoint().eval().template permute<-4, 1, 2, 3, 4, 0>(Xped::Bool<ENABLE_AD>{});
// Xped::Qbasis<Symmetry> env;
// Xped::Qbasis<Symmetry> peps = t.uncoupledDomain()[0];
// env.push_back({1}, 2);
// env.push_back({2}, 2);
// env.push_back({3}, 2);
// Xped::Tensor<double, 2, 0, Symmetry, false> C1init({{env, env}}, {{}});
// static thread_local std::mt19937 engine(std::random_device{}());
// engine.seed(0);
// C1init.setRandom(engine);
// Xped::Tensor<double, 2, 0, Symmetry, ENABLE_AD> C1 = C1init;
// Xped::Tensor<double, 4, 0, Symmetry, false> T1init({{env, env, peps, peps}}, {{}});
// engine.seed(1);
// T1init.setRandom(engine);
// Xped::Tensor<double, 4, 0, Symmetry, ENABLE_AD> T1 = T1init;

// auto C1T1 = C1.template contract<std::array{-1, 1}, std::array{1, -2, -3, -4}, 1>(T1.adjoint().eval());
// auto T4C1T1 = T1.adjoint().eval().template contract<std::array{-1, 1, -2, -3}, std::array{1, -4, -5, -6}, 3>(C1T1.twist(0));
// auto T4C1T1A = T4C1T1.template contract<std::array{-1, 1, -2, -3, 2, -4}, std::array{1, 2, -5, -6, -7}, 4>(t);
// auto C4T3 = C1.template contract<std::array{1, -1}, std::array{-2, 1, -3, -4}, 1>(T1.adjoint().eval());
// auto C4T3Ad = C4T3.template contract<std::array{-1, -2, -3, 1}, std::array{-4, -5, -6, 1, -7}, 3>(tdag.twist(3));
// auto left_half = T4C1T1A.template contract<std::array{1, 2, -1, 3, -2, 4, -3}, std::array{1, -4, 4, 2, 3, -5, -6}, 3>(C4T3Ad);
// // return left_half.coeff(0, 0, 0);
// auto T1C2 = T1.template contract<std::array{-1, 1, -2, -3}, std::array{1, -4}, 3>(C1.adjoint().eval());
// auto T1C2T2 = T1C2.template contract<std::array{-1, -2, -3, 1}, std::array{1, -4, -5, -6}, 3>(T1);
// auto AT1C2T2 = t.adjoint().eval().twist(1).template contract<std::array{-3, -1, 1, 2, -2}, std::array{-4, 1, -5, -6, 2, -7},
// 3>(T1C2T2); auto T3C3 = T1.template contract<std::array{1, -1, -2, -3}, std::array{-4, 1}, 3>(C1.adjoint().eval()); auto T3C3Ad =
// T3C3.template contract<std::array{-1, -2, 1, -3}, std::array{-4, -5, -6, 1, -7}, 3>(t); auto right_half = AT1C2T2.template
// contract<std::array{-1, 1, -2, -3, 2, 3, 4}, std::array{-4, 1, 3, -5, 2, 4, -6}, 3>(T3C3Ad); auto rho_h = left_half.template
// contract<std::array{1, 2, -3, 3, 4, -1}, std::array{2, -4, 1, 3, 4, -2}, 2>(right_half); auto Id2 = Xped::Tensor<Scalar, 2, 2,
// Symmetry, false>::Identity(rho_h.uncoupledCodomain(), rho_h.uncoupledDomain(), rho_h.world()); auto norm = rho_h.template
// contract<std::array{1, 2, 3, 4}, std::array{3, 4, 1, 2}, 0>(Id2.twist(0).twist(1)).trace(); rho_h = rho_h * (1. / norm);
// // return tmp.coeff(tmp.sector().size() - 1, 0, 0);
// return rho_h.trace();
// // return tmp.coeff(0, 0, 0);
// };
auto f = [](const auto& t) {
constexpr auto ENABLE_AD = std::decay_t<decltype(t)>::IS_AD;
auto tdag = t.adjoint().eval().template permute<-4, 1, 2, 3, 4, 0>(Xped::Bool<ENABLE_AD>{});
Xped::Qbasis<Symmetry> env;
Xped::Qbasis<Symmetry> peps = t.uncoupledDomain()[0];
env.push_back({1}, 2);
env.push_back({2}, 2);
env.push_back({3}, 2);
Xped::Tensor<double, 2, 0, Symmetry, false> C1init({{env, env}}, {{}});
static thread_local std::mt19937 engine(std::random_device{}());
engine.seed(0);
C1init.setRandom(engine);
Xped::Tensor<double, 2, 0, Symmetry, ENABLE_AD> C1 = C1init;
Xped::Tensor<double, 4, 0, Symmetry, false> T1init({{env, env, peps, peps}}, {{}});
engine.seed(1);
T1init.setRandom(engine);
Xped::Tensor<double, 4, 0, Symmetry, ENABLE_AD> T1 = T1init;

auto C1T1 = C1.template contract<std::array{-1, 1}, std::array{1, -2, -3, -4}, 1>(T1.adjoint().eval());
auto T4C1T1 = T1.adjoint().eval().template contract<std::array{-1, 1, -2, -3}, std::array{1, -4, -5, -6}, 3>(C1T1.twist(0));
auto T4C1T1A = T4C1T1.template contract<std::array{-1, 1, -2, -3, 2, -4}, std::array{1, 2, -5, -6, -7}, 4>(t);
auto C4T3 = C1.template contract<std::array{1, -1}, std::array{-2, 1, -3, -4}, 1>(T1.adjoint().eval());
auto C4T3Ad = C4T3.template contract<std::array{-1, -2, -3, 1}, std::array{-4, -5, -6, 1, -7}, 3>(tdag.twist(3));
auto left_half = T4C1T1A.template contract<std::array{1, 2, -1, 3, -2, 4, -3}, std::array{1, -4, 4, 2, 3, -5, -6}, 3>(C4T3Ad);
// return left_half.coeff(0, 0, 0);
auto T1C2 = T1.template contract<std::array{-1, 1, -2, -3}, std::array{1, -4}, 3>(C1.adjoint().eval());
auto T1C2T2 = T1C2.template contract<std::array{-1, -2, -3, 1}, std::array{1, -4, -5, -6}, 3>(T1);
auto AT1C2T2 = t.adjoint().eval().twist(1).template contract<std::array{-3, -1, 1, 2, -2}, std::array{-4, 1, -5, -6, 2, -7}, 3>(T1C2T2);
auto T3C3 = T1.template contract<std::array{1, -1, -2, -3}, std::array{-4, 1}, 3>(C1.adjoint().eval());
auto T3C3Ad = T3C3.template contract<std::array{-1, -2, 1, -3}, std::array{-4, -5, -6, 1, -7}, 3>(t);
auto right_half = AT1C2T2.template contract<std::array{-1, 1, -2, -3, 2, 3, 4}, std::array{-4, 1, 3, -5, 2, 4, -6}, 3>(T3C3Ad);
auto rho_h = left_half.template contract<std::array{1, 2, -3, 3, 4, -1}, std::array{2, -4, 1, 3, 4, -2}, 2>(right_half);
auto Id2 = Xped::Tensor<Scalar, 2, 2, Symmetry, false>::Identity(rho_h.uncoupledCodomain(), rho_h.uncoupledDomain(), rho_h.world());
auto norm = rho_h.template contract<std::array{1, 2, 3, 4}, std::array{3, 4, 1, 2}, 0>(Id2.twist(0).twist(1)).trace();
rho_h = rho_h * (1. / norm);
// return tmp.coeff(tmp.sector().size() - 1, 0, 0);
return rho_h.trace();
// return tmp.coeff(0, 0, 0);
return t.template permute<-1, 3, 1, 2, 0>(Xped::Bool<ENABLE_AD>{}).coeff(0, 0, 0);
};
Xped::internal::check_ad_vs_fd_small<double, Symmetry>(f, SU2_BASIS_SIZE, test_world);
// Xped::internal::check_ad_vs_fd_small<double, Symmetry>(f, SU2_BASIS_SIZE, test_world);
Xped::internal::check_ad_vs_fd<double, Symmetry>(f, SU2_BASIS_SIZE, test_world);
}
SUBCASE("U1")
{
Expand Down

0 comments on commit a673fcc

Please sign in to comment.