Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
qyli committed Jan 8, 2025
1 parent 0b3855e commit 6e78135
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 761 deletions.
2 changes: 1 addition & 1 deletion example/FreeFermion_tanTRG/addPkg.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Pkg

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

Pkg.resolve()
Pkg.gc()
10 changes: 5 additions & 5 deletions example/FreeFermion_tanTRG/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ function SpinlessFreeFermion(T::AbstractMatrix)
# hopping
for i = 1:L, j = i+1:L
@assert T[i, j] == T[j, i]'
addIntr2!(Root, U₁SpinlessFermion.FdagF, (i, j), -T[i, j];
Z = U₁SpinlessFermion.Z, name = (:Fdag, :F))
addIntr2!(Root, U₁SpinlessFermion.FdagF, (j, i), -T[j, i];
Z = U₁SpinlessFermion.Z, name = (:Fdag, :F))
addIntr!(Root, U₁SpinlessFermion.FdagF, (i, j), (true, true),
-T[i, j]; Z = U₁SpinlessFermion.Z, name = (:Fdag, :F))
addIntr!(Root, U₁SpinlessFermion.FdagF, (j, i), (true, true),
-T[j, i]; Z = U₁SpinlessFermion.Z, name = (:Fdag, :F))
end

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

return InteractionTree(Root)
Expand Down
2 changes: 1 addition & 1 deletion example/Heisenberg_DMRG/addPkg.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Pkg

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

Pkg.resolve()
Pkg.gc()
73 changes: 35 additions & 38 deletions example/Heisenberg_DMRG/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,58 @@ Latt = YCTria(9, 6) |> Snake! # Triangular lattice
J′ = 0.0

lsD = let
lsD = broadcast(Int64 round, 2 .^ vcat(6:10))
repeat(lsD, inner=2)
lsD = broadcast(Int64 round, 2 .^ vcat(6:10))
repeat(lsD, inner = 2)
end
lsE = zeros(length(lsD))
lsinfo = Vector{Any}(undef, length(lsD))
lsTimer = Vector{Any}(undef, length(lsD))

