diff --git a/src/treetensornetworks/projttns/abstractprojttn.jl b/src/treetensornetworks/projttns/abstractprojttn.jl index c28c739b..0a9c162c 100644 --- a/src/treetensornetworks/projttns/abstractprojttn.jl +++ b/src/treetensornetworks/projttns/abstractprojttn.jl @@ -134,9 +134,9 @@ function position( # shift position P = shift_position(P, pos) # remove internal edges (out of place) - ie=internal_edges(P) - newenvskeys=filter(!in(ie),keys(P.environments)) - P=ProjTTN(pos,P.H,getindices(P.environments,newenvskeys)) + ie = internal_edges(P) + newenvskeys = filter(!in(ie), keys(P.environments)) + P = ProjTTN(pos, P.H, getindices(P.environments, newenvskeys)) # make all environments surrounding new position for e in incident_edges(P) make_environment!(P, psi, e) diff --git a/test/test_treetensornetworks/test_position.jl b/test/test_treetensornetworks/test_position.jl index 1ba6371d..d5d0475d 100644 --- a/test/test_treetensornetworks/test_position.jl +++ b/test/test_treetensornetworks/test_position.jl @@ -4,40 +4,40 @@ using ITensorNetworks: position using Test @testset "ProjTTN position copy-safe" begin - # make a nontrivial TTN state and TTN operator - - auto_fermion_enabled = ITensors.using_auto_fermion() - use_qns = true - cutoff = 1e-12 + # make a nontrivial TTN state and TTN operator - tooth_lengths = fill(2, 3) - c = named_comb_tree(tooth_lengths) - if use_qns # test whether autofermion breaks things when using non-fermionic QNs - ITensors.enable_auto_fermion() - else # when using no QNs, autofermion breaks # ToDo reference Issue in ITensors - ITensors.disable_auto_fermion() - end - s = siteinds("S=1/2", c; conserve_qns=use_qns) + auto_fermion_enabled = ITensors.using_auto_fermion() + use_qns = true + cutoff = 1e-12 - os = ITensorNetworks.heisenberg(c) + tooth_lengths = fill(2, 3) + c = named_comb_tree(tooth_lengths) + if use_qns # test whether autofermion breaks things when using non-fermionic QNs + ITensors.enable_auto_fermion() + else # when using no QNs, autofermion breaks # ToDo reference Issue in ITensors + ITensors.disable_auto_fermion() + end + s = siteinds("S=1/2", c; conserve_qns=use_qns) - H = TTN(os, s) + os = ITensorNetworks.heisenberg(c) - d = Dict() - for (i, v) in enumerate(vertices(s)) - d[v] = isodd(i) ? "Up" : "Dn" - end - states = v -> d[v] - psi = TTN(s, states) + H = TTN(os, s) - # actual test, verifies that position is copy safe - vs= vertices(s) - PH0 = ProjTTN(H) - PH0 = position(PH0, psi, [vs[2],]) - PH=copy(PH0) - PH=position(PH,psi,[vs[2],vs[5]]) - @test keys(PH.environments)!=keys(PH0.environments) - if !auto_fermion_enabled - ITensors.disable_auto_fermion() - end -end \ No newline at end of file + d = Dict() + for (i, v) in enumerate(vertices(s)) + d[v] = isodd(i) ? "Up" : "Dn" + end + states = v -> d[v] + psi = TTN(s, states) + + # actual test, verifies that position is copy safe + vs = vertices(s) + PH0 = ProjTTN(H) + PH0 = position(PH0, psi, [vs[2]]) + PH = copy(PH0) + PH = position(PH, psi, [vs[2], vs[5]]) + @test keys(PH.environments) != keys(PH0.environments) + if !auto_fermion_enabled + ITensors.disable_auto_fermion() + end +end