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

Improving infinite mpo matrix #77

Merged
merged 42 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a96ab73
Improvement on InfiniteMPO done, tests left to do
LHerviou Jun 14, 2023
4abfc79
Fixing for dense
LHerviou Jun 15, 2023
397d6e4
Apply suggestions from code review
LHerviou Jun 15, 2023
4817582
Fixing order of downloading
LHerviou Jun 15, 2023
fc72016
Fixing unconventional translations
LHerviou Jun 15, 2023
bef7ee1
Trying to fix format
LHerviou Jun 15, 2023
60191be
Initializing
LHerviou Jun 16, 2023
4c3caa3
Fixing vumps_mpo
LHerviou Jun 16, 2023
1a6a6cf
Implementation of Mat comments
LHerviou Jun 16, 2023
72e84e6
Merge pull request #250 from LHerviou/TemporaryTests
LHerviou Jun 16, 2023
1e8db7d
Working with adhoc add and multiply
LHerviou Jun 20, 2023
ca08705
Introduced propser summation for empty tensors
LHerviou Jun 20, 2023
e3965ef
Testing with newest ITensor
LHerviou Jun 26, 2023
d9bdba5
Testing the fix
LHerviou Jun 26, 2023
aafb7e2
Merge pull request #252 from LHerviou/Temp_Improving
LHerviou Jul 3, 2023
95c892c
Faster construction for long range models. There seems to be a signif…
LHerviou Jul 4, 2023
7ab8adf
Taking into account Mats comments
LHerviou Aug 23, 2023
9167704
Moved a function around, and added a convenience fuse_legs! that do t…
LHerviou Aug 23, 2023
e6988e6
Fixing format
LHerviou Aug 23, 2023
c0c586e
Removed apply_tensor from tests and add the fill! fix as it does not …
LHerviou Aug 23, 2023
ac087d9
Format test
LHerviou Aug 23, 2023
0a0849c
Merge pull request #253 from LHerviou/Temp_ImprovingInfiniteMPOMatrix
LHerviou Aug 23, 2023
e44c58a
Attempt at limiting the number of calls to translatecell
LHerviou Aug 23, 2023
5772ec9
Format
LHerviou Aug 23, 2023
0c8a6cd
Matts comments
LHerviou Aug 24, 2023
559e9c6
Fixing the test
LHerviou Aug 25, 2023
dbd351b
Merge pull request #254 from LHerviou/Temp_ImprovingInfiniteMPOMatrix
LHerviou Aug 25, 2023
334ebf4
Fixing fuse_legs!
LHerviou Aug 25, 2023
7f52678
Merge pull request #255 from LHerviou/Temp_ImprovingInfiniteMPOMatrix
LHerviou Aug 25, 2023
ad42339
Minor bug
LHerviou Aug 25, 2023
0e1d8b5
Merge pull request #256 from LHerviou/Temp_ImprovingInfiniteMPOMatrix
LHerviou Aug 25, 2023
f6b6868
Comments
LHerviou Aug 28, 2023
56b6719
Name change for InfiniteMPOMatrix to InfiniteMPOBlock
LHerviou Aug 28, 2023
bd8f653
Forgot a change in a test, and trying to see if I can remove the fill
LHerviou Aug 28, 2023
4512b02
Restablishing fill
LHerviou Aug 28, 2023
d6c00b8
Merge pull request #257 from LHerviou/Temp_ImprovingInfiniteMPOMatrix
LHerviou Aug 28, 2023
07655f3
Fixing name
LHerviou Aug 28, 2023
a4c24dc
Merge pull request #258 from LHerviou/Temp_ImprovingInfiniteMPOMatrix
LHerviou Aug 28, 2023
39ffc55
Comments + convenience
LHerviou Aug 29, 2023
ece17bc
Format
LHerviou Aug 29, 2023
4c482b2
Bug fix
LHerviou Aug 29, 2023
8da20d1
Cleaning up combineblocks
LHerviou Aug 30, 2023
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
2 changes: 1 addition & 1 deletion src/ITensorInfiniteMPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ include("itensormap.jl")
include("celledvectors.jl")
include("abstractinfinitemps.jl")
include("infinitemps.jl")
include("infinitempo.jl")
include("infinitecanonicalmps.jl")
include("infinitempomatrix.jl")
include("infinitempo.jl")
include("transfermatrix.jl")
include("models/models.jl")
include("models/fqhe13.jl")
Expand Down
10 changes: 10 additions & 0 deletions src/ITensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,13 @@ end
# TODO: make this definition AbstractMPS
# Handle orthogonality center correctly
Base.getindex(ψ::MPS, r::UnitRange{Int}) = MPS([ψ[n] for n in r])

