Skip to content

Commit

Permalink
Enforce infiniteMPO to be square
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Dec 18, 2024
1 parent 72a980b commit 5e9a222
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/operators/mpohamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ 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 +237,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 +260,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′

Check warning on line 263 in src/operators/mpohamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/operators/mpohamiltonian.jl#L263

Added line #L263 was not covered by tests

if !ismissing(virtualspaces[i - 1][key_L]) &&
ismissing(virtualspaces[i][key_R])
Expand All @@ -276,12 +276,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 5e9a222

Please sign in to comment.