Skip to content

Commit 6e78135

Browse files
author
qyli
committed
update example
1 parent 0b3855e commit 6e78135

File tree

20 files changed

+84
-761
lines changed

20 files changed

+84
-761
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using Pkg
22

33
Pkg.activate(".")
4-
Pkg.add("FiniteMPS")
54
Pkg.add(url = "https://github.com/Qiaoyi-Li/FiniteLattices.jl.git", rev="dev")
5+
Pkg.add("FiniteMPS")
66

77
Pkg.resolve()
88
Pkg.gc()

example/FreeFermion_tanTRG/model.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ function SpinlessFreeFermion(T::AbstractMatrix)
2525
# hopping
2626
for i = 1:L, j = i+1:L
2727
@assert T[i, j] == T[j, i]'
28-
addIntr2!(Root, U₁SpinlessFermion.FdagF, (i, j), -T[i, j];
29-
Z = U₁SpinlessFermion.Z, name = (:Fdag, :F))
30-
addIntr2!(Root, U₁SpinlessFermion.FdagF, (j, i), -T[j, i];
31-
Z = U₁SpinlessFermion.Z, name = (:Fdag, :F))
28+
addIntr!(Root, U₁SpinlessFermion.FdagF, (i, j), (true, true),
29+
-T[i, j]; Z = U₁SpinlessFermion.Z, name = (:Fdag, :F))
30+
addIntr!(Root, U₁SpinlessFermion.FdagF, (j, i), (true, true),
31+
-T[j, i]; Z = U₁SpinlessFermion.Z, name = (:Fdag, :F))
3232
end
3333

3434
# chemical potential
3535
for i = 1:L
36-
addIntr1!(Root, U₁SpinlessFermion.n, i, -T[i, i]; name = :n)
36+
addIntr!(Root, U₁SpinlessFermion.n, i, -T[i, i]; name = :n)
3737
end
3838

3939
return InteractionTree(Root)

example/Heisenberg_DMRG/addPkg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using Pkg
22

33
Pkg.activate(".")
4-
Pkg.add("FiniteMPS")
54
Pkg.add(url = "https://github.com/Qiaoyi-Li/FiniteLattices.jl.git", rev="dev")
5+
Pkg.add("FiniteMPS")
66

77
Pkg.resolve()
88
Pkg.gc()

example/Heisenberg_DMRG/main.jl

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,58 @@ Latt = YCTria(9, 6) |> Snake! # Triangular lattice
1111
J′ = 0.0
1212

1313
lsD = let
14-
lsD = broadcast(Int64 round, 2 .^ vcat(6:10))
15-
repeat(lsD, inner=2)
14+
lsD = broadcast(Int64 round, 2 .^ vcat(6:10))
15+
repeat(lsD, inner = 2)
1616
end
1717
lsE = zeros(length(lsD))
1818
lsinfo = Vector{Any}(undef, length(lsD))
1919
lsTimer = Vector{Any}(undef, length(lsD))
2020

