From 59cbf791a180d2c529aee6faa7930e8d04560652 Mon Sep 17 00:00:00 2001 From: Benedikt Kloss Date: Fri, 2 Feb 2024 06:57:21 -0500 Subject: [PATCH] Fix DMRG variational apply test and type signature in type definition. --- src/treetensornetworks/projttns/projouterprodttn.jl | 4 +++- src/treetensornetworks/projttns/projttnsum.jl | 6 +++--- test/test_treetensornetworks/test_solvers/test_contract.jl | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/treetensornetworks/projttns/projouterprodttn.jl b/src/treetensornetworks/projttns/projouterprodttn.jl index 3052e0bd..27f532e6 100644 --- a/src/treetensornetworks/projttns/projouterprodttn.jl +++ b/src/treetensornetworks/projttns/projouterprodttn.jl @@ -106,6 +106,8 @@ function contract_ket(P::ProjOuterProdTTN, v::ITensor) return v end +# ToDo: debug this, not yet working +# probably function contract(P::ProjOuterProdTTN, x::ITensor) - return conj(contract_ket(P, x)) * contract_ket(P, ITensor(true)) + return conj(contract_ket(P, dag(x))) * contract_ket(P, ITensor(true)) end diff --git a/src/treetensornetworks/projttns/projttnsum.jl b/src/treetensornetworks/projttns/projttnsum.jl index cd1cdf72..31eed8f5 100644 --- a/src/treetensornetworks/projttns/projttnsum.jl +++ b/src/treetensornetworks/projttns/projttnsum.jl @@ -2,9 +2,9 @@ ProjTTNSum """ struct ProjTTNSum{V} <: AbstractProjTTN{V} - terms::Vector{AbstractProjTTN{V}} - function ProjTTNSum(terms::Vector{<:AbstractProjTTN}) - return new{eltype(terms)}(terms) + terms::Vector{T} where {T<:AbstractProjTTN{V}} + function ProjTTNSum(terms::Vector{T}) where {V,T<:AbstractProjTTN{V}} + return new{V}(terms) end end diff --git a/test/test_treetensornetworks/test_solvers/test_contract.jl b/test/test_treetensornetworks/test_solvers/test_contract.jl index 46eadf11..4be8a574 100644 --- a/test/test_treetensornetworks/test_solvers/test_contract.jl +++ b/test/test_treetensornetworks/test_solvers/test_contract.jl @@ -24,6 +24,10 @@ using Test # Test basic usage with default parameters Hpsi = apply(H, psi; alg="fit", init=psi, nsweeps=1) @test inner(psi, Hpsi) ≈ inner(psi', H, psi) atol = 1E-5 + # Test variational compression via DMRG + Hfit = ProjOuterProdTTN(psi', H) + Hpsi_via_dmrg = dmrg(Hfit, psi; updater_kwargs=(; which_eigval=:LR,), nsweeps=1) + @test abs(inner(Hpsi_via_dmrg, Hpsi / norm(Hpsi))) ≈ 1 atol = 1E-4 # Test basic usage for use with multiple ProjOuterProdTTN with default parameters # BLAS.axpy-like test