diff --git a/Project.toml b/Project.toml index f6c5866f0..740f72d0f 100644 --- a/Project.toml +++ b/Project.toml @@ -37,7 +37,7 @@ MPSKitAdaptExt = "Adapt" [compat] Accessors = "0.1" Adapt = "4" -BlockTensorKit = "0.3.16" +BlockTensorKit = "0.3.19" Compat = "3.47, 4.10" DocStringExtensions = "0.9.3" HalfIntegers = "1.6.0" diff --git a/src/operators/ortho.jl b/src/operators/ortho.jl index de7d00200..9ea1f64a5 100644 --- a/src/operators/ortho.jl +++ b/src/operators/ortho.jl @@ -50,7 +50,7 @@ function left_canonicalize!( if dim(R) == 0 # fully truncated V = _rightunit ⊞ _rightunit - Q1 = typeof(WA)(undef, SumSpace{S}() ⊗ P ← P ⊗ SumSpace{S}()) + Q1 = typeof(WA)(undef, codomain(WA) ← P ⊗ SumSpace{S}()) Q2 = typeof(WC)(undef, P ← P ⊗ SumSpace{S}()) else scale!(Q, d) @@ -144,7 +144,7 @@ function right_canonicalize!( R, Q = right_orth!(tmp; alg) if dim(R) == 0 V = _rightunit ⊞ _rightunit - Q1 = typeof(WA)(undef, SumSpace{S}() ⊗ P ← P ⊗ SumSpace{S}()) + Q1 = typeof(WA)(undef, SumSpace{S}() ⊗ P ← domain(WA)) Q2 = typeof(WB)(undef, SumSpace{S}() ⊗ P ← P) else scale!(Q, d) diff --git a/test/hamiltonian/finite.jl b/test/hamiltonian/finite.jl index 950f855fc..e3c266249 100644 --- a/test/hamiltonian/finite.jl +++ b/test/hamiltonian/finite.jl @@ -109,6 +109,46 @@ using TensorKit: ℙ end end +@testset "Finite MPOHamiltonian canonicalization with decoupled sites" begin + # regression test for https://github.com/QuantumKitHub/MPSKit.jl/issues/522 + T = ComplexF64 + for V in (ℂ^2, U1Space(-1 => 1, 0 => 1, 1 => 1), Rep[SU₂](1 // 2 => 1)) + O₁ = randn(T, V, V) + O₁ += O₁' + O₂ = randn(T, V^2 ← V^2) + O₂ += O₂' + E = id(storagetype(O₁), domain(O₁)) + + # bulk block of the middle site is empty on the left but not on the right + H_right = FiniteMPOHamiltonian(fill(V, 3), (1,) => O₁, (2, 3) => O₂) + H_right_tm = O₁ ⊗ E ⊗ E + E ⊗ O₂ + H = MPSKit.right_canonicalize!(copy(H_right), 2) + @test convert(TensorMap, H) ≈ H_right_tm + + # bulk block of the middle site is empty on the right but not on the left + H_left = FiniteMPOHamiltonian(fill(V, 3), (1, 2) => O₂, (3,) => O₁) + H_left_tm = O₂ ⊗ E + E ⊗ E ⊗ O₁ + H = MPSKit.left_canonicalize!(copy(H_left), 2) + @test convert(TensorMap, H) ≈ H_left_tm + + L = 5 + H5 = FiniteMPOHamiltonian(fill(V, L), (1, 2) => O₂, (3,) => O₁, (4, 5) => O₂) + H5_tm = O₂ ⊗ E ⊗ E ⊗ E + E ⊗ E ⊗ O₁ ⊗ E ⊗ E + E ⊗ E ⊗ E ⊗ O₂ + H = copy(H5) + for i in L:-1:2 + MPSKit.right_canonicalize!(H, i) + end + @test convert(TensorMap, H) ≈ H5_tm + for i in 1:(L - 1) + MPSKit.left_canonicalize!(H, i) + end + @test convert(TensorMap, H) ≈ H5_tm + + H5_trunc = changebonds(H5, SvdCut(; trunc = truncrank(16))) + @test convert(TensorMap, H5_trunc) ≈ H5_tm + end +end + @testset "Finite MPOHamiltonian repeated indices" begin X = randn(ComplexF64, ℂ^2, ℂ^2) X += X'