Skip to content

Commit b6e6f1d

Browse files
relax deduce_pspaces
1 parent 1dc9592 commit b6e6f1d

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/operators/mpoham.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,18 @@ function deduce_pspaces(opps::SumOfLocalOperators)
8383
end
8484

8585
non_deduced = map(ismissing, pspaces)
86-
any(non_deduced) &&
87-
error("cannot automatically deduce physical spaces at $(findall(non_deduced))")
8886

87+
if any(non_deduced) # Some spaces were not defined / not able to be deduced
88+
if allequal(filter(!ismissing, pspaces)) # all non-missing spaces are equal
89+
# fill in the missing spaces with the unique non-missing space
90+
uniquespace = first(filter(!ismissing, pspaces))
91+
for i in eachindex(pspaces)
92+
pspaces[i] = uniquespace
93+
end
94+
else # Not all non-missing spaces are equal
95+
error("cannot automatically deduce physical spaces at $(findall(non_deduced))")
96+
end
97+
end
8998
return collect(S, pspaces)
9099
end
91100

test/mpoham.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using MPSKitModels
1+
using MPSKitModels, MPSKit, TensorKit
22

33
lattice = InfiniteChain(1)
44
H1 = @mpoham begin
@@ -20,3 +20,13 @@ end
2020
H = @mpoham sum(ZZ{i,j} for (i, j) in nearest_neighbours(lattice))
2121
@test length(H) == length(lattice)
2222
end
23+
24+
@testset "deduce_pspaces" begin
25+
# Not fully defining the pspaces should still work
26+
lattice = FiniteChain(5)
27+
H = @mpoham S_zz(){lattice[2],lattice[3]}
28+
29+
@test unique(MPSKit.physicalspace(H))[1] == ComplexSpace(2)
30+
31+
@test_throws Exception @mpoham σˣ(){lattice[1]} + σˣ(; spin=3 // 2){lattice[2]}
32+
end

0 commit comments

Comments
 (0)