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

[WIP] Start simplifying the necessary OpSum definitions for Models #63

Merged
merged 35 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
fbf3e22
Start simplifying the necessary OpSum definitions for Models
mtfishman Jun 15, 2022
3df8da3
Merge main, fix conflicts
mtfishman Jun 21, 2022
712c9fb
Format
mtfishman Jun 21, 2022
469b8e1
Fix finite to infinite MPS conversion
mtfishman Jun 21, 2022
b2b43ba
New interface for models in terms of unit_cell_terms, defining the te…
mtfishman Jun 22, 2022
b89c072
Rewrite models in terms of new interface
mtfishman Jun 22, 2022
5551250
Replace broken subtraction in OpSum with addition
mtfishman Jun 22, 2022
0e409bf
Start testing examples
mtfishman Jun 23, 2022
e111000
Update examples/vumps/transfer_matrix_spectrum.jl
mtfishman Jun 23, 2022
73ea449
Update src/abstractinfinitemps.jl
mtfishman Jun 23, 2022
f80abc2
Fix path in examples
mtfishman Jun 23, 2022
e1ec11a
Move some old examples to development directory
mtfishman Jun 23, 2022
0637def
Start simplifying interface for defining site indices
mtfishman Jun 23, 2022
a974f02
Update examples for simpler interface
mtfishman Jun 23, 2022
6ae2e23
Continue updating tests for new interface
mtfishman Jun 23, 2022
1186278
Format
mtfishman Jun 23, 2022
82b23c4
Fix more tests
mtfishman Jun 23, 2022
3f98fbc
Clean up tests
mtfishman Jun 23, 2022
a145680
Small test fix
mtfishman Jun 23, 2022
847ac33
Fix Hubbard example, fix more tests
mtfishman Jun 23, 2022
9cfd0d3
Update FQHE example for new interface
mtfishman Jun 23, 2022
f4451e7
Update test/test_vumpsmpo_fqhe.jl
mtfishman Jun 23, 2022
24663c3
Format and clean up code
mtfishman Jun 23, 2022
e4cbe22
Merge branch 'simplify_models' of github.com:mtfishman/ITensorsInfini…
mtfishman Jun 23, 2022
d30675d
Default to V=0 for Hubbard model
mtfishman Jun 24, 2022
baea006
Start updating development examples
mtfishman Jun 27, 2022
742a5aa
Update directsum for latest ITensors interface
mtfishman Jul 15, 2022
275ea00
Update examples/vumps/transfer_matrix_spectrum.jl
mtfishman Jul 15, 2022
1ae9ed4
Update examples/vumps/vumps_heisenberg.jl
mtfishman Jul 15, 2022
b03215c
Format
mtfishman Jul 15, 2022
6221209
Merge branch 'simplify_models' of github.com:mtfishman/ITensorsInfini…
mtfishman Jul 15, 2022
ab7f0cd
Fix examples. Simplify overload requirements for new models
mtfishman Aug 16, 2022
6fa08e1
Format
mtfishman Aug 16, 2022
a6b7279
Fix test
mtfishman Aug 16, 2022
11ce0f8
Clean up code a bit with SplitApplyCombine
mtfishman Aug 16, 2022
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
63 changes: 63 additions & 0 deletions examples/development/finite_mps_to_infinite_mps.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using ITensors
using ITensorInfiniteMPS

# H = -J Σⱼ XⱼXⱼ₊₁ - h Σⱼ Zⱼ
function ising_opsum_infinite(N; J, h)
os = OpSum()
for n in 1:N
os -= J, "X", n, "X", n + 1
end
for n in 1:N
os -= h, "Z", n
end
return os
end

function ising_opsum_finite(N; J, h)
return ising_opsum_infinite(N - 1; J, h) + (-h, "Z", N)
end

function main(; N, J, h, nsites)
s = siteinds("S=1/2", N)

H = MPO(ising_opsum_finite(N; J=J, h=h), s)
ψ0 = randomMPS(s)

