Skip to content

Commit 1c061c9

Browse files
authored
Fixes an issue with missing duals for spaces in fusers. (#184)
* Fix dual spaces in fusers * Make `DenseMPO` to `TensorMap` converter work for symmetry * Expand tests to include `FiniteMPO` with symmetry
1 parent cd03726 commit 1c061c9

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

src/operators/densempo.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ function Base.convert(::Type{<:AbstractTensorMap}, mpo::FiniteMPO)
8383
U_right = Tensor(ones, scalartype(mpo), V_right')
8484

8585
tensors = vcat(U_left, mpo.opp, U_right)
86-
indices = [[i, -i, -(i + N), i + 1] for i in 1:length(mpo)]
86+
indices = [[i, -i, -(2N - i + 1), i + 1] for i in 1:length(mpo)]
8787
pushfirst!(indices, [1])
8888
push!(indices, [N + 1])
8989
O = ncon(tensors, indices)
9090

91-
return transpose(O, (ntuple(identity, N), ntuple(i -> i + N, N)))
91+
return transpose(O, (ntuple(identity, N), ntuple(i -> 2N - i + 1, N)))
9292
end
9393

9494
# Linear Algebra
@@ -210,7 +210,8 @@ function Base.:*(mpo1::FiniteMPO{TO}, mpo2::FiniteMPO{TO}) where {TO}
210210
Fₗ = i != 1 ? Fᵣ :
211211
isomorphism(A, fuse(left_virtualspace(mpo2, i), left_virtualspace(mpo1, i)),
212212
left_virtualspace(mpo2, i) * left_virtualspace(mpo1, i))
213-
Fᵣ = isomorphism(A, fuse(right_virtualspace(mpo2, i), right_virtualspace(mpo1, i)),
213+
Fᵣ = isomorphism(A,
214+
fuse(right_virtualspace(mpo2, i)', right_virtualspace(mpo1, i)'),
214215
right_virtualspace(mpo2, i)' * right_virtualspace(mpo1, i)')
215216

216217
@plansor O[i][-1 -2; -3 -4] := Fₗ[-1; 1 4] * mpo2[i][1 2; -3 3] *
@@ -232,7 +233,7 @@ function Base.:*(mpo::FiniteMPO, mps::FiniteMPS)
232233
Fₗ = i != 1 ? Fᵣ :
233234
isomorphism(TT, fuse(left_virtualspace(A[i]), left_virtualspace(mpo, i)),
234235
left_virtualspace(A[i]) * left_virtualspace(mpo, i))
235-
Fᵣ = isomorphism(TT, fuse(right_virtualspace(A[i]), right_virtualspace(mpo, i)),
236+
Fᵣ = isomorphism(TT, fuse(right_virtualspace(A[i])', right_virtualspace(mpo, i)'),
236237
right_virtualspace(A[i])' * right_virtualspace(mpo, i)')
237238
@plansor A[i][-1 -2; -3] := Fₗ[-1; 1 3] * A[i][1 2; 4] *
238239
mpo[i][3 -2; 2 5] *

test/operators.jl

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,43 @@ vspaces = (ℙ^10, Rep[U₁]((0 => 20)), Rep[SU₂](1 // 2 => 10, 3 // 2 => 5, 5
1919
@testset "FiniteMPO" begin
2020
# start from random operators
2121
L = 4
22-
O₁ = TensorMap(rand, ComplexF64, (ℂ^2)^L, (ℂ^2)^L)
23-
O₂ = TensorMap(rand, ComplexF64, space(O₁))
22+
T = ComplexF64
2423

25-
# create MPO and convert it back to see if it is the same
26-
mpo₁ = FiniteMPO(O₁) # type-unstable for now!
27-
mpo₂ = FiniteMPO(O₂)
28-
@test convert(TensorMap, mpo₁) O₁
29-
@test convert(TensorMap, -mpo₂) -O₂
24+
for V in (ℂ^2, U1Space(0 => 1, 1 => 1))
25+
O₁ = TensorMap(rand, T, V^L, V^L)
26+
O₂ = TensorMap(rand, T, space(O₁))
3027

31-
# test scalar multiplication
32-
α = rand(ComplexF64)
33-
@test convert(TensorMap, α * mpo₁) α * O₁
34-
@test convert(TensorMap, mpo₁ * α) O₁ * α
28+
# create MPO and convert it back to see if it is the same
29+
mpo₁ = FiniteMPO(O₁) # type-unstable for now!
30+
mpo₂ = FiniteMPO(O₂)
31+
@test convert(TensorMap, mpo₁) O₁
32+
@test convert(TensorMap, -mpo₂) -O₂
3533

36-
# test addition and multiplication
37-
@test convert(TensorMap, mpo₁ + mpo₂) O₁ + O₂
38-
@test convert(TensorMap, mpo₁ * mpo₂) O₁ * O₂
34+
# test scalar multiplication
35+
α = rand(T)
36+
@test convert(TensorMap, α * mpo₁) α * O₁
37+
@test convert(TensorMap, mpo₁ * α) O₁ * α
3938

40-
# test application to a state
41-
ψ₁ = Tensor(rand, ComplexF64, domain(O₁))
42-
mps₁ = FiniteMPS(ψ₁)
39+
# test addition and multiplication
40+
@test convert(TensorMap, mpo₁ + mpo₂) O₁ + O₂
41+
@test convert(TensorMap, mpo₁ * mpo₂) O₁ * O₂
4342

44-
@test convert(TensorMap, mpo₁ * mps₁) O₁ * ψ₁
43+
# test application to a state
44+
ψ₁ = Tensor(rand, T, domain(O₁))
45+
mps₁ = FiniteMPS(ψ₁)
4546

46-
@test dot(mps₁, mpo₁, mps₁) dot(ψ₁, O₁, ψ₁)
47-
@test dot(mps₁, mpo₁, mps₁) dot(mps₁, mpo₁ * mps₁)
48-
# test conversion to and from mps
49-
mpomps₁ = convert(FiniteMPS, mpo₁)
50-
mpompsmpo₁ = convert(FiniteMPO, mpomps₁)
47+
@test convert(TensorMap, mpo₁ * mps₁) O₁ * ψ₁
5148

52-
@test convert(FiniteMPO, mpomps₁) mpo₁ rtol = 1e-6
49+
@test dot(mps₁, mpo₁, mps₁) dot(ψ₁, O₁, ψ₁)
50+
@test dot(mps₁, mpo₁, mps₁) dot(mps₁, mpo₁ * mps₁)
51+
# test conversion to and from mps
52+
mpomps₁ = convert(FiniteMPS, mpo₁)
53+
mpompsmpo₁ = convert(FiniteMPO, mpomps₁)
5354

54-
@test dot(mpomps₁, mpomps₁) dot(mpo₁, mpo₁)
55+
@test convert(FiniteMPO, mpomps₁) mpo₁ rtol = 1e-6
56+
57+
@test dot(mpomps₁, mpomps₁) dot(mpo₁, mpo₁)
58+
end
5559
end
5660

5761
@testset "Finite MPOHamiltonian" begin

0 commit comments

Comments
 (0)