Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 12 additions & 3 deletions src/operators/mpoham.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,19 @@ function deduce_pspaces(opps::SumOfLocalOperators)
end
end

non_deduced = map(ismissing, pspaces)
any(non_deduced) &&
error("cannot automatically deduce physical spaces at $(findall(non_deduced))")
not_missing = filter(!ismissing, pspaces)

if length(not_missing) != length(pspaces) # Some spaces were not defined / not able to be deduced
if allequal(not_missing) # all non-missing spaces are equal
# fill in the missing spaces with the unique non-missing space
uniquespace = first(not_missing)
for i in eachindex(pspaces)
pspaces[i] = uniquespace
end
else # Not all non-missing spaces are equal
error("cannot automatically deduce physical spaces at $(findall(map(ismissing, pspaces)))")
end
end
return collect(S, pspaces)
end

Expand Down
12 changes: 11 additions & 1 deletion test/mpoham.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MPSKitModels
using MPSKitModels, MPSKit, TensorKit

lattice = InfiniteChain(1)
H1 = @mpoham begin
Expand All @@ -20,3 +20,13 @@ end
H = @mpoham sum(ZZ{i,j} for (i, j) in nearest_neighbours(lattice))
@test length(H) == length(lattice)
end

@testset "deduce_pspaces" begin
# Not fully defining the pspaces should still work
lattice = FiniteChain(5)
H = @mpoham S_zz(){lattice[2],lattice[3]}

@test unique(MPSKit.physicalspace(H))[1] == ComplexSpace(2)

@test_throws Exception @mpoham σˣ(){lattice[1]} + σˣ(; spin=3 // 2){lattice[2]}
end
Loading