2121
# initial state
2222
Ψ = let
23-
if Sym == :U₁
24-
aspace = vcat(Rep[U₁](0 => 1), repeat([Rep[U₁](i => 1 for i in -1:1/2:1),], size(Latt) - 1))
25-
Ψ = randMPS(U₁Spin.pspace, aspace)
26-
elseif Sym == :SU₂
27-
aspace = vcat(Rep[SU₂](0 => 1), repeat([Rep[SU₂](i => 1 for i in 0:1//2:1),], size(Latt) - 1))
28-
Ψ = randMPS(SU₂Spin.pspace, aspace)
29-
end
30-
Ψ
23+
if Sym == :U₁
24+
aspace = vcat(Rep[U₁](0 => 1), repeat([Rep[U₁](i => 1 for i in -1:1/2:1)], size(Latt) - 1))
25+
Ψ = randMPS(U₁Spin.pspace, aspace)
26+
elseif Sym == :SU₂
27+
aspace = vcat(Rep[SU₂](0 => 1), repeat([Rep[SU₂](i => 1 for i in 0:1//2:1)], size(Latt) - 1))
28+
Ψ = randMPS(SU₂Spin.pspace, aspace)
29+
end
30+
Ψ
3131
end
3232

3333
let
34-
if Sym == :U₁
35-
H = AutomataMPO(U₁Heisenberg(Latt; J′=J′))
36-
else
37-
H = AutomataMPO(SU₂Heisenberg(Latt; J′=J′))
38-
end
39-
Env = Environment(Ψ', H, Ψ)
34+
if Sym == :U₁
35+
H = AutomataMPO(U₁Heisenberg(Latt; J′ = J′))
36+
else
37+
H = AutomataMPO(SU₂Heisenberg(Latt; J′ = J′))
38+
end
39+
Env = Environment(Ψ', H, Ψ)
4040
41-
for (i, D) in enumerate(lsD)
42-
lsinfo[i], lsTimer[i] = DMRGSweep2!(Env;
43-
GCstep=GCstep, GCsweep=true, verbose=verbose,
44-
trunc=truncdim(D) & truncbelow(1e-8))
45-
lsE[i] = lsinfo[i][2][1].Eg
46-
end
41+
for (i, D) in enumerate(lsD)
42+
lsinfo[i], lsTimer[i] = DMRGSweep2!(Env;
43+
GCstep = GCstep, GCsweep = true, verbose = verbose,
44+
trunc = truncdim(D) & truncbelow(1e-8))
45+
lsE[i] = lsinfo[i][2][1].Eg
46+
end
4747
48-
GC.gc()
48+
GC.gc()
4949
end
5050
5151
# Observables
5252
Obs = let
53-
Tree = ObservableTree()
54-
for i in 1:size(Latt), j in i+1:size(Latt)
55-
if Sym == :U₁
56-
addObs!(Tree, (U₁Spin.Sz, U₁Spin.Sz), (i, j); name=(:Sz, :Sz))
57-
addObs!(Tree, U1Spin.S₊₋, (i, j); name=(:Su, :Sd))
58-
elseif Sym == :SU₂
59-
addObs!(Tree, SU₂Spin.SS, (i, j); name=(:S, :S))
60-
end
61-
end
53+
Tree = ObservableTree()
54+
for i in 1:size(Latt), j in i+1:size(Latt)
55+
if Sym == :U₁
56+
addObs!(Tree, (U₁Spin.Sz, U₁Spin.Sz), (i, j), (false, false); name = (:Sz, :Sz))
57+
addObs!(Tree, U1Spin.S₊₋, (i, j), (false, false); name = (:Su, :Sd))
58+
elseif Sym == :SU₂
59+
addObs!(Tree, SU₂Spin.SS, (i, j), (false, false); name = (:S, :S))
60+
end
61+
end
6262
63-
@time calObs!(Tree, Ψ; GCspacing=1000, verbose=verbose, showtimes=10)
63+
@time calObs!(Tree, Ψ; GCspacing = 1000, verbose = verbose, showtimes = 10)
64+
65+
convert(Dict, Tree)
6466
65-
if Sym == :U₁
66-
convert(Dict, Tree)
67-
elseif Sym == :SU₂
68-
convert(Dict, Tree)
69-
end
7067
end
7168

example/Heisenberg_DMRG/model.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ function SU₂Heisenberg(Latt::AbstractLattice; J::Number=1.0, J′::Number=0.0)
88

99
# NN interaction
1010
for pairs in neighbor(Latt)
11-
addIntr2!(Root, LocalSpace.SS, pairs,
11+
addIntr!(Root, LocalSpace.SS, pairs, (false, false),
1212
J; name=(:S, :S))
1313
end
1414

1515
# NNN interaction
1616
for pairs in neighbor(Latt; level = 2)
17-
addIntr2!(Root, LocalSpace.SS, pairs,
17+
addIntr!(Root, LocalSpace.SS, pairs, (false, false),
1818
J′; name=(:S, :S))
1919
end
2020

@@ -34,21 +34,21 @@ function U₁Heisenberg(Latt::AbstractLattice; J::Number=1, J′::Number=0)
3434

3535
# NN interaction
3636
for pairs in neighbor(Latt)
37-
addIntr2!(Root, (LocalSpace.Sz, LocalSpace.Sz), pairs,
37+
addIntr!(Root, (LocalSpace.Sz, LocalSpace.Sz), pairs, (false, false),
3838
J; name=(:Sz, :Sz))
39-
addIntr2!(Root, LocalSpace.S₋₊, pairs,
39+
addIntr!(Root, LocalSpace.S₋₊, pairs, (false, false),
4040
J/2; name=(:Sm, :Sp))
41-
addIntr2!(Root, LocalSpace.S₊₋, pairs,
41+
addIntr!(Root, LocalSpace.S₊₋, pairs, (false, false),
4242
J/2; name=(:Sp, :Sm))
4343
end
4444

4545
# NNN interaction
4646
for pairs in neighbor(Latt; level = 2)
47-
addIntr2!(Root, (LocalSpace.Sz, LocalSpace.Sz), pairs,
47+
addIntr!(Root, (LocalSpace.Sz, LocalSpace.Sz), pairs, (false, false),
4848
J′; name=(:Sz, :Sz))
49-
addIntr2!(Root, LocalSpace.S₋₊, pairs,
49+
addIntr!(Root, LocalSpace.S₋₊, pairs, (false, false),
5050
J′/2; name=(:Sm, :Sp))
51-
addIntr2!(Root, LocalSpace.S₊₋, pairs,
51+
addIntr!(Root, LocalSpace.S₊₋, pairs, (false, false),
5252
J′/2; name=(:Sp, :Sm))
5353
end
5454

example/Hubbard_DMRG/addPkg.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using Pkg
22

33
Pkg.activate(".")
4-
Pkg.add("FiniteMPS")
54
Pkg.add(url = "https://github.com/Qiaoyi-Li/FiniteLattices.jl.git", rev="dev")
5+
Pkg.add("FiniteMPS")
6+
67

78
Pkg.resolve()
89
Pkg.gc()

example/Hubbard_DMRG/main.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ Obs = let
4545
addObs!(Tree, U₁SU₂Fermion.n, i, 1; name=:n)
4646
end
4747
for i in 1:size(Latt), j in i+1:size(Latt)
48-
addObs!(Tree, U₁SU₂Fermion.SS, (i, j), 1; name=(:S, :S))
49-
addObs!(Tree, (U₁SU₂Fermion.n, U₁SU₂Fermion.n), (i, j), 1; name=(:n, :n))
50-
addObs!(Tree, U₁SU₂Fermion.FdagF, (i, j), 1; Z=U₁SU₂Fermion.Z, name=(:Fdag, :F))
48+
addObs!(Tree, U₁SU₂Fermion.SS, (i, j), (false, false); name=(:S, :S))
49+
addObs!(Tree, (U₁SU₂Fermion.n, U₁SU₂Fermion.n), (i, j), (false, false); name=(:n, :n))
50+
addObs!(Tree, U₁SU₂Fermion.FdagF, (i, j), (true, true); Z=U₁SU₂Fermion.Z, name=(:Fdag, :F))
5151
end
5252
5353
for (i, j) in neighbor(Latt), (k, l) in neighbor(Latt)
@@ -56,9 +56,9 @@ Obs = let
5656
i > k && continue # note ⟨Δᵢⱼ^dag Δₖₗ⟩ = ⟨Δₖₗ^dag Δᵢⱼ⟩
5757
5858
# singlet pairing
59-
addObs!(Tree, U₁SU₂Fermion.ΔₛdagΔₛ, (i, j, k, l), 1; Z=U₁SU₂Fermion.Z, name=(:Fdag, :FdagS, :FS, :F))
59+
addObs!(Tree, U₁SU₂Fermion.ΔₛdagΔₛ, (i, j, k, l), Tuple(fill(true, 4)); Z=U₁SU₂Fermion.Z, name=(:Fdag, :FdagS, :FS, :F))
6060
# triplet pairing
61-
addObs!(Tree, U₁SU₂Fermion.ΔₜdagΔₜ, (i, j, k, l), 1; Z=U₁SU₂Fermion.Z, name=(:Fdag, :FdagT, :FT, :F))
61+
addObs!(Tree, U₁SU₂Fermion.ΔₜdagΔₜ, (i, j, k, l), Tuple(fill(true, 4)); Z=U₁SU₂Fermion.Z, name=(:Fdag, :FdagT, :FT, :F))
6262
end
6363
6464
@time calObs!(Tree, Ψ; GCspacing=1000, verbose=verbose, showtimes=10)

example/Hubbard_DMRG/model.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ function U₁SU₂Hubbard(Latt::AbstractLattice; t::Number=1, t′::Number=0, U:
55
let LocalSpace = U₁SU₂Fermion
66
# NN hopping
77
for pairs in neighbor(Latt; ordered=true)
8-
addIntr2!(Root, LocalSpace.FdagF, pairs,
8+
addIntr!(Root, LocalSpace.FdagF, pairs, (true, true),
99
-t; Z=LocalSpace.Z, name=(:Fdag, :F))
1010
end
1111
# NNN hopping
1212
for pairs in neighbor(Latt; level = 2, ordered=true)
13-
addIntr2!(Root, LocalSpace.FdagF, pairs,
13+
addIntr!(Root, LocalSpace.FdagF, pairs, (true, true),
1414
-t′; Z=LocalSpace.Z, name=(:Fdag, :F))
1515
end
1616
# nn interaction
1717
for pairs in neighbor(Latt)
18-
addIntr2!(Root, (LocalSpace.n, LocalSpace.n), pairs,
18+
addIntr!(Root, (LocalSpace.n, LocalSpace.n), pairs, (false, false),
1919
V; name=(:n, :n))
2020
end
2121

2222
# U and μ
2323
for i in 1:size(Latt)
24-
addIntr1!(Root, LocalSpace.nd, i, U; name=:nd)
25-
addIntr1!(Root, LocalSpace.n, i, -μ; name=:n)
24+
addIntr!(Root, LocalSpace.nd, i, U; name=:nd)
25+
addIntr!(Root, LocalSpace.n, i, -μ; name=:n)
2626
end
2727
end
2828

example/Hubbard_tanTRG/addPkg.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ using Pkg
44
@assert pwd()[end-13:end] == "Hubbard_tanTRG"
55

66
Pkg.activate(".")
7-
Pkg.develop(path = "../../")
8-
Pkg.add(url = "https://github.com/Qiaoyi-Li/FiniteLattices.jl.git", rev="dev")
97
Pkg.add("MKL")
8+
Pkg.add("FiniteMPS")
9+
Pkg.add(url = "https://github.com/Qiaoyi-Li/FiniteLattices.jl.git", rev="dev")
10+
1011

1112
Pkg.resolve()
1213
Pkg.gc()

example/Hubbard_tanTRG/model.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ function U₁SU₂Hubbard(Latt::AbstractLattice; t::Number=1, t′::Number=0, U:
55
let LocalSpace = U₁SU₂Fermion
66
# NN hopping
77
for pairs in neighbor(Latt; ordered=true)
8-
addIntr2!(Root, LocalSpace.FdagF, pairs,
8+
addIntr!(Root, LocalSpace.FdagF, pairs, (true, true),
99
-t; Z=LocalSpace.Z, name=(:Fdag, :F))
1010
end
1111
# NNN hopping
1212
for pairs in neighbor(Latt; level = 2, ordered=true)
13-
addIntr2!(Root, LocalSpace.FdagF, pairs,
13+
addIntr!(Root, LocalSpace.FdagF, pairs, (true, true),
1414
-t′; Z=LocalSpace.Z, name=(:Fdag, :F))
1515
end
1616
# nn interaction
1717
for pairs in neighbor(Latt)
18-
addIntr2!(Root, (LocalSpace.n, LocalSpace.n), pairs,
18+
addIntr!(Root, (LocalSpace.n, LocalSpace.n), pairs, (false, false),
1919
V; name=(:n, :n))
2020
end
2121

2222
# U and μ
2323
for i in 1:size(Latt)
24-
addIntr1!(Root, LocalSpace.nd, i, U; name=:nd)
25-
addIntr1!(Root, LocalSpace.n, i, -μ; name=:n)
24+
addIntr!(Root, LocalSpace.nd, i, U; name=:nd)
25+
addIntr!(Root, LocalSpace.n, i, -μ; name=:n)
2626
end
2727
end
2828

0 commit comments

Comments
 (0)