Skip to content

Add simple update algorithm #97

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

Merged
merged 84 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
399a600
remove CTMRG redundant logging
Yue-Zhengyuan Nov 1, 2024
9406792
Merge branch 'QuantumKitHub:master' into master
Yue-Zhengyuan Nov 2, 2024
be6b8a7
Merge branch 'QuantumKitHub:master' into master
Yue-Zhengyuan Nov 5, 2024
2d22cf5
Merge pull request #1 from QuantumKitHub/pb-improve-sequential
Yue-Zhengyuan Nov 5, 2024
55f1e00
add simple update algorithm
Yue-Zhengyuan Nov 6, 2024
f9d19fd
add full update core algorithm
Yue-Zhengyuan Nov 6, 2024
0119c55
improve formatting
Yue-Zhengyuan Nov 7, 2024
6a0d151
Merge branch 'QuantumKitHub:master' into master
Yue-Zhengyuan Nov 7, 2024
98e24ec
Merge pull request #2 from QuantumKitHub/pb-improve-sequential
Yue-Zhengyuan Nov 7, 2024
043a7fe
add TODO for svd initialization of ALS optimization
Yue-Zhengyuan Nov 7, 2024
0927082
remove a redundant SVD in full update
Yue-Zhengyuan Nov 7, 2024
e3d7402
Merge branch 'QuantumKitHub:master' into master
Yue-Zhengyuan Nov 8, 2024
6735ade
prepare for addition of full-infinite env CTMRG
Yue-Zhengyuan Nov 10, 2024
3a82f06
Add `length` for SUWeight
Yue-Zhengyuan Nov 14, 2024
9577feb
Define `Base.show` for `SUWeight`
Yue-Zhengyuan Nov 15, 2024
effe459
Merge branch 'QuantumKitHub:master' into master
Yue-Zhengyuan Nov 17, 2024
a1c3e06
add test for simple update
Yue-Zhengyuan Nov 17, 2024
448176c
add test for full update
Yue-Zhengyuan Nov 17, 2024
1894873
update formatting
Yue-Zhengyuan Nov 17, 2024
9899298
Refactor calc_convergence
Yue-Zhengyuan Nov 18, 2024
b4d43b5
Update sdiag_pow for latest TensorKit
Yue-Zhengyuan Nov 18, 2024
4bc9e46
Rename folder "timeevol" to "time_evolution"
Yue-Zhengyuan Nov 18, 2024
1e97ec0
Replace `maxabs` by infinity norm
Yue-Zhengyuan Nov 18, 2024
a1c4a2d
Focus on simple update
Yue-Zhengyuan Nov 18, 2024
65533e4
implement `InfiniteWeightPEPS`
Yue-Zhengyuan Nov 18, 2024
b1a0083
Update to the Heisenberg tensors
Sander-De-Meyer Nov 20, 2024
376be37
Minor fix after using operators from MPSKitModels
Yue-Zhengyuan Nov 20, 2024
8690f8a
Use Julia's logging system; shorten SU test
Yue-Zhengyuan Nov 20, 2024
c5d586d
Solve deprecation warning for `permute`
Yue-Zhengyuan Nov 21, 2024
a7d46ef
Remove buggy in-place rotations and reflections
Yue-Zhengyuan Nov 21, 2024
53d5a55
Minor refactoring
Yue-Zhengyuan Nov 21, 2024
a026db8
Print more message during simple update
Yue-Zhengyuan Nov 22, 2024
2643b68
Replace custom rho with existing exp. value calculation
Yue-Zhengyuan Nov 23, 2024
23f92bf
Integrate SU with LocalOperator
Yue-Zhengyuan Nov 23, 2024
6122573
remove accidentally added test
Yue-Zhengyuan Nov 24, 2024
7a1d5d5
Add rotation and reflection of LocalOperator
Yue-Zhengyuan Nov 24, 2024
e616b00
Improve `get_gateterm`
Yue-Zhengyuan Nov 24, 2024
ff17a71
fix format
Yue-Zhengyuan Nov 25, 2024
69d52d4
fix format again
Yue-Zhengyuan Nov 25, 2024
aa519a6
Introduce `SimpleUpdate` algorithm struct
Yue-Zhengyuan Nov 27, 2024
2dd6310
Export `simpleupdate`; remove abbreviated `SU`
Yue-Zhengyuan Nov 27, 2024
ca1423f
add FixedSpaceTruncation for simple update
Yue-Zhengyuan Nov 28, 2024
460ea5e
Create heisenberg_sufu_onesite
Sander-De-Meyer Nov 28, 2024
4c33911
format fix
Sander-De-Meyer Nov 28, 2024
fd96a58
Add spin U(1) symmetry to Heisenberg model SU test
Yue-Zhengyuan Nov 29, 2024
0d47dc1
Add SU-AD test for heisenberg
Yue-Zhengyuan Nov 29, 2024
df4c4b1
fix formatting
Yue-Zhengyuan Nov 29, 2024
f85dcb0
add check that all operators are twosite
Sander-De-Meyer Dec 2, 2024
e7026eb
update check two-body terms
Sander-De-Meyer Dec 3, 2024
003c4e2
Change PEPSOptimize parameters in `suad` test
Yue-Zhengyuan Dec 5, 2024
959ce80
Merge branch 'QuantumKitHub:master' into simpleupdate
Yue-Zhengyuan Dec 5, 2024
ef5e080
Hubbard model
Sander-De-Meyer Dec 5, 2024
5d4feba
Clean up test on Hubbard model
Yue-Zhengyuan Dec 6, 2024
2e0cccd
Add t-J model Hamiltonian
Yue-Zhengyuan Dec 6, 2024
4650c3c
Squashed commit of the following:
Yue-Zhengyuan Dec 9, 2024
c390819
Merge pull request #5 from QuantumKitHub/master
Yue-Zhengyuan Dec 9, 2024
0c5e223
Update `ctmrg_leftmove` with latest upstream
Yue-Zhengyuan Dec 9, 2024
0240197
Apply suggestions from code review
Yue-Zhengyuan Dec 9, 2024
406291b
Rename for `absorb_weight`
Yue-Zhengyuan Dec 9, 2024
cde0356
Improve SUWeight construction
Yue-Zhengyuan Dec 9, 2024
417e1cf
Move geometric operations on LocalOperator
Yue-Zhengyuan Dec 9, 2024
68b94b0
Remove `sdiag_inv_sqrt` (replaced with `sdiag_pow`)
Yue-Zhengyuan Dec 9, 2024
ee6b16e
Fix rrule for sdiag_pow and formatting
Yue-Zhengyuan Dec 9, 2024
f6434f4
Fix Heisenberg SU test
Yue-Zhengyuan Dec 10, 2024
635b9ca
Improve some docstring
Yue-Zhengyuan Dec 10, 2024
995ccee
Add back `length` for `SUWeight`
Yue-Zhengyuan Dec 10, 2024
be133bc
update actions
lkdvos Dec 10, 2024
ea0d4bd
Refactoring `SUWeight`
Yue-Zhengyuan Dec 10, 2024
36baf09
Update simple update test
Yue-Zhengyuan Dec 10, 2024
d68d8b9
disable multithreading
lkdvos Dec 10, 2024
12c4297
remove superfluous broadcats
lkdvos Dec 10, 2024
0a980d9
Add function signatures
pbrehmer Dec 10, 2024
9ad9a24
Merge Heisenberg tests
pbrehmer Dec 10, 2024
dfb4593
Fix docstring and error messages
Yue-Zhengyuan Dec 11, 2024
e0dd985
Promote `SUWeight` to a custom `struct`
Yue-Zhengyuan Dec 11, 2024
8e87944
Fix formatting
Yue-Zhengyuan Dec 11, 2024
6ecb00b
Fix pow rrule and make eltype more consistent
pbrehmer Dec 11, 2024
41596d1
Fix `similar` for `InfinitePEPO` after modifying `eltype`
Yue-Zhengyuan Dec 11, 2024
17eac3d
Remove `eltype` of `InfiniteWeightPEPS`
Yue-Zhengyuan Dec 11, 2024
20a68f9
Scrap eltype for CTMRGEnv, add args to similar(::PEPO)
pbrehmer Dec 11, 2024
76889d3
Fix conj in sdiag_pow rrule
pbrehmer Dec 11, 2024
187efb1
Cicrumvent Heisenberg tests errors by using GMRES to differentiate SVD
pbrehmer Dec 11, 2024
993577d
small improvements
lkdvos Dec 11, 2024
8fc39e0
update MPSKitModels compat
lkdvos Dec 11, 2024
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
12 changes: 7 additions & 5 deletions .github/workflows/CI.yml → .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Tests
on:
push:
branches:
Expand All @@ -23,8 +23,8 @@ jobs:
fail-fast: false
matrix:
version:
- 'lts'
- '1'
- 'lts' # minimal supported version
- '1' # latest released Julia version
group:
- ctmrg
- boundarymps
Expand All @@ -34,9 +34,11 @@ jobs:
- ubuntu-latest
- macOS-latest
- windows-latest
uses: "QuantumKitHub/.github/.github/workflows/tests.yml@main"
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/Tests.yml@main"
with:
group: "${{ matrix.group }}"
julia-version: "${{ matrix.version }}"
os: "${{ matrix.os }}"
secrets: inherit
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ KrylovKit = "0.8"
LinearAlgebra = "1"
LoggingExtras = "1"
MPSKit = "0.11"
MPSKitModels = "0.3"
MPSKitModels = "0.3.5"
OhMyThreads = "0.7"
OptimKit = "0.3"
Printf = "1"
Expand Down
62 changes: 62 additions & 0 deletions examples/hubbard_su.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Test
using Printf
using Random
using PEPSKit
using TensorKit

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

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
# Hubbard model Hamiltonian at half-filling
t, U = 1.0, 6.0
ham = hubbard_model(Float64, Trivial, Trivial, InfiniteSquare(N1, N2); t=t, U=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)
alg = SimpleUpdate(dt, tol, maxiter, trscheme)
result = simpleupdate(peps, ham, alg; bipartite=false)
global peps = result[1]
end