energy, ψ = dmrg(H, ψ0; nsweeps=10, cutoff=1e-10)
@show energy / N

n1 = N ÷ 2
n2 = n1 + 1

ψ = orthogonalize(ψ, n1)

println("\nFinite MPS energy on bond (n1, n2) = $((n1, n2))")

ϕ12 = ψ[n1] * ψ[n2]
ham12 = contract(MPO(ising_opsum_infinite(1; J=J, h=h), [s[n1], s[n2]]))
@show inner(ϕ12, apply(ham12, ϕ12))

# Get an infinite MPS that approximates
# the finite MPS in the bulk.
# `nsites` sets the number of sites in the unit
# cell of the infinite MPS.
ψ∞ = infinitemps_approx(ψ; nsites=nsites, nsweeps=10)

println("\nInfinite MPS energy on a few different bonds")
println("Infinite MPS has unit cell of size $nsites")

# Compute a few energies
for n1 in 1:3
n2 = n1 + 1
@show n1, n2
ϕ12 = ψ∞.AL[n1] * ψ∞.AL[n2] * ψ∞.C[n2]
s1 = siteind(ψ∞, n1)
s2 = siteind(ψ∞, n2)
ham12 = contract(MPO(ising_opsum_infinite(1; J=J, h=h), [s1, s2]))
@show inner(ϕ12, apply(ham12, ϕ12)) / norm(ϕ12)
end

return nothing
end

main(; N=100, J=1.0, h=1.5, nsites=1)
19 changes: 19 additions & 0 deletions examples/development/orthogonalize_infinitemps.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using ITensors
using ITensorInfiniteMPS
using Random

Random.seed!(1234)

# n-site unit cell
nsites = 4
s = siteinds("S=1/2", nsites; conserve_szparity=true)
χ = 10
@assert iseven(χ)
space = (("SzParity", 1, 2) => χ ÷ 2) ⊕ (("SzParity", 0, 2) => χ ÷ 2)
ψ = InfiniteMPS(ComplexF64, s; space=space)
for n in 1:nsites
ψ[n] = randomITensor(inds(ψ[n]))
end

ψ = orthogonalize(ψ, :)
@show norm(contract(ψ.AL[1:nsites]) * ψ.C[nsites] - ψ.C[0] * contract(ψ.AR[1:nsites]))
112 changes: 0 additions & 112 deletions examples/finite_mps_to_infinite_mps.jl

This file was deleted.

20 changes: 0 additions & 20 deletions examples/infinitemps.jl

This file was deleted.

15 changes: 8 additions & 7 deletions examples/vumps/transfer_matrix_spectrum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ nfinite = Nfinite ÷ 2
orthogonalize!(ψfinite, nfinite)
hnfinite = ITensor(model, sfinite[nfinite], sfinite[nfinite + 1]; model_params...)
energy_finite = energy_local(ψfinite[nfinite], ψfinite[nfinite + 1], hnfinite)
energy_infinite = energy_local(ψ.AL[1], ψ.AL[2] * ψ.C[2], H[(1, 2)])
energy_infinite = energy_local(ψ.AL[1], ψ.AL[2] * ψ.C[2], contract(H[(1, 2)]))
@show energy_finite, energy_infinite
@show abs(energy_finite - energy_infinite)

Expand All @@ -115,7 +115,7 @@ Sz2_infinite = expect(ψ.AL[2] * ψ.C[2], "Sz")
#

using Arpack
using KrylovKit
using KrylovKit: eigsolve
using LinearAlgebra

T = TransferMatrix(ψ.AL)
Expand All @@ -138,7 +138,7 @@ tol = 1e-10
neigs = length(v⃗ᴿ)

# Normalize the vectors
N⃗ = [(translatecell(v⃗ᴸ[n], 1) * v⃗ᴿ[n])[] for n in 1:neigs]
N⃗ = [(translatecelltags(v⃗ᴸ[n], 1) * v⃗ᴿ[n])[] for n in 1:neigs]

