From eef91d6c9927562a8e023e167e3b16e876089858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gauth=C3=A9?= Date: Fri, 15 Aug 2025 19:03:05 -0400 Subject: [PATCH 1/8] avoid @autoopt --- .../contractions/ctmrg_contractions.jl | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/algorithms/contractions/ctmrg_contractions.jl b/src/algorithms/contractions/ctmrg_contractions.jl index 1d794e5cc..befe4c48b 100644 --- a/src/algorithms/contractions/ctmrg_contractions.jl +++ b/src/algorithms/contractions/ctmrg_contractions.jl @@ -54,8 +54,11 @@ function enlarge_northwest_corner( E_west::CTMRG_PF_EdgeTensor, C_northwest::CTMRGCornerTensor, E_north::CTMRG_PF_EdgeTensor, A::PFTensor, ) - return @autoopt @tensor corner[χ_S D_S; χ_E D_E] := - E_west[χ_S D1; χ1] * C_northwest[χ1; χ2] * E_north[χ2 D2; χ_E] * A[D1 D_S; D2 D_E] + return @tensor begin + EC[χ_S DW; χ2] := E_west[χ_S DW; χ1] * C_northwest[χ1; χ2] + ECE[χ_S χ_E; DW DN] := EC[χ_S DW; χ2] * E_north[χ2 DN; χ_E] + corner[χ_S D_S; χ_E D_E] := ECE[χ_S χ_E; DW DN] * A[DW D_S; DN D_E] + end end """ @@ -92,8 +95,11 @@ function enlarge_northeast_corner( E_north::CTMRG_PF_EdgeTensor, C_northeast::CTMRGCornerTensor, E_east::CTMRG_PF_EdgeTensor, A::PFTensor, ) - return @autoopt @tensor corner[χ_W D_W; χ_S D_S] := - E_north[χ_W D1; χ1] * C_northeast[χ1; χ2] * E_east[χ2 D2; χ_S] * A[D_W D_S; D1 D2] + return @tensor begin + EC[χ_W DN; χ2] := E_north[χ_W DN; χ1] * C_northeast[χ1; χ2] + ECE[χ_W χ_S; DN DE] := EC[χ_W DN; χ2] * E_east[χ2 DE; χ_S] + corner[χ_W D_W; χ_S D_S] := ECE[χ_W χ_S; DN DE] * A[D_W D_S; DN DE] + end end """ @@ -130,8 +136,11 @@ function enlarge_southeast_corner( E_east::CTMRG_PF_EdgeTensor, C_southeast::CTMRGCornerTensor, E_south::CTMRG_PF_EdgeTensor, A::PFTensor, ) - return @autoopt @tensor corner[χ_N D_N; χ_W D_W] := - E_east[χ_N D1; χ1] * C_southeast[χ1; χ2] * E_south[χ2 D2; χ_W] * A[D_W D2; D_N D1] + return @tensor begin + EC[χ_N D1; χ2] := E_east[χ_N D1; χ1] * C_southeast[χ1; χ2] + ECE[χ_N χ_W; D1 D2] := EC[χ_N D1; χ2] * E_south[χ2 D2; χ_W] + corner[χ_N D_N; χ_W D_W] := ECE[χ_N χ_W; D1 D2] * A[D_W D2; D_N D1] + end end """ @@ -168,8 +177,11 @@ function enlarge_southwest_corner( E_south::CTMRG_PF_EdgeTensor, C_southwest::CTMRGCornerTensor, E_west::CTMRG_PF_EdgeTensor, A::PFTensor, ) - return @autoopt @tensor corner[χ_E D_E; χ_N D_N] := - E_south[χ_E D1; χ1] * C_southwest[χ1; χ2] * E_west[χ2 D2; χ_N] * A[D2 D1; D_N D_E] + return @tensor begin + EC[χ_E D1; χ2] := E_south[χ_E D1; χ1] * C_southwest[χ1; χ2] + ECE[χ_E χ_N; D2 D1] := EC[χ_E D1; χ2] * E_west[χ2 D2; χ_N] + corner[χ_E D_E; χ_N D_N] := ECE[χ_E χ_N; D2 D1] * A[D2 D1; D_N D_E] + end end # Projector contractions @@ -1067,8 +1079,11 @@ function renormalize_west_edge( end end function renormalize_west_edge(E_west::CTMRG_PF_EdgeTensor, P_bottom, P_top, A::PFTensor) - return @autoopt @tensor edge[χ_S D_E; χ_N] := - E_west[χ1 D1; χ2] * A[D1 D5; D3 D_E] * P_bottom[χ2 D3; χ_N] * P_top[χ_S; χ1 D5] + return @tensor begin + PE[χ_S χNW; D_W D_S] := P_top[χ_S; χSW D_S] * E_west[χSW D_W; χNW] + PEA[χ_S D_E; χNW D_N] := PE[χ_S χNW; D_W D_S] * A[D_W D_S; D_N D_E] + edge[χ_S D_E; χ_N] := PEA[χ_S D_E; χNW D_N] * P_bottom[χNW D_N; χ_N] + end end # Gauge fixing contractions From 47922bdc59c7719cb4930199dda090afe5eadcb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gauth=C3=A9?= Date: Mon, 8 Sep 2025 18:24:40 -0400 Subject: [PATCH 2/8] optimize renomarlize_south_edge --- src/algorithms/contractions/ctmrg_contractions.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/algorithms/contractions/ctmrg_contractions.jl b/src/algorithms/contractions/ctmrg_contractions.jl index befe4c48b..83be26386 100644 --- a/src/algorithms/contractions/ctmrg_contractions.jl +++ b/src/algorithms/contractions/ctmrg_contractions.jl @@ -1024,6 +1024,16 @@ function renormalize_south_edge(E_south, P_left, P_right, A) return renormalize_west_edge(E_south, P_left, P_right, A_west) end +function renormalize_south_edge(E_south::CTMRG_PF_EdgeTensor, P_left, P_right, A::PFTensor) + # specialize to avoid extra permute on A when calling renormalize_west_edge + return @tensor begin + temp[χ_W D_W; χSW] := P_left[χSW D_W; χ_W] # impose χ_W as 1st leg + PE[χ_W χSE; D_W D_S] := temp[χ_W D_W; χSW] * E_south[χSE D_S; χSW] + PEA[χ_W D_N; χSE D_E] := PE[χ_W χSE; D_W D_S] * A[D_W D_S; D_N D_E] + edge[χ_E D_N; χ_W] := PEA[χ_W D_N; χSE D_E] * P_right[χ_E; χSE D_E] + end +end + """ renormalize_west_edge((row, col), env, P_top, P_bottom, network::InfiniteSquareNetwork{P}) renormalize_west_edge(E_west, P_top, P_bottom, A::P) From bc7b6dbe86f79af0cdadf858d017c78f762e3cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gauth=C3=A9?= Date: Mon, 8 Sep 2025 20:05:16 -0400 Subject: [PATCH 3/8] add space test --- test/ctmrg/partition_function.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/ctmrg/partition_function.jl b/test/ctmrg/partition_function.jl index a649da8a7..c4455abe1 100644 --- a/test/ctmrg/partition_function.jl +++ b/test/ctmrg/partition_function.jl @@ -5,6 +5,21 @@ using PEPSKit using TensorKit using QuadGK + +@testset "Check spaces in partition function CTMRG" begin + zA = randn(ℂ^6 ⊗ ℂ^8 ← ℂ^4 ⊗ ℂ^2) + zB = randn(ℂ^2 ⊗ ℂ^9 ← ℂ^5 ⊗ ℂ^6) + zC = randn(ℂ^7 ⊗ ℂ^4 ← ℂ^8 ⊗ ℂ^3) + zD = randn(ℂ^3 ⊗ ℂ^5 ← ℂ^9 ⊗ ℂ^7) + + Z = InfinitePartitionFunction([zA zB; zC zD]) + χenv = ℂ^12 + env0 = CTMRGEnv(Z, χenv) + env, = leading_boundary(env0, Z; alg = :simultaneous, maxiter = 3, projector_alg = :fullinfinite) + @test env isa CTMRGEnv +end + + ## Setup """ From 5d981ffaf9b8ad4a4041570e7934fa5edb6ac662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gauth=C3=A9?= Date: Thu, 11 Sep 2025 09:36:57 -0400 Subject: [PATCH 4/8] fix contractions --- .../contractions/ctmrg_contractions.jl | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/src/algorithms/contractions/ctmrg_contractions.jl b/src/algorithms/contractions/ctmrg_contractions.jl index 83be26386..200efcc5a 100644 --- a/src/algorithms/contractions/ctmrg_contractions.jl +++ b/src/algorithms/contractions/ctmrg_contractions.jl @@ -947,18 +947,28 @@ environment tensors. ``` """ function renormalize_north_edge( - (row, col), env::CTMRGEnv, P_left, P_right, network::InfiniteSquareNetwork + (row, col), env::CTMRGEnv, P_right, P_left, network::InfiniteSquareNetwork ) return renormalize_north_edge( env.edges[NORTH, _prev(row, end), col], - P_left[NORTH, row, col], - P_right[NORTH, row, _prev(col, end)], + P_right[NORTH, row, col], + P_left[NORTH, row, _prev(col, end)], network[row, col], # so here it's fine ) end -function renormalize_north_edge(E_north, P_left, P_right, A) +function renormalize_north_edge(E_north, P_right, P_left, A) A_west = _rotl90_localsandwich(A) - return renormalize_west_edge(E_north, P_left, P_right, A_west) + return renormalize_west_edge(E_north, P_right, P_left, A_west) +end +# specialize PartitionFunction to avoid permute(A) +function renormalize_north_edge(E_north::CTMRG_PF_EdgeTensor, P_right, P_left, A::PFTensor) + return @tensor begin + temp = permute(E_north, ((2, 1), (3,))) # impose D_N as 1st leg + PE[D_N D_E; χNW χ_E] := temp[D_N χNW; χNE] * P_right[χNE D_E; χ_E] + PEA[D_W χNW; D_S χ_E] := A[D_W D_S; D_N D_E] * PE[D_N D_E; χNW χ_E] + P_leftp = permute(P_left, ((1,), (3, 2))) + edge[χ_W D_S; χ_E] := P_leftp[χ_W; D_W χNW] * PEA[D_W χNW; D_S χ_E] + end end """ @@ -992,6 +1002,15 @@ function renormalize_east_edge(E_east, P_bottom, P_top, A) A_west = _rot180_localsandwich(A) return renormalize_west_edge(E_east, P_bottom, P_top, A_west) end +# specialize PartitionFunction to avoid permute(A) +function renormalize_east_edge(E_east::CTMRG_PF_EdgeTensor, P_bottom, P_top, A::PFTensor) + return @tensor begin + temp = permute(P_top, ((3, 1), (2,))) # impose D_N as 1st leg + PE[D_N D_E; χN χSE] := temp[D_N χN; χNE] * E_east[χNE D_E; χSE] + PEA[D_W χN; χSE D_S] := A[D_W D_S; D_N D_E] * PE[D_N D_E; χN χSE] + edge[χ_N D_W; χ_S] := PEA[D_W χ_N; χSE D_S] * P_bottom[χSE D_S; χ_S] + end +end """ renormalize_south_edge((row, col), env, P_left, P_right, network::InfiniteSquareNetwork{P}) @@ -1052,12 +1071,12 @@ environment tensors. ``` """ function renormalize_west_edge( # For simultaneous CTMRG scheme - (row, col), env::CTMRGEnv, P_bottom::Array{Pb, 3}, P_top::Array{Pt, 3}, network::InfiniteSquareNetwork, + (row, col), env::CTMRGEnv, P_top::Array{Pt, 3}, P_bottom::Array{Pb, 3}, network::InfiniteSquareNetwork, ) where {Pt, Pb} return renormalize_west_edge( env.edges[WEST, row, _prev(col, end)], - P_bottom[WEST, row, col], - P_top[WEST, _next(row, end), col], + P_top[WEST, row, col], + P_bottom[WEST, _next(row, end), col], network[row, col], ) end @@ -1072,12 +1091,12 @@ function renormalize_west_edge( # For sequential CTMRG scheme ) end function renormalize_west_edge( - E_west::CTMRG_PEPS_EdgeTensor, P_bottom, P_top, A::PEPSSandwich + E_west::CTMRG_PEPS_EdgeTensor, P_top, P_bottom, A::PEPSSandwich ) - # starting with P_top to save one permute in the end + # starting with P_bottom to save one permute in the end return @tensor begin # already putting χE in front here to make next permute cheaper - PE[χS χNW DSb DWb; DSt DWt] := P_top[χS; χSW DSt DSb] * E_west[χSW DWt DWb; χNW] + PE[χS χNW DSb DWb; DSt DWt] := P_bottom[χS; χSW DSt DSb] * E_west[χSW DWt DWb; χNW] PEket[χS χNW DNt DEt; DSb DWb d] := PE[χS χNW DSb DWb; DSt DWt] * ket(A)[d; DNt DEt DSt DWt] @@ -1085,14 +1104,14 @@ function renormalize_west_edge( corner[χS DEt DEb; χNW DNt DNb] := PEket[χS χNW DNt DEt; DSb DWb d] * conj(bra(A)[d; DNb DEb DSb DWb]) - edge[χS DEt DEb; χN] := corner[χS DEt DEb; χNW DNt DNb] * P_bottom[χNW DNt DNb; χN] + edge[χS DEt DEb; χN] := corner[χS DEt DEb; χNW DNt DNb] * P_top[χNW DNt DNb; χN] end end -function renormalize_west_edge(E_west::CTMRG_PF_EdgeTensor, P_bottom, P_top, A::PFTensor) +function renormalize_west_edge(E_west::CTMRG_PF_EdgeTensor, P_top, P_bottom, A::PFTensor) return @tensor begin - PE[χ_S χNW; D_W D_S] := P_top[χ_S; χSW D_S] * E_west[χSW D_W; χNW] + PE[χ_S χNW; D_W D_S] := P_bottom[χ_S; χSW D_S] * E_west[χSW D_W; χNW] PEA[χ_S D_E; χNW D_N] := PE[χ_S χNW; D_W D_S] * A[D_W D_S; D_N D_E] - edge[χ_S D_E; χ_N] := PEA[χ_S D_E; χNW D_N] * P_bottom[χNW D_N; χ_N] + edge[χ_S D_E; χ_N] := PEA[χ_S D_E; χNW D_N] * P_top[χNW D_N; χ_N] end end From 4026327f09e535b16886bedcbae1ea03b2542eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gauth=C3=A9?= Date: Thu, 11 Sep 2025 11:45:04 -0400 Subject: [PATCH 5/8] use permute --- src/algorithms/contractions/ctmrg_contractions.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/algorithms/contractions/ctmrg_contractions.jl b/src/algorithms/contractions/ctmrg_contractions.jl index 200efcc5a..4c16c6aff 100644 --- a/src/algorithms/contractions/ctmrg_contractions.jl +++ b/src/algorithms/contractions/ctmrg_contractions.jl @@ -1046,8 +1046,8 @@ end function renormalize_south_edge(E_south::CTMRG_PF_EdgeTensor, P_left, P_right, A::PFTensor) # specialize to avoid extra permute on A when calling renormalize_west_edge return @tensor begin - temp[χ_W D_W; χSW] := P_left[χSW D_W; χ_W] # impose χ_W as 1st leg - PE[χ_W χSE; D_W D_S] := temp[χ_W D_W; χSW] * E_south[χSE D_S; χSW] + P_leftp = permute(P_leftp, ((3, 2), (1,))) # impose χ_W as 1st leg + PE[χ_W χSE; D_W D_S] := P_leftp[χ_W D_W; χSW] * E_south[χSE D_S; χSW] PEA[χ_W D_N; χSE D_E] := PE[χ_W χSE; D_W D_S] * A[D_W D_S; D_N D_E] edge[χ_E D_N; χ_W] := PEA[χ_W D_N; χSE D_E] * P_right[χ_E; χSE D_E] end From a1c4a37bcfeb62c23818c07000d7e140fcb263bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gauth=C3=A9?= Date: Thu, 11 Sep 2025 11:50:48 -0400 Subject: [PATCH 6/8] debug --- src/algorithms/contractions/ctmrg_contractions.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/contractions/ctmrg_contractions.jl b/src/algorithms/contractions/ctmrg_contractions.jl index 4c16c6aff..ae15a7360 100644 --- a/src/algorithms/contractions/ctmrg_contractions.jl +++ b/src/algorithms/contractions/ctmrg_contractions.jl @@ -1046,7 +1046,7 @@ end function renormalize_south_edge(E_south::CTMRG_PF_EdgeTensor, P_left, P_right, A::PFTensor) # specialize to avoid extra permute on A when calling renormalize_west_edge return @tensor begin - P_leftp = permute(P_leftp, ((3, 2), (1,))) # impose χ_W as 1st leg + P_leftp = permute(P_left, ((3, 2), (1,))) # impose χ_W as 1st leg PE[χ_W χSE; D_W D_S] := P_leftp[χ_W D_W; χSW] * E_south[χSE D_S; χSW] PEA[χ_W D_N; χSE D_E] := PE[χ_W χSE; D_W D_S] * A[D_W D_S; D_N D_E] edge[χ_E D_N; χ_W] := PEA[χ_W D_N; χSE D_E] * P_right[χ_E; χSE D_E] From a9f487e1c8b14e33441369fdffa04b3f64f58e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gauth=C3=A9?= Date: Thu, 11 Sep 2025 17:51:45 -0400 Subject: [PATCH 7/8] do not permute A in enlarge_northeast_corner --- src/algorithms/contractions/ctmrg_contractions.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/algorithms/contractions/ctmrg_contractions.jl b/src/algorithms/contractions/ctmrg_contractions.jl index ae15a7360..e645009c2 100644 --- a/src/algorithms/contractions/ctmrg_contractions.jl +++ b/src/algorithms/contractions/ctmrg_contractions.jl @@ -96,9 +96,9 @@ function enlarge_northeast_corner( E_east::CTMRG_PF_EdgeTensor, A::PFTensor, ) return @tensor begin - EC[χ_W DN; χ2] := E_north[χ_W DN; χ1] * C_northeast[χ1; χ2] - ECE[χ_W χ_S; DN DE] := EC[χ_W DN; χ2] * E_east[χ2 DE; χ_S] - corner[χ_W D_W; χ_S D_S] := ECE[χ_W χ_S; DN DE] * A[D_W D_S; DN DE] + EC[DN χ_W; χ2] := E_north[χ_W DN; χ1] * C_northeast[χ1; χ2] + ECE[DN DE; χ_S χ_W] := EC[DN χ_W; χ2] * E_east[χ2 DE; χ_S] + corner[χ_W D_W; χ_S D_S] := A[D_W D_S; DN DE] * ECE[DN DE; χ_S χ_W] end end From 7c2d7bd6be7753074e2b2b9e383bbe90c117660c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gauth=C3=A9?= Date: Thu, 11 Sep 2025 19:10:17 -0400 Subject: [PATCH 8/8] runic --- src/algorithms/contractions/ctmrg_contractions.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/contractions/ctmrg_contractions.jl b/src/algorithms/contractions/ctmrg_contractions.jl index e645009c2..651d3a378 100644 --- a/src/algorithms/contractions/ctmrg_contractions.jl +++ b/src/algorithms/contractions/ctmrg_contractions.jl @@ -98,7 +98,7 @@ function enlarge_northeast_corner( return @tensor begin EC[DN χ_W; χ2] := E_north[χ_W DN; χ1] * C_northeast[χ1; χ2] ECE[DN DE; χ_S χ_W] := EC[DN χ_W; χ2] * E_east[χ2 DE; χ_S] - corner[χ_W D_W; χ_S D_S] := A[D_W D_S; DN DE] * ECE[DN DE; χ_S χ_W] + corner[χ_W D_W; χ_S D_S] := A[D_W D_S; DN DE] * ECE[DN DE; χ_S χ_W] end end