# initial state
Ψ = let
if Sym == :U₁
aspace = vcat(Rep[U₁](0 => 1), repeat([Rep[U₁](i => 1 for i in -1:1/2:1),], size(Latt) - 1))
Ψ = randMPS(U₁Spin.pspace, aspace)
elseif Sym == :SU₂
aspace = vcat(Rep[SU₂](0 => 1), repeat([Rep[SU₂](i => 1 for i in 0:1//2:1),], size(Latt) - 1))
Ψ = randMPS(SU₂Spin.pspace, aspace)
end
Ψ
if Sym == :U₁
aspace = vcat(Rep[U₁](0 => 1), repeat([Rep[U₁](i => 1 for i in -1:1/2:1)], size(Latt) - 1))
Ψ = randMPS(U₁Spin.pspace, aspace)
elseif Sym == :SU₂
aspace = vcat(Rep[SU₂](0 => 1), repeat([Rep[SU₂](i => 1 for i in 0:1//2:1)], size(Latt) - 1))
Ψ = randMPS(SU₂Spin.pspace, aspace)
end
Ψ
end

let
if Sym == :U₁
H = AutomataMPO(U₁Heisenberg(Latt; J′=J′))
else
H = AutomataMPO(SU₂Heisenberg(Latt; J′=J′))
end
Env = Environment', H, Ψ)
if Sym == :U₁
H = AutomataMPO(U₁Heisenberg(Latt; J′ = J′))
else
H = AutomataMPO(SU₂Heisenberg(Latt; J′ = J′))
end
Env = Environment', H, Ψ)

for (i, D) in enumerate(lsD)
lsinfo[i], lsTimer[i] = DMRGSweep2!(Env;
GCstep=GCstep, GCsweep=true, verbose=verbose,
trunc=truncdim(D) & truncbelow(1e-8))
lsE[i] = lsinfo[i][2][1].Eg
end
for (i, D) in enumerate(lsD)
lsinfo[i], lsTimer[i] = DMRGSweep2!(Env;
GCstep = GCstep, GCsweep = true, verbose = verbose,
trunc = truncdim(D) & truncbelow(1e-8))
lsE[i] = lsinfo[i][2][1].Eg
end

GC.gc()
GC.gc()
end

# Observables
Obs = let
Tree = ObservableTree()
for i in 1:size(Latt), j in i+1:size(Latt)
if Sym == :U₁
addObs!(Tree, (U₁Spin.Sz, U₁Spin.Sz), (i, j); name=(:Sz, :Sz))
addObs!(Tree, U1Spin.S₊₋, (i, j); name=(:Su, :Sd))
elseif Sym == :SU₂
addObs!(Tree, SU₂Spin.SS, (i, j); name=(:S, :S))
end
end
Tree = ObservableTree()
for i in 1:size(Latt), j in i+1:size(Latt)
if Sym == :U₁
addObs!(Tree, (U₁Spin.Sz, U₁Spin.Sz), (i, j), (false, false); name = (:Sz, :Sz))
addObs!(Tree, U1Spin.S₊₋, (i, j), (false, false); name = (:Su, :Sd))
elseif Sym == :SU₂
addObs!(Tree, SU₂Spin.SS, (i, j), (false, false); name = (:S, :S))
end
end

@time calObs!(Tree, Ψ; GCspacing=1000, verbose=verbose, showtimes=10)
@time calObs!(Tree, Ψ; GCspacing = 1000, verbose = verbose, showtimes = 10)

convert(Dict, Tree)

if Sym == :U₁
convert(Dict, Tree)
elseif Sym == :SU₂
convert(Dict, Tree)
end
end

16 changes: 8 additions & 8 deletions example/Heisenberg_DMRG/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ function SU₂Heisenberg(Latt::AbstractLattice; J::Number=1.0, J′::Number=0.0)

# NN interaction
for pairs in neighbor(Latt)
addIntr2!(Root, LocalSpace.SS, pairs,
addIntr!(Root, LocalSpace.SS, pairs, (false, false),
J; name=(:S, :S))
end

# NNN interaction
for pairs in neighbor(Latt; level = 2)
addIntr2!(Root, LocalSpace.SS, pairs,
addIntr!(Root, LocalSpace.SS, pairs, (false, false),
J′; name=(:S, :S))
end

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

# NN interaction
for pairs in neighbor(Latt)
addIntr2!(Root, (LocalSpace.Sz, LocalSpace.Sz), pairs,
addIntr!(Root, (LocalSpace.Sz, LocalSpace.Sz), pairs, (false, false),
J; name=(:Sz, :Sz))
addIntr2!(Root, LocalSpace.S₋₊, pairs,
addIntr!(Root, LocalSpace.S₋₊, pairs, (false, false),
J/2; name=(:Sm, :Sp))
addIntr2!(Root, LocalSpace.S₊₋, pairs,
addIntr!(Root, LocalSpace.S₊₋, pairs, (false, false),
J/2; name=(:Sp, :Sm))
end

# NNN interaction
for pairs in neighbor(Latt; level = 2)
addIntr2!(Root, (LocalSpace.Sz, LocalSpace.Sz), pairs,
addIntr!(Root, (LocalSpace.Sz, LocalSpace.Sz), pairs, (false, false),
J′; name=(:Sz, :Sz))
addIntr2!(Root, LocalSpace.S₋₊, pairs,
addIntr!(Root, LocalSpace.S₋₊, pairs, (false, false),
J′/2; name=(:Sm, :Sp))
addIntr2!(Root, LocalSpace.S₊₋, pairs,
addIntr!(Root, LocalSpace.S₊₋, pairs, (false, false),
J′/2; name=(:Sp, :Sm))
end

Expand Down
3 changes: 2 additions & 1 deletion example/Hubbard_DMRG/addPkg.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Pkg

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


Pkg.resolve()
Pkg.gc()
10 changes: 5 additions & 5 deletions example/Hubbard_DMRG/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ Obs = let
addObs!(Tree, U₁SU₂Fermion.n, i, 1; name=:n)
end
for i in 1:size(Latt), j in i+1:size(Latt)
addObs!(Tree, U₁SU₂Fermion.SS, (i, j), 1; name=(:S, :S))
addObs!(Tree, (U₁SU₂Fermion.n, U₁SU₂Fermion.n), (i, j), 1; name=(:n, :n))
addObs!(Tree, U₁SU₂Fermion.FdagF, (i, j), 1; Z=U₁SU₂Fermion.Z, name=(:Fdag, :F))
addObs!(Tree, U₁SU₂Fermion.SS, (i, j), (false, false); name=(:S, :S))
addObs!(Tree, (U₁SU₂Fermion.n, U₁SU₂Fermion.n), (i, j), (false, false); name=(:n, :n))
addObs!(Tree, U₁SU₂Fermion.FdagF, (i, j), (true, true); Z=U₁SU₂Fermion.Z, name=(:Fdag, :F))
end

for (i, j) in neighbor(Latt), (k, l) in neighbor(Latt)
Expand All @@ -56,9 +56,9 @@ Obs = let
i > k && continue # note ⟨Δᵢⱼ^dag Δₖₗ⟩ = ⟨Δₖₗ^dag Δᵢⱼ⟩

# singlet pairing
addObs!(Tree, U₁SU₂Fermion.ΔₛdagΔₛ, (i, j, k, l), 1; Z=U₁SU₂Fermion.Z, name=(:Fdag, :FdagS, :FS, :F))
addObs!(Tree, U₁SU₂Fermion.ΔₛdagΔₛ, (i, j, k, l), Tuple(fill(true, 4)); Z=U₁SU₂Fermion.Z, name=(:Fdag, :FdagS, :FS, :F))
# triplet pairing
addObs!(Tree, U₁SU₂Fermion.ΔₜdagΔₜ, (i, j, k, l), 1; Z=U₁SU₂Fermion.Z, name=(:Fdag, :FdagT, :FT, :F))
addObs!(Tree, U₁SU₂Fermion.ΔₜdagΔₜ, (i, j, k, l), Tuple(fill(true, 4)); Z=U₁SU₂Fermion.Z, name=(:Fdag, :FdagT, :FT, :F))
end

@time calObs!(Tree, Ψ; GCspacing=1000, verbose=verbose, showtimes=10)
Expand Down
10 changes: 5 additions & 5 deletions example/Hubbard_DMRG/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ function U₁SU₂Hubbard(Latt::AbstractLattice; t::Number=1, t′::Number=0, U:
let LocalSpace = U₁SU₂Fermion
# NN hopping
for pairs in neighbor(Latt; ordered=true)
addIntr2!(Root, LocalSpace.FdagF, pairs,
addIntr!(Root, LocalSpace.FdagF, pairs, (true, true),
-t; Z=LocalSpace.Z, name=(:Fdag, :F))
end
# NNN hopping
for pairs in neighbor(Latt; level = 2, ordered=true)
addIntr2!(Root, LocalSpace.FdagF, pairs,
addIntr!(Root, LocalSpace.FdagF, pairs, (true, true),
-t′; Z=LocalSpace.Z, name=(:Fdag, :F))
end
# nn interaction
for pairs in neighbor(Latt)
addIntr2!(Root, (LocalSpace.n, LocalSpace.n), pairs,
addIntr!(Root, (LocalSpace.n, LocalSpace.n), pairs, (false, false),
V; name=(:n, :n))
end

# U and μ
for i in 1:size(Latt)
addIntr1!(Root, LocalSpace.nd, i, U; name=:nd)
addIntr1!(Root, LocalSpace.n, i, -μ; name=:n)
addIntr!(Root, LocalSpace.nd, i, U; name=:nd)
addIntr!(Root, LocalSpace.n, i, -μ; name=:n)
end
end

Expand Down
5 changes: 3 additions & 2 deletions example/Hubbard_tanTRG/addPkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ using Pkg
@assert pwd()[end-13:end] == "Hubbard_tanTRG"

Pkg.activate(".")
Pkg.develop(path = "../../")
Pkg.add(url = "https://github.com/Qiaoyi-Li/FiniteLattices.jl.git", rev="dev")
Pkg.add("MKL")
Pkg.add("FiniteMPS")
Pkg.add(url = "https://github.com/Qiaoyi-Li/FiniteLattices.jl.git", rev="dev")


Pkg.resolve()
Pkg.gc()
10 changes: 5 additions & 5 deletions example/Hubbard_tanTRG/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ function U₁SU₂Hubbard(Latt::AbstractLattice; t::Number=1, t′::Number=0, U:
let LocalSpace = U₁SU₂Fermion
# NN hopping
for pairs in neighbor(Latt; ordered=true)
addIntr2!(Root, LocalSpace.FdagF, pairs,
addIntr!(Root, LocalSpace.FdagF, pairs, (true, true),
-t; Z=LocalSpace.Z, name=(:Fdag, :F))
end
# NNN hopping
for pairs in neighbor(Latt; level = 2, ordered=true)
addIntr2!(Root, LocalSpace.FdagF, pairs,
addIntr!(Root, LocalSpace.FdagF, pairs, (true, true),
-t′; Z=LocalSpace.Z, name=(:Fdag, :F))
end
# nn interaction
for pairs in neighbor(Latt)
addIntr2!(Root, (LocalSpace.n, LocalSpace.n), pairs,
addIntr!(Root, (LocalSpace.n, LocalSpace.n), pairs, (false, false),
V; name=(:n, :n))
end

# U and μ
for i in 1:size(Latt)
addIntr1!(Root, LocalSpace.nd, i, U; name=:nd)
addIntr1!(Root, LocalSpace.n, i, -μ; name=:n)
addIntr!(Root, LocalSpace.nd, i, U; name=:nd)
addIntr!(Root, LocalSpace.n, i, -μ; name=:n)
end
end

Expand Down
91 changes: 0 additions & 91 deletions example/deprecate/HubbardDMRG_CBE.jl

This file was deleted.

Loading

0 comments on commit 6e78135

Please sign in to comment.