#TODO Remove if everything is working nicely
#Was still crashing on my laptop after updating ITensors
Base.fill!(::NDTensors.NoData, ::Any) = NDTensors.NoData()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a similar definition in ITensor/ITensors.jl#1173, is the definition there not sufficient?


function ITensors.NDTensors.contraction_output(
A::NDTensors.EmptyTensor, B::NDTensors.DiagBlockSparseTensor, label
)
return NDTensors.EmptyTensor(eltype(B), label)
LHerviou marked this conversation as resolved.
Show resolved Hide resolved
end
7 changes: 6 additions & 1 deletion src/celledvectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ _setindex_cell1!(cv::CelledVector, val, n::Int) = (ITensors.data(cv)[n] = val)
function getindex(cv::CelledVector, n::Int)
cellₙ = cell(cv, n)
siteₙ = cellindex(cv, n)
cellₙ == 1 && return _getindex_cell1(cv, siteₙ) #Avoid unnecessary calls
return translatecell(cv.translator, _getindex_cell1(cv, siteₙ), cellₙ - 1)
end

Expand Down Expand Up @@ -169,7 +170,11 @@ getindex(cv::CelledVector, c::Cell) = cv[eachindex(cv, c)]
function setindex!(cv::CelledVector, T, n::Int)
cellₙ = cell(cv, n)
siteₙ = cellindex(cv, n)
_setindex_cell1!(cv, translatecell(cv.translator, T, -(cellₙ - 1)), siteₙ)
if cellₙ == 1
_setindex_cell1!(cv, T, siteₙ)
else
_setindex_cell1!(cv, translatecell(cv.translator, T, -(cellₙ - 1)), siteₙ)
end
return cv
end

Expand Down
105 changes: 105 additions & 0 deletions src/infinitempo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,108 @@ end
translator(mpo::InfiniteMPO) = mpo.data.translator

InfiniteMPO(data::CelledVector{ITensor}) = InfiniteMPO(data, 0, size(data, 1), false)