v⃗ᴿ ./= sqrt.(N⃗)
v⃗ᴸ ./= sqrt.(N⃗)
Expand All @@ -152,18 +152,19 @@ function proj(v⃗ᴸ, v⃗ᴿ, n)
Lⁿ = v⃗ᴸ[n]
Rⁿ = v⃗ᴿ[n]
return ITensorMap(
[translatecell(Lⁿ, 1), translatecell(Rⁿ, -1)]; input_inds=inds(Rⁿ), output_inds=inds(Lⁿ)
[translatecelltags(Lⁿ, 1), translatecelltags(Rⁿ, -1)]; input_inds=inds(Rⁿ), output_inds=inds(Lⁿ)
mtfishman marked this conversation as resolved.
Show resolved Hide resolved
)
end

P⃗ = [proj(v⃗ᴸ, v⃗ᴿ, n) for n in 1:neigs]
T⁻P = T - sum(P⃗)

#vⁱᴿ² = vⁱᴿ - (translatecell(v⃗ᴸ[1], 1) * vⁱᴿ)[] / norm(v⃗ᴿ[1]) * v⃗ᴿ[1]
#vⁱᴿ² = vⁱᴿ - (translatecelltags(v⃗ᴸ[1], 1) * vⁱᴿ)[] / norm(v⃗ᴿ[1]) * v⃗ᴿ[1]
#@show norm(dag(vⁱᴿ²) * v⃗ᴿ[1])

λ⃗ᴾᴿ, v⃗ᴾᴿ, right_info = eigsolve(T⁻P, vⁱᴿ, neigs, :LM; tol=tol)
@show λ⃗ᴾᴿ
# XXX: Error with mismatched QN index arrows
# λ⃗ᴾᴿ, v⃗ᴾᴿ, right_info = eigsolve(T⁻P, vⁱᴿ, neigs, :LM; tol=tol)
# @show λ⃗ᴾᴿ

vⁱᴿ⁻ᵈᵃᵗᵃ = vec(array(vⁱᴿ))
λ⃗ᴿᴬ, v⃗ᴿ⁻ᵈᵃᵗᵃ = Arpack.eigs(T; v0=vⁱᴿ⁻ᵈᵃᵗᵃ, nev=neigs)
Expand Down
6 changes: 3 additions & 3 deletions examples/vumps/vumps_heisenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ subspace_expansion_kwargs = (cutoff=cutoff, maxdim=maxdim)
ψ = vumps(H, ψ; vumps_kwargs...)

# Alternate steps of running VUMPS and increasing the bond dimension
for _ in 1:outer_iters
@time for _ in 1:outer_iters
println("\nIncrease bond dimension")
global ψ = subspace_expansion(ψ, H; subspace_expansion_kwargs...)
global ψ = @time subspace_expansion(ψ, H; subspace_expansion_kwargs...)
println("Run VUMPS with new bond dimension")
global ψ = vumps(H, ψ; vumps_kwargs...)
global ψ = @time vumps(H, ψ; vumps_kwargs...)
end

# Check translational invariance
Expand Down
11 changes: 6 additions & 5 deletions examples/vumps/vumps_ising_extended.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ using ITensorInfiniteMPS

maxdim = 64 # Maximum bond dimension
cutoff = 1e-6 # Singular value cutoff when increasing the bond dimension
max_vumps_iters = 100 # Maximum number of iterations of the VUMPS algorithm at each bond dimension
max_vumps_iters = 10 # Maximum number of iterations of the VUMPS algorithm at each bond dimension
vumps_tol = 1e-6
outer_iters = 10 # Number of times to increase the bond dimension
eager = true

