@@ -226,8 +226,9 @@ function InfiniteMPOHamiltonian(lattice′::AbstractArray{<:VectorSpace},
226226
227227 # construct the virtual spaces
228228 MissingS = Union{Missing,S}
229- virtualspaces = PeriodicArray ([Vector {MissingS} (missing , maximum (last, K; init= 1 ) + 1 )
230- for K in nonzero_keys])
229+ operator_size = maximum (K -> maximum (last, K; init= 1 ) + 1 , nonzero_keys)
230+ virtualspaces = PeriodicArray ([Vector {MissingS} (missing , operator_size)
231+ for _ in 1 : length (nonzero_keys)])
231232 for V in virtualspaces
232233 V[1 ] = oneunit (S)
233234 V[end ] = oneunit (S)
@@ -237,7 +238,7 @@ function InfiniteMPOHamiltonian(lattice′::AbstractArray{<:VectorSpace},
237238 for i in 1 : length (lattice)
238239 for j in findall (x -> x isa AbstractTensorMap, nonzero_opps[i])
239240 key_L, key_R′ = nonzero_keys[i][j]
240- key_R = key_R′ == 0 ? length (virtualspaces[i]) : key_R′
241+ key_R = key_R′ == 0 ? operator_size : key_R′
241242 O = nonzero_opps[i][j]
242243
243244 if ismissing (virtualspaces[i - 1 ][key_L])
@@ -260,7 +261,7 @@ function InfiniteMPOHamiltonian(lattice′::AbstractArray{<:VectorSpace},
260261 for i in 1 : length (lattice)
261262 for j in findall (x -> ! (x isa AbstractTensorMap), nonzero_opps[i])
262263 key_L, key_R′ = nonzero_keys[i][j]
263- key_R = key_R′ == 0 ? length (virtualspaces[i]) : key_R′
264+ key_R = key_R′ == 0 ? operator_size : key_R′
264265
265266 if ! ismissing (virtualspaces[i - 1 ][key_L]) &&
266267 ismissing (virtualspaces[i][key_R])
@@ -276,12 +277,7 @@ function InfiniteMPOHamiltonian(lattice′::AbstractArray{<:VectorSpace},
276277 end
277278 end
278279
279- for i in 1 : length (lattice)
280- if any (ismissing, virtualspaces[i])
281- @warn " missing virtual spaces at site $i : $(findall (ismissing, virtualspaces[i])) "
282- replace! (virtualspaces[i], missing => oneunit (S))
283- end
284- end
280+ foreach (Base. Fix2 (replace!, missing => oneunit (S)), virtualspaces)
285281 virtualsumspaces = map (virtualspaces) do V
286282 return SumSpace (collect (S, V))
287283 end
0 commit comments