#
# Hm should have the form below. Only link indices are shown.
#
# I M-->l=n : : :
# l=n-->M l=n-->M-->l=n : : :
# l=n-1-->M l=n-1-->M-->l=n ... ; : :
# : : : : :
# l=1-->M l=1->M-->l=n ... l=1-->M-->l=2 l=1-->M-->l=1 l=1-->M
# M M-->l=n ... M-->l=2 M-->l=1 I
#
# We no longer assume any specific form of the matrix of tensor, and we squash all elements together
# This is facilutated by making all elements of Hm into order(4) tensors by adding dummy Dw=1 indices.
# We use on line then columns ITensors.directsum() to join all the blocks into the final ITensor.
# This code should be 100% dense/blocks-sparse agnostic.
#
function cat_to_itensor(Hm::Matrix{ITensor})
lx, ly = size(Hm)
T = eltype(Hm[1, 1])
left_links, right_links = find_all_links(Hm)
#Start by fusing lines together
Ls = []
new_rs = []
for x in 1:lx
#Formatting issues force me to write this as a loop
input = [Hm[x, 1] * onehot(T, right_links[1] => 1) => right_links[1]]
for y in 2:(ly - 1)
append!(input, [Hm[x, y] => right_links[y]])
end
append!(input, [Hm[x, ly] * onehot(T, right_links[ly] => 1) => right_links[ly]])
H, ir = directsum(input...; tags="Link, right")
if x == 1
append!(new_rs, [ir])
else
replaceinds!(H, [ir], [new_rs[1]])
end
append!(Ls, [H])
end
input = [Ls[1] * onehot(T, left_links[1] => 1) => left_links[1]]
for x in 2:(lx - 1)
append!(input, [Ls[x] => left_links[x]])
end
append!(input, [Ls[lx] * onehot(T, left_links[lx] => 1) => left_links[lx]])
H, new_l = directsum(input...; tags="Link, left")
return H, new_l, new_rs[1]
end
#
# Hm is the InfiniteMPOMatrix
# Hlrs is an array of {ITensor,Index,Index}s, one for each site in the unit cell.
# Hi is a CelledVector of ITensors.
#
function InfiniteMPO(Hm::InfiniteMPOMatrix)
Hlrs = cat_to_itensor.(Hm) #return an array of {ITensor,Index,Index}
#
# Unpack the array of tuples into three arrays. And also get an array site indices.
#
Hi = CelledVector([Hlr[1] for Hlr in Hlrs], translator(Hm))
ils = CelledVector([Hlr[2] for Hlr in Hlrs], translator(Hm))
irs = CelledVector([Hlr[3] for Hlr in Hlrs], translator(Hm))
s = siteinds(Hm)
#
# Create new tags with proper cell and link numbers. Also daisy chain
# all the indices so right index at j = dag(left index at j+1)
#
for j in 1:nsites(Hm)
newTag = "Link,c=$(getcell(s[j])),l=$(getsite(s[j]))"
ir = replacetags(irs[j], tags(irs[j]), newTag) #new right index
Hi[j] = replaceinds(Hi[j], [irs[j]], [ir])
Hi[j + 1] = replaceinds(Hi[j + 1], [ils[j + 1]], [dag(ir)])
end
return InfiniteMPO(Hi)
end

"""
fuse_legs!(Hcl::InfiniteMPO, L, R)

Fuse the non-site legs of the infiniteMPO Hcl and the corresponding left L and right R environments.
Essentially the inverse of splitblocks. It becomes useful for the very dense MPOs once get after compression sometimes.
Hcl is modified on site, L and R are not.
Input: Hcl the infinite MPO
L the left environment (an ITensor)
R the right environment (an ITensor)
Output: the tuple (newL, newR) the updated environments
"""
function fuse_legs!(Hcl::InfiniteMPO, L, R)
LHerviou marked this conversation as resolved.
Show resolved Hide resolved
N = nsites(Hcl)
for j in 1:(N - 1)
right_link = only(commoninds(Hcl[j], Hcl[j + 1]))
comb = combiner(right_link; tags=tags(right_link), dir=dir(right_link))
comb_ind = combinedind(comb)
Hcl.data.data[j] = Hcl[j] * comb
Hcl.data.data[j + 1] = dag(comb) * Hcl[j + 1]
mtfishman marked this conversation as resolved.
Show resolved Hide resolved
end
right_link = only(commoninds(Hcl[N], Hcl[N + 1]))
right_link2 = translatecell(fermion_momentum_translator, right_link, -1)
comb = combiner(right_link; tags=tags(right_link), dir=dir(right_link))
comb_ind = combinedind(comb)
comb2 = translatecell(fermion_momentum_translator, comb, -1)
comb2_ind = combinedind(comb2)
Hcl.data.data[N] = Hcl[N] * comb
Hcl.data.data[1] = dag(comb2) * Hcl[1]
L = L * comb2
R = dag(comb) * R
return L, R
end
Loading
Loading