Skip to content

Commit

Permalink
Enforce InfiniteMPOHamiltonian to be square (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos authored Dec 18, 2024
1 parent 72a980b commit e8098f6
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/operators/mpohamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ function InfiniteMPOHamiltonian(lattice′::AbstractArray{<:VectorSpace},

# construct the virtual spaces
MissingS = Union{Missing,S}
virtualspaces = PeriodicArray([Vector{MissingS}(missing, maximum(last, K; init=1) + 1)
for K in nonzero_keys])
operator_size = maximum(K -> maximum(last, K; init=1) + 1, nonzero_keys)
virtualspaces = PeriodicArray([Vector{MissingS}(missing, operator_size)
for _ in 1:length(nonzero_keys)])
for V in virtualspaces
V[1] = oneunit(S)
V[end] = oneunit(S)
Expand All @@ -237,7 +238,7 @@ function InfiniteMPOHamiltonian(lattice′::AbstractArray{<:VectorSpace},
for i in 1:length(lattice)
for j in findall(x -> x isa AbstractTensorMap, nonzero_opps[i])
key_L, key_R′ = nonzero_keys[i][j]
key_R = key_R′ == 0 ? length(virtualspaces[i]) : key_R′
key_R = key_R′ == 0 ? operator_size : key_R′
O = nonzero_opps[i][j]

if ismissing(virtualspaces[i - 1][key_L])
Expand All @@ -260,7 +261,7 @@ function InfiniteMPOHamiltonian(lattice′::AbstractArray{<:VectorSpace},
for i in 1:length(lattice)
for j in findall(x -> !(x isa AbstractTensorMap), nonzero_opps[i])
key_L, key_R′ = nonzero_keys[i][j]
key_R = key_R′ == 0 ? length(virtualspaces[i]) : key_R′
key_R = key_R′ == 0 ? operator_size : key_R′

if !ismissing(virtualspaces[i - 1][key_L]) &&
ismissing(virtualspaces[i][key_R])
Expand All @@ -276,12 +277,7 @@ function InfiniteMPOHamiltonian(lattice′::AbstractArray{<:VectorSpace},
end
end

for i in 1:length(lattice)
if any(ismissing, virtualspaces[i])
@warn "missing virtual spaces at site $i: $(findall(ismissing, virtualspaces[i]))"
replace!(virtualspaces[i], missing => oneunit(S))
end
end
foreach(Base.Fix2(replace!, missing => oneunit(S)), virtualspaces)
virtualsumspaces = map(virtualspaces) do V
return SumSpace(collect(S, V))
end
Expand Down

0 comments on commit e8098f6

Please sign in to comment.