# absort weight into site tensors
peps = InfinitePEPS(peps)
# CTMRG
χenv0, χenv = 6, 20
Espace = Vect[fℤ₂](0 => χenv0 / 2, 1 => χenv0 / 2)
envs = CTMRGEnv(randn, Float64, peps, Espace)
for χ in [χenv0, χenv]
trscheme = truncerr(1e-9) & truncdim(χ)
ctm_alg = CTMRG(;
maxiter=40, tol=1e-10, verbosity=3, trscheme=trscheme, ctmrgscheme=:sequential
)
global envs = leading_boundary(envs, peps, ctm_alg)
end

"""
Benchmark values of the ground state energy from
Qin, M., Shi, H., & Zhang, S. (2016). Benchmark study of the two-dimensional Hubbard model with auxiliary-field quantum Monte Carlo method. Physical Review B, 94(8), 085103.
"""
# measure physical quantities
E = costfun(peps, envs, ham) / (N1 * N2)
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
@info @sprintf("Energy = %.8f\n", E)
@info @sprintf("Benchmark energy = %.8f\n", E_exact)
@test isapprox(E, E_exact; atol=1e-2)
14 changes: 12 additions & 2 deletions src/PEPSKit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ include("utility/util.jl")
include("utility/diffable_threads.jl")
include("utility/svd.jl")
include("utility/rotations.jl")
include("utility/mirror.jl")
include("utility/diffset.jl")
include("utility/hook_pullback.jl")
include("utility/autoopt.jl")

