Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Neighborhood Tensor Update (aka Cluster Update) #121

Draft
wants to merge 69 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
1586485
Add full update
Yue-Zhengyuan Dec 12, 2024
9168e05
Merge remote-tracking branch 'upstream/master' into fullupdate
Yue-Zhengyuan Dec 13, 2024
38847a5
Adapt FU to updated CTMRG
Yue-Zhengyuan Dec 13, 2024
99f0bbe
Minor fix
Yue-Zhengyuan Dec 16, 2024
cf59cc4
Fix OhMyThreads precompilation warning
pbrehmer Dec 17, 2024
fa53699
Fix FullInfiniteProjector
Yue-Zhengyuan Dec 19, 2024
4bb3fb0
Fix simultaneous CTMRG pre-allocation
Yue-Zhengyuan Dec 19, 2024
cba8a63
Merge remote-tracking branch 'upstream/master' into fullupdate
Yue-Zhengyuan Dec 20, 2024
304d1f6
Implement fallback SVD in simple update
Yue-Zhengyuan Dec 20, 2024
81c529d
Fix formatting
Yue-Zhengyuan Dec 21, 2024
2945be4
Merge remote-tracking branch 'upstream/master' into fullupdate
Yue-Zhengyuan Dec 22, 2024
b3137ae
Remove DS_Store
Yue-Zhengyuan Dec 25, 2024
233701b
Minor variable renames
Yue-Zhengyuan Dec 25, 2024
70c51b5
Restore sdiag_inv_sqrt for possibly better stability
Yue-Zhengyuan Dec 25, 2024
653fbf4
Refactoring FU ALS cost function
Yue-Zhengyuan Dec 25, 2024
5a8ab05
Fix formatting
Yue-Zhengyuan Dec 29, 2024
9c08d22
refactoring FU
Yue-Zhengyuan Jan 7, 2025
4ad64d5
Implement NTU-NN bond environment
Yue-Zhengyuan Jan 8, 2025
e94dfd6
Add ALS optimization for NTU
Yue-Zhengyuan Jan 9, 2025
bcf547a
Refactor FU
Yue-Zhengyuan Jan 10, 2025
b48a48d
Fix FU regression
Yue-Zhengyuan Jan 10, 2025
e10d87d
Implement main function of NTU
Yue-Zhengyuan Jan 10, 2025
4d64d8c
Add NNN bondenv for NTU
Yue-Zhengyuan Jan 11, 2025
ae06c25
Cleanup ntutools with metaprogramming
Yue-Zhengyuan Jan 11, 2025
4349927
Add NNN+ bondenv for NTU
Yue-Zhengyuan Jan 11, 2025
21e4a71
Minor fix of docstring
Yue-Zhengyuan Jan 13, 2025
3f7841f
Add Heisenberg NTU test
Yue-Zhengyuan Jan 15, 2025
dbd6f4f
Remove sdiag_inv_sqrt again; normalize env_ctm
Yue-Zhengyuan Jan 15, 2025
15b13be
Merge remote-tracking branch 'upstream/master' into ntu
Yue-Zhengyuan Jan 15, 2025
89efa3a
Add dual check for bondenvs; fix fermion bondenv
Yue-Zhengyuan Jan 16, 2025
e8d233a
Update env_ctm construction
Yue-Zhengyuan Jan 17, 2025
67bd6ed
Refactor truncation_scheme for time evolution algorithms
Yue-Zhengyuan Jan 17, 2025
aac5625
Use `twist` to handle dual spaces
Yue-Zhengyuan Jan 20, 2025
e2bfd25
Add Full Environment Truncation (FET)
Yue-Zhengyuan Jan 21, 2025
5194f56
Replace ALS by FET in FU and NTU
Yue-Zhengyuan Jan 21, 2025
56c428b
Minor fix of FET for fermions to keep `s` positive
Yue-Zhengyuan Jan 21, 2025
591e9a2
Update FulEnvTruncate
Yue-Zhengyuan Jan 22, 2025
a795eee
Add test on bondenv_ntu
Yue-Zhengyuan Jan 22, 2025
ef2bedc
Add weights to NTU
Yue-Zhengyuan Jan 22, 2025
e0bae56
Fix NTU test
Yue-Zhengyuan Jan 23, 2025
3b463c2
Improve FET log format
Yue-Zhengyuan Jan 23, 2025
e4836a3
Add Heisenberg SU-NTU example
Yue-Zhengyuan Jan 23, 2025
614d430
Add Heisenberg SU-FU example
Yue-Zhengyuan Jan 23, 2025
1d37fcd
Add bipartite support to NTU
Yue-Zhengyuan Jan 24, 2025
7bf5af8
Minor fixes
Yue-Zhengyuan Jan 24, 2025
800afd4
Refine error messages
Yue-Zhengyuan Jan 24, 2025
5fa79a1
Remove unnecessary assertion on bond matrix
Yue-Zhengyuan Jan 24, 2025
137045e
Add FET test
Yue-Zhengyuan Jan 25, 2025
7e43b87
Restore ALSTruncation
Yue-Zhengyuan Jan 25, 2025
11fc085
Allow FU/NTU to use FET/ALS
Yue-Zhengyuan Jan 25, 2025
865b175
Minor fix
Yue-Zhengyuan Jan 25, 2025
4d44901
Minor tweak of FU, NTU examples
Yue-Zhengyuan Jan 25, 2025
8e30759
Format fix
Yue-Zhengyuan Jan 25, 2025
6ad6d55
Show weight change in FU
Yue-Zhengyuan Jan 26, 2025
a0aa378
Excise full update
Yue-Zhengyuan Jan 26, 2025
392057a
Add tests for bond environment
Yue-Zhengyuan Jan 26, 2025
92b300a
Add tests for bond environment
Yue-Zhengyuan Jan 26, 2025
56cee0e
Modify GitHub tests
Yue-Zhengyuan Jan 26, 2025
a96b45c
Minor update of FU
Yue-Zhengyuan Jan 26, 2025
f2b3bf4
Rename variables
Yue-Zhengyuan Jan 26, 2025
0e68cec
Rename variables
Yue-Zhengyuan Jan 26, 2025
d0ee55d
Update FU example main function
Yue-Zhengyuan Jan 29, 2025
1db84d7
Clean up Heisenberg examples
Yue-Zhengyuan Jan 30, 2025
d7bf104
Merge remote-tracking branch 'upstream/master' into ntu-weight
Yue-Zhengyuan Jan 30, 2025
fd092d7
Adapt FU, NTU to latest package versions
Yue-Zhengyuan Jan 30, 2025
3a437d7
Merge branch 'ntu-weight' into ntu-dev
Yue-Zhengyuan Jan 30, 2025
eb61d04
Fix tests
Yue-Zhengyuan Jan 31, 2025
c349441
Update SU, NTU with DiagonalTensorMap
Yue-Zhengyuan Feb 3, 2025
80824e3
Remove flip_svd
Yue-Zhengyuan Feb 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- boundarymps
- examples
- utility
- bondenv
os:
- ubuntu-latest
- macOS-latest
Expand Down
61 changes: 61 additions & 0 deletions examples/heisenberg_evol/heis_tools.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@static if Sys.isapple()
using AppleAccelerate
end
using Test
using Printf
using Random
import Statistics: mean
using TensorKit
using PEPSKit

module MeasureHeis

export measure_heis

using TensorKit
import MPSKitModels: S_x, S_y, S_z, S_exchange
using PEPSKit

"""
Measure magnetization on each site
"""
function cal_mags(peps::InfinitePEPS, envs::CTMRGEnv)
N1, N2 = size(peps)
lattice = collect(space(t, 1) for t in peps.A)
# detect symmetry on physical axis
symm = sectortype(space(peps.A[1, 1]))
if symm == Trivial
Sas = real.([S_x(symm), im * S_y(symm), S_z(symm)])
elseif symm == U1Irrep
# only Sz preserves <Sz>
Sas = real.([S_z(symm)])
else
throw(ArgumentError("Unrecognized symmetry on physical axis"))
end
return [
collect(
expectation_value(
peps, LocalOperator(lattice, (CartesianIndex(r, c),) => Sa), envs
) for (r, c) in Iterators.product(1:N1, 1:N2)
) for Sa in Sas
]
end

"""
Measure physical quantities for Heisenberg model
"""
function measure_heis(peps::InfinitePEPS, H::LocalOperator, envs::CTMRGEnv)
results = Dict{String,Any}()
N1, N2 = size(peps)
results["e_site"] = costfun(peps, envs, H) / (N1 * N2)
results["mag"] = cal_mags(peps, envs)
results["mag_norm"] = collect(
norm([mags[r, c] for mags in results["mag"]]) for
(r, c) in Iterators.product(1:N1, 1:N2)
)
return results
end

end

import .MeasureHeis: measure_heis
29 changes: 29 additions & 0 deletions examples/heisenberg_evol/ntupdate.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
include("simpleupdate.jl")

# continue SU with NTU
dts = [1e-2, 5e-3]
maxiter = 2000
for dt in dts
alg = NTUpdate(;
dt,
maxiter,
tol=1e-8,
bondenv_alg=NTUEnvNN(),
opt_alg=FullEnvTruncation(; trscheme=trscheme_peps),
# opt_alg=ALSTruncation(; trscheme=trscheme_peps),
ctm_alg=SequentialCTMRG(;
tol=1e-7, verbosity=2, maxiter=30, trscheme=trscheme_envs
),
)
result = ntupdate(peps, envs, ham, alg, ctm_alg; bipartite=true)
global peps = result[1]
global envs = result[2]
end
# measure physical quantities with CTMRG
peps_ = InfinitePEPS(peps)
meas = measure_heis(peps_, ham, envs)
display(meas)
@info @sprintf("Energy = %.8f\n", meas["e_site"])
@info @sprintf("Staggered magnetization = %.8f\n", mean(meas["mag_norm"]))
@test isapprox(meas["e_site"], -0.66884; atol=1e-3)
@test isapprox(mean(meas["mag_norm"]), 0.34; atol=1e-2)
52 changes: 52 additions & 0 deletions examples/heisenberg_evol/simpleupdate.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
include("heis_tools.jl")

# benchmark data is from Phys. Rev. B 94, 035133 (2016)
Dbond, χenv, symm = 4, 16, Trivial
trscheme_peps = truncerr(1e-10) & truncdim(Dbond)
trscheme_envs = truncerr(1e-10) & truncdim(χenv)
N1, N2 = 2, 2
# Heisenberg model Hamiltonian
# (already only includes nearest neighbor terms)
ham = heisenberg_XYZ(ComplexF64, symm, InfiniteSquare(N1, N2); Jx=1.0, Jy=1.0, Jz=1.0)
# convert to real tensors
ham = LocalOperator(ham.lattice, Tuple(ind => real(op) for (ind, op) in ham.terms)...)

# random initialization of 2x2 iPEPS with weights and CTMRGEnv (using real numbers)
if symm == Trivial
Pspace = ℂ^2
Vspace = ℂ^Dbond
Espace = ℂ^χenv
elseif symm == U1Irrep
Pspace = ℂ[U1Irrep](1//2 => 1, -1//2 => 1)
Vspace = ℂ[U1Irrep](0 => Dbond ÷ 2, 1//2 => Dbond ÷ 4, -1//2 => Dbond ÷ 4)
Espace = ℂ[U1Irrep](0 => χenv ÷ 2, 1//2 => χenv ÷ 4, -1//2 => χenv ÷ 4)
else
error("Not implemented")
end
Random.seed!(0)
peps = InfiniteWeightPEPS(rand, Float64, Pspace, Vspace; unitcell=(N1, N2))
# normalize vertex tensors
for ind in CartesianIndices(peps.vertices)
peps.vertices[ind] /= norm(peps.vertices[ind], Inf)
end

# simple update
dts = [1e-2, 1e-3, 4e-4]
tols = [1e-6, 1e-8, 1e-8]
maxiter = 10000
for (dt, tol) in zip(dts, tols)
alg = SimpleUpdate(dt, tol, maxiter, trscheme_peps)
result = simpleupdate(peps, ham, alg; bipartite=true)
global peps = result[1]
end
# measure physical quantities with CTMRG
peps_ = InfinitePEPS(peps)
envs = CTMRGEnv(rand, Float64, peps_, Espace)
ctm_alg = SequentialCTMRG(; tol=1e-10, verbosity=2, trscheme=trscheme_envs)
envs = leading_boundary(envs, peps_, ctm_alg)
meas = measure_heis(peps_, ham, envs)
display(meas)
@info @sprintf("Energy = %.8f\n", meas["e_site"])
@info @sprintf("Staggered magnetization = %.8f\n", mean(meas["mag_norm"]))
@test isapprox(meas["e_site"], -0.6675; atol=1e-3)
@test isapprox(mean(meas["mag_norm"]), 0.3767; atol=1e-3)
14 changes: 7 additions & 7 deletions examples/hubbard_su.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ using PEPSKit
using TensorKit

# random initialization of 2x2 iPEPS with weights and CTMRGEnv (using real numbers)
Dcut, symm = 8, Trivial
N1, N2 = 2, 2
Dbond, symm = 8, Trivial
Nr, Nc = 2, 2
Random.seed!(10)
if symm == Trivial
Pspace = Vect[fℤ₂](0 => 2, 1 => 2)
Vspace = Vect[fℤ₂](0 => Dcut / 2, 1 => Dcut / 2)
Vspace = Vect[fℤ₂](0 => Dbond / 2, 1 => Dbond / 2)
else
error("Not implemented")
end
peps = InfiniteWeightPEPS(rand, Float64, Pspace, Vspace; unitcell=(N1, N2))
peps = InfiniteWeightPEPS(rand, Float64, Pspace, Vspace; unitcell=(Nr, Nc))

# normalize vertex tensors
for ind in CartesianIndices(peps.vertices)
Expand All @@ -22,14 +22,14 @@ end

# Hubbard model Hamiltonian at half-filling
t, U = 1, 6
ham = hubbard_model(Float64, Trivial, Trivial, InfiniteSquare(N1, N2); t, U, mu=U / 2)
ham = hubbard_model(Float64, Trivial, Trivial, InfiniteSquare(Nr, Nc); t, U, mu=U / 2)

# simple update
dts = [1e-2, 1e-3, 4e-4, 1e-4]
tols = [1e-6, 1e-8, 1e-8, 1e-8]
maxiter = 10000
for (n, (dt, tol)) in enumerate(zip(dts, tols))
trscheme = truncerr(1e-10) & truncdim(Dcut)
trscheme = truncerr(1e-10) & truncdim(Dbond)
alg = SimpleUpdate(dt, tol, maxiter, trscheme)
peps, = simpleupdate(peps, ham, alg; bipartite=false)
end
Expand All @@ -53,7 +53,7 @@ Es_exact = Dict(0 => -1.62, 2 => -0.176, 4 => 0.8603, 6 => -0.6567, 8 => -0.5243
E_exact = Es_exact[U] - U / 2

# measure energy
E = costfun(peps, envs, ham) / (N1 * N2)
E = costfun(peps, envs, ham) / (Nr * Nc)
@info "Energy = $E"
@info "Benchmark energy = $E_exact"
@test isapprox(E, E_exact; atol=5e-2)
9 changes: 7 additions & 2 deletions src/PEPSKit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module PEPSKit
using LinearAlgebra, Statistics, Base.Threads, Base.Iterators, Printf
using Base: @kwdef
using Compat
using Accessors: @set
using VectorInterface
using TensorKit, KrylovKit, MPSKit, OptimKit, TensorOperations
using ChainRulesCore, Zygote
using LoggingExtras
using MPSKit: loginit!, logiter!, logfinish!, logcancel!
using MPSKitModels
using FiniteDifferences
using Accessors: @set
using OhMyThreads: tmap

include("utility/util.jl")
Expand All @@ -21,6 +21,7 @@ include("utility/mirror.jl")
include("utility/diffset.jl")
include("utility/hook_pullback.jl")
include("utility/autoopt.jl")
include("utility/fullenv_truncation.jl")

include("networks/tensors.jl")
include("networks/infinitesquarenetwork.jl")
Expand Down Expand Up @@ -50,8 +51,9 @@ include("algorithms/ctmrg/simultaneous.jl")
include("algorithms/ctmrg/sequential.jl")
include("algorithms/ctmrg/gaugefix.jl")

include("algorithms/time_evolution/gatetools.jl")
include("algorithms/time_evolution/evoltools.jl")
include("algorithms/time_evolution/simpleupdate.jl")
include("algorithms/time_evolution/ntupdate.jl")

include("algorithms/toolbox.jl")

Expand Down Expand Up @@ -194,7 +196,10 @@ export PEPSOptimize, GeomSum, ManualIter, LinSolver
export fixedpoint

export absorb_weight
export ALSTruncation, FullEnvTruncation, fullenv_truncate
export su_iter, simpleupdate, SimpleUpdate
export NTUEnvNN, NTUEnvNNN, NTUEnvNNNp
export ntu_iter, ntupdate, NTUpdate

export InfinitePartitionFunction
export InfinitePEPS, InfiniteTransferPEPS
Expand Down
24 changes: 21 additions & 3 deletions src/algorithms/ctmrg/sequential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,36 @@ function SequentialCTMRG(;
)
end

"""
ctmrg_leftmove(col::Int, state, envs::CTMRGEnv, alg::SequentialCTMRG)

Perform sequential CTMRG left move on the `col`-th column.
"""
function ctmrg_leftmove(col::Int, state, envs::CTMRGEnv, alg::SequentialCTMRG)
#=
----> left move
C1 ← T1 ← r-1
↓ ‖
T4 = M == r
↓ ‖
C4 → T3 → r+1
c-1 c
=#
projectors, info = sequential_projectors(col, state, envs, alg.projector_alg)
envs = renormalize_sequentially(col, projectors, state, envs)
return envs, info
end

function ctmrg_iteration(state, envs::CTMRGEnv, alg::SequentialCTMRG)
ϵ = zero(real(scalartype(state)))
for _ in 1:4 # rotate
for col in 1:size(state, 2) # left move column-wise
projectors, info = sequential_projectors(col, state, envs, alg.projector_alg)
envs = renormalize_sequentially(col, projectors, state, envs)
envs, info = ctmrg_leftmove(col, state, envs, alg)
ϵ = max(ϵ, info.err)
end
state = rotate_north(state, EAST)
envs = rotate_north(envs, EAST)
end

return envs, (; err=ϵ)
end

Expand Down
11 changes: 11 additions & 0 deletions src/algorithms/time_evolution/bondenv/env_approx.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
Use CTMRG to approximately contract
a cluster around a bond to construct bond environment
"""
@kwdef struct CTMBondEnv <: BondEnvAlgorithm
pad::Int = 1
end

function bondenv_ctm(row::Int, col::Int, peps::InfinitePEPS, alg::CTMBondEnv)
return error("Not implemented")

Check warning on line 10 in src/algorithms/time_evolution/bondenv/env_approx.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/time_evolution/bondenv/env_approx.jl#L9-L10

Added lines #L9 - L10 were not covered by tests
end
Loading
Loading