##############################################################################
# CODE BELOW HERE DOES NOT NEED TO BE MODIFIED
#
N = 3# Number of sites in the unit cell
N = 3 # Number of sites in the unit cell
J = -1.0
J₂ = -0.2
h = 1.0;
Expand Down Expand Up @@ -53,17 +53,18 @@ sfinite = siteinds("S=1/2", Nfinite; conserve_szparity=true)
Hfinite = MPO(model, sfinite; J=J, J₂=J₂, h=h)
ψfinite = randomMPS(sfinite, initstate; linkdims=10)
@show flux(ψfinite)
sweeps = Sweeps(10)
setmaxdim!(sweeps, maxdim)
setcutoff!(sweeps, cutoff)
dmrg_kwargs = (nsweeps=10, maxdim, cutoff)
energy_finite_total, ψfinite = dmrg(Hfinite, ψfinite; dmrg_kwargs...)
energy_finite_total, ψfinite = dmrg(Hfinite, ψfinite, sweeps)

nfinite = Nfinite ÷ 2
Sz_finite = expect(ψfinite, "Sz")[nfinite:(nfinite + N - 1)]

println("\nEnergy")
@show energy_infinite
@show energy_finite_total / Nfinite
@show reference(model, Observable("energy"); J=J, h=h, J₂=J₂)

println("\nSz")
@show Sz
@show Sz_finite
1 change: 1 addition & 0 deletions src/ITensorInfiniteMPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export Cell,
reference,
subspace_expansion,
translatecell,
translatecelltags,
translator,
tdvp,
vumps,
Expand Down
12 changes: 10 additions & 2 deletions src/abstractinfinitemps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,21 @@ end

# TODO: return a Dictionary or IndexSetNetwork?
function ITensors.siteinds(ψ::AbstractInfiniteMPS, r::AbstractRange)
return [siteinds(ψ, n) for n in r]
return [siteind(ψ, n) for n in r]
end

siterange(ψ::AbstractInfiniteMPS, c::Cell) = 1:(nsites(ψ) .+ (c.cell - 1))
function siterange(ψ::AbstractInfiniteMPS, c::Cell)
#1:(nsites(ψ) .+ (c.cell - 1))
start = nsites(ψ) * (c.cell - 1) + 1
stop = start + nsites(ψ) - 1
return start:stop
end

ITensors.siteinds(ψ::AbstractInfiniteMPS, c::Cell) = siteinds(ψ, siterange(ψ, c))

ITensors.siteinds(ψ::AbstractInfiniteMPS) = CelledVector(siteinds(ψ, Cell(1)), translator(ψ))
mtfishman marked this conversation as resolved.
Show resolved Hide resolved
infsiteinds(ψ::AbstractInfiniteMPS) = siteinds(ψ)

Base.getindex(ψ::AbstractInfiniteMPS, r::UnitRange{Int}) = MPS([ψ[n] for n in r])

struct UnitRangeToFunction{T<:Real,F<:Function}
Expand Down
13 changes: 9 additions & 4 deletions src/celledvectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ function translatecell(translator::Function, is::Union{<:Tuple,<:Vector}, n::Int
return translatecell.(translator, is, n)
end

#Default behavior
#translatecell(T::ITensor, n::Integer) = ITensors.setinds(T, translatecell(inds(T), n))
# Default behavior
translatecelltags(T::ITensor, n::Integer) = translatecell(translatecelltags, T, n)
translatecelltags(T::ITensors.Indices, n::Integer) = translatecell(translatecelltags, T, n)
#translatecell(T::MPO, n::Integer) = translatecell.(T, n)
#translatecell(T::Matrix{ITensor}, n::Integer) = translatecell.(T, n)

Expand Down Expand Up @@ -99,11 +100,15 @@ function CelledVector{T}(v::Vector{T}, translator::Function) where {T}
end

"""
celllength(cv::CelledVector)
cell_length(cv::CelledVector)

celllength(cv::CelledVector) # Deprecated

The length of a unit cell of a CelledVector.
"""
celllength(cv::CelledVector) = length(ITensors.data(cv))
cell_length(cv::CelledVector) = length(ITensors.data(cv))

celllength(cv::CelledVector) = cell_length(cv)

# For compatibility with Base
Base.size(cv::CelledVector) = size(ITensors.data(cv))
Expand Down
Loading