include("states/abstractpeps.jl")
include("states/infinitepeps.jl")
include("states/infiniteweightpeps.jl")

include("operators/transferpeps.jl")
include("operators/infinitepepo.jl")
Expand All @@ -43,6 +45,9 @@ include("algorithms/ctmrg/sparse_environments.jl")
include("algorithms/ctmrg/ctmrg.jl")
include("algorithms/ctmrg/gaugefix.jl")

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

include("algorithms/toolbox.jl")

include("algorithms/peps_opt.jl")
Expand All @@ -59,7 +64,7 @@ include("utility/symmetrization.jl")
const ctmrgscheme = :simultaneous
const reuse_env = true
const trscheme = FixedSpaceTruncation()
const fwd_alg = TensorKit.SVD()
const fwd_alg = TensorKit.SDD()
const rrule_alg = Arnoldi(; tol=1e-2fpgrad_tol, krylovdim=48, verbosity=-1)
const svd_alg = SVDAdjoint(; fwd_alg, rrule_alg)
const optimizer = LBFGS(32; maxiter=100, gradtol=1e-4, verbosity=2)
Expand Down Expand Up @@ -167,13 +172,18 @@ export leading_boundary
export PEPSOptimize, GeomSum, ManualIter, LinSolver
export fixedpoint

export absorb_weight
export su_iter, simpleupdate, SimpleUpdate

export InfinitePEPS, InfiniteTransferPEPS
export SUWeight, InfiniteWeightPEPS
export InfinitePEPO, InfiniteTransferPEPO
export initializeMPS, initializePEPS
export ReflectDepth, ReflectWidth, Rotate, RotateReflect
export symmetrize!, symmetrize_retract_and_finalize!
export showtypeofgrad
export InfiniteSquare, vertices, nearest_neighbours, next_nearest_neighbours
export transverse_field_ising, heisenberg_XYZ, j1_j2, pwave_superconductor
export transverse_field_ising, heisenberg_XYZ, j1_j2
export pwave_superconductor, hubbard_model, tj_model

end # module
28 changes: 23 additions & 5 deletions src/algorithms/ctmrg/ctmrg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@
end
end

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

Perform 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 = ctmrg_projectors(col, state, envs, alg)
envs = ctmrg_renormalize(col, projectors, state, envs, alg)
return envs, info
end

"""
ctmrg_iter(state, envs::CTMRGEnv, alg::CTMRG) -> envs′, info

Expand All @@ -143,14 +163,12 @@
ϵ = zero(real(scalartype(state)))
for _ in 1:4 # rotate
for col in 1:size(state, 2) # left move column-wise
projectors, info = ctmrg_projectors(col, state, envs, alg)
envs = ctmrg_renormalize(col, projectors, state, envs, alg)
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
function ctmrg_iter(state, envs::CTMRGEnv, alg::SimultaneousCTMRG)
Expand Down Expand Up @@ -300,7 +318,7 @@
Q::AbstractTensorMap{E,3,3},
Q_next::AbstractTensorMap{E,3,3},
) where {E<:ElementarySpace}
isqS = sdiag_inv_sqrt(S)
isqS = sdiag_pow(S, -0.5)
P_left = Q_next * V' * isqS
P_right = isqS * U' * Q
return P_left, P_right
Expand All @@ -312,7 +330,7 @@
Q::EnlargedCorner,
Q_next::EnlargedCorner,
) where {E<:ElementarySpace}
isqS = sdiag_inv_sqrt(S)
isqS = sdiag_pow(S, -0.5)

Check warning on line 333 in src/algorithms/ctmrg/ctmrg.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/ctmrg/ctmrg.jl#L333

Added line #L333 was not covered by tests
P_left = left_projector(Q.E_1, Q.C, Q.E_2, V, isqS, Q.ket, Q.bra)
P_right = right_projector(
Q_next.E_1, Q_next.C, Q_next.E_2, U, isqS, Q_next.ket, Q_next.bra
Expand Down
11 changes: 11 additions & 0 deletions src/algorithms/ctmrg/gaugefix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@
return max(ΔCS, ΔTS), CSnew, TSnew
end

"""
calc_convergence(envsNew::CTMRGEnv, envsOld::CTMRGEnv)

Calculate convergence of CTMRG by comparing the singular values of CTM tensors.
"""
function calc_convergence(envsNew::CTMRGEnv, envsOld::CTMRGEnv)
CSOld = map(x -> tsvd(x)[2], envsOld.corners)
TSOld = map(x -> tsvd(x)[2], envsOld.edges)
return calc_convergence(envsNew, CSOld, TSOld)

Check warning on line 184 in src/algorithms/ctmrg/gaugefix.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/ctmrg/gaugefix.jl#L181-L184

Added lines #L181 - L184 were not covered by tests
end

@non_differentiable calc_convergence(args...)

"""
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/peps_opt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ function fixedpoint(

if scalartype(env₀) <: Real
env₀ = complex(env₀)
@warn "the provided real environment was converted to a complex environment since\
:fixed mode generally produces complex gauges; use :diffgauge mode instead to work\
@warn "the provided real environment was converted to a complex environment since \
:fixed mode generally produces complex gauges; use :diffgauge mode instead to work \
with purely real environments"
end

Expand Down
52 changes: 52 additions & 0 deletions src/algorithms/time_evolution/gatetools.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
get_gate(dt::Float64, H::LocalOperator)

Compute `exp(-dt * H)` from the nearest neighbor Hamiltonian `H`.
"""
function get_gate(dt::Float64, H::LocalOperator)
@assert all([
length(op.dom) == 2 && norm(Tuple(terms[2] - terms[1])) == 1.0 for
(terms, op) in H.terms
]) "Only nearest-neighbour terms allowed"
return LocalOperator(
H.lattice, Tuple(sites => exp(-dt * op) for (sites, op) in H.terms)...
)
end

"""
is_equivalent(bond1::NTuple{2,CartesianIndex{2}}, bond2::NTuple{2,CartesianIndex{2}}, (Nrow, Ncol)::NTuple{2,Int})

Check if two 2-site bonds are related by a (periodic) lattice translation.
"""
function is_equivalent(
bond1::NTuple{2,CartesianIndex{2}},
bond2::NTuple{2,CartesianIndex{2}},
(Nrow, Ncol)::NTuple{2,Int},
)
r1 = bond1[1] - bond1[2]
r2 = bond2[1] - bond2[2]
shift_row = bond1[1][1] - bond2[1][1]
shift_col = bond1[1][2] - bond2[1][2]
return r1 == r2 && mod(shift_row, Nrow) == 0 && mod(shift_col, Ncol) == 0
end

"""
get_gateterm(gate::LocalOperator, bond::NTuple{2,CartesianIndex{2}})

Get the term of a 2-site gate acting on a certain bond.
Input `gate` should only include one term for each nearest neighbor bond.
"""
function get_gateterm(gate::LocalOperator, bond::NTuple{2,CartesianIndex{2}})
label = findall(p -> is_equivalent(p.first, bond, size(gate.lattice)), gate.terms)
if length(label) == 0
# try reversed site order
label = findall(
p -> is_equivalent(p.first, reverse(bond), size(gate.lattice)), gate.terms
)
@assert length(label) == 1
return permute(gate.terms[label[1]].second, ((2, 1), (4, 3)))
else
@assert length(label) == 1
return gate.terms[label[1]].second
end
end
Loading
Loading