From b52e27443ab935097342159615ef086ecb6c73cd Mon Sep 17 00:00:00 2001 From: Yue Zhengyuan Date: Mon, 7 Jul 2025 16:03:23 +0800 Subject: [PATCH 1/3] Fix correlator for fermionic PEPS --- src/algorithms/correlators.jl | 2 ++ test/runtests.jl | 3 +++ test/utility/correlator.jl | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 test/utility/correlator.jl diff --git a/src/algorithms/correlators.jl b/src/algorithms/correlators.jl index 76d32a37e..0e6a07aae 100644 --- a/src/algorithms/correlators.jl +++ b/src/algorithms/correlators.jl @@ -38,6 +38,7 @@ function correlator_horizontal( ) T = TransferMatrix(Atop, sandwich, _dag(Abot)) Vo = Vo * T + twistdual!(T.below, 2:numout(T.below)) Vn = Vn * T i += CartesianIndex(0, 1) end @@ -53,6 +54,7 @@ function correlator_horizontal( ) T = TransferMatrix(Atop, sandwich, _dag(Abot)) Vo = Vo * T + twistdual!(T.below, 2:numout(T.below)) Vn = Vn * T i += CartesianIndex(0, 1) diff --git a/test/runtests.jl b/test/runtests.jl index 787964a9b..4f5f9ea56 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -84,6 +84,9 @@ end @time @safetestset "Rotation of InfiniteWeightPEPS" begin include("utility/iwpeps_rotation.jl") end + @time @safetestset "Correlators" begin + include("utility/correlator.jl") + end end if GROUP == "ALL" || GROUP == "EXAMPLES" @time @safetestset "Transverse Field Ising model" begin diff --git a/test/utility/correlator.jl b/test/utility/correlator.jl new file mode 100644 index 000000000..1f6baea96 --- /dev/null +++ b/test/utility/correlator.jl @@ -0,0 +1,28 @@ +using Test +using Random +using TensorKit +using PEPSKit +import MPSKitModels: TJOperators as tJ + +Pspace = tJ.tj_space(Trivial, Trivial) +Vspace = Vect[FermionParity](0 => 2, 1 => 2) +Espace = Vect[FermionParity](0 => 3, 1 => 3) +Random.seed!(100) +peps = InfinitePEPS(rand, ComplexF64, Pspace, Vspace; unitcell=(2, 2)); +env = CTMRGEnv(rand, ComplexF64, peps, Espace); +lattice = collect(space(t, 1) for t in peps.A) + +site0 = CartesianIndex(1, 1) +maxsep = 6 +site1s = collect(site0 + CartesianIndex(0, i) for i in 1:maxsep) + +op = tJ.S_exchange(ComplexF64, Trivial, Trivial); + +vals1 = correlator(peps, op, site0, site1s, env) +vals2 = collect( + begin + O = LocalOperator(lattice, (site0, site1) => op) + val = expectation_value(peps, O, env) + end for site1 in site1s +) +@test vals1 ≈ vals2 From d59b405bb7601b3e32d3ff29d4e15eef2021db9e Mon Sep 17 00:00:00 2001 From: Yue Zhengyuan Date: Mon, 7 Jul 2025 16:32:41 +0800 Subject: [PATCH 2/3] Fix formatting --- test/utility/correlator.jl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/utility/correlator.jl b/test/utility/correlator.jl index 1f6baea96..ace26424d 100644 --- a/test/utility/correlator.jl +++ b/test/utility/correlator.jl @@ -19,10 +19,8 @@ site1s = collect(site0 + CartesianIndex(0, i) for i in 1:maxsep) op = tJ.S_exchange(ComplexF64, Trivial, Trivial); vals1 = correlator(peps, op, site0, site1s, env) -vals2 = collect( - begin - O = LocalOperator(lattice, (site0, site1) => op) - val = expectation_value(peps, O, env) - end for site1 in site1s -) +vals2 = collect(begin + O = LocalOperator(lattice, (site0, site1) => op) + val = expectation_value(peps, O, env) +end for site1 in site1s) @test vals1 ≈ vals2 From 795ee6e0f2b5f4ccb6affd6809b8fda4e37069bb Mon Sep 17 00:00:00 2001 From: Yue Zhengyuan Date: Mon, 7 Jul 2025 17:04:33 +0800 Subject: [PATCH 3/3] Improve test coverage --- test/utility/correlator.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/utility/correlator.jl b/test/utility/correlator.jl index ace26424d..18943dfee 100644 --- a/test/utility/correlator.jl +++ b/test/utility/correlator.jl @@ -13,8 +13,8 @@ env = CTMRGEnv(rand, ComplexF64, peps, Espace); lattice = collect(space(t, 1) for t in peps.A) site0 = CartesianIndex(1, 1) -maxsep = 6 -site1s = collect(site0 + CartesianIndex(0, i) for i in 1:maxsep) +maxsep = 8 +site1s = collect(site0 + CartesianIndex(0, i) for i in 2:2:maxsep) op = tJ.S_exchange(ComplexF64, Trivial, Trivial);