Skip to content

Commit 5879c1b

Browse files
Relax deduce_pspaces (#51)
* relax `deduce_pspaces` * avoid recomputations
1 parent f64f858 commit 5879c1b

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/operators/mpoham.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,19 @@ function deduce_pspaces(opps::SumOfLocalOperators)
8282
end
8383
end
8484

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

87+
if length(not_missing) != length(pspaces) # Some spaces were not defined / not able to be deduced
88+
if allequal(not_missing) # all non-missing spaces are equal
89+
# fill in the missing spaces with the unique non-missing space
90+
uniquespace = first(not_missing)
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(map(ismissing, pspaces)))")
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)