From a763414d5fb7b9f0ac2c4afb89ec477683719d12 Mon Sep 17 00:00:00 2001 From: Benedikt Kloss Date: Wed, 6 Mar 2024 15:55:08 -0500 Subject: [PATCH 1/3] Make internal vertices without siteindices compare equal in `hascommoninds`. --- src/abstractitensornetwork.jl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/abstractitensornetwork.jl b/src/abstractitensornetwork.jl index 6905694b..8e7b40c0 100644 --- a/src/abstractitensornetwork.jl +++ b/src/abstractitensornetwork.jl @@ -798,7 +798,11 @@ function hascommoninds( ::typeof(siteinds), A::AbstractITensorNetwork{V}, B::AbstractITensorNetwork{V} ) where {V} for v in vertices(A) - !hascommoninds(siteinds(A, v), siteinds(B, v)) && return false + if isempty(siteinds(A, v)) + !isempty(siteinds(B, v)) && return false + else + !hascommoninds(siteinds(A, v), siteinds(B, v)) && return false + end end return true end @@ -815,9 +819,13 @@ function check_hascommoninds( ) end for v in vertices(A) - !hascommoninds(siteinds(A, v), siteinds(B, v)) && error( - "$(typeof(A)) A and $(typeof(B)) B must share site indices. On vertex $v, A has site indices $(siteinds(A, v)) while B has site indices $(siteinds(B, v)).", - ) + if isempty(siteinds(A, v)) + !(isempty(siteinds(B, v))) && return false + else + !hascommoninds(siteinds(A, v), siteinds(B, v)) && error( + "$(typeof(A)) A and $(typeof(B)) B must share site indices. On vertex $v, A has site indices $(siteinds(A, v)) while B has site indices $(siteinds(B, v)).", + ) + end end return nothing end From e3d4793ddd2f99ceb1bfdce4960cd73b2ceb18d5 Mon Sep 17 00:00:00 2001 From: Benedikt Kloss Date: Wed, 6 Mar 2024 18:48:11 -0500 Subject: [PATCH 2/3] Add test. --- test/test_opsum_to_ttn.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/test_opsum_to_ttn.jl b/test/test_opsum_to_ttn.jl index 810d7f03..efdd2bd4 100644 --- a/test/test_opsum_to_ttn.jl +++ b/test/test_opsum_to_ttn.jl @@ -247,7 +247,6 @@ end Tttno = contract(Hsvd) end @test Tttno ≈ Tmpo rtol = 1e-6 - Hsvd_lr = TTN( Hlr, is_missing_site; root_vertex=root_vertex, algorithm="svd", cutoff=1e-10 ) @@ -257,6 +256,10 @@ end Tmpo_lr = contract(Hsvd_lr) end @test Tttno_lr ≈ Tmpo_lr rtol = 1e-6 + # ToDo: move to a more appropriate file, since this is not related to OpSum to TTN conversion + # test whether Hamiltonian contracts with itself (used to error due to missing siteindices) + @test isa(inner(Hsvd, Hsvd), Number) end end end +return nothing From 576bed31501e4af731d943a894845cba5146afab Mon Sep 17 00:00:00 2001 From: Benedikt Kloss Date: Wed, 6 Mar 2024 18:48:32 -0500 Subject: [PATCH 3/3] Add error message. --- src/abstractitensornetwork.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/abstractitensornetwork.jl b/src/abstractitensornetwork.jl index 8e7b40c0..10fc6a1d 100644 --- a/src/abstractitensornetwork.jl +++ b/src/abstractitensornetwork.jl @@ -820,7 +820,9 @@ function check_hascommoninds( end for v in vertices(A) if isempty(siteinds(A, v)) - !(isempty(siteinds(B, v))) && return false + !(isempty(siteinds(B, v))) && error( + "$(typeof(A)) A and $(typeof(B)) B must share site indices. On vertex $v, A has no site indices while B has site indices $(siteinds(B, v)).", + ) else !hascommoninds(siteinds(A, v), siteinds(B, v)) && error( "$(typeof(A)) A and $(typeof(B)) B must share site indices. On vertex $v, A has site indices $(siteinds(A, v)) while B has site indices $(siteinds(B, v)).",