From e84f7fedb776d8e3ed8b34e410f11d90af2efc83 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Fri, 30 Oct 2026 16:07:11 -0400 Subject: [PATCH] Add regression test for long-range SvdCut with identity components Compressing a FiniteMPOHamiltonian with a long-range interaction whose operators have non-zero trace lost precision geometrically with distance in v0.14.0 (#550). This was fixed by the canonical-form rewrite in #539; this test guards against regressions. Co-Authored-By: Claude Opus 5.5 --- test/algorithms/changebonds.jl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/algorithms/changebonds.jl b/test/algorithms/changebonds.jl index 93b894b84..299718221 100644 --- a/test/algorithms/changebonds.jl +++ b/test/algorithms/changebonds.jl @@ -249,6 +249,19 @@ end @test expectation_value(ψ, H′) ≈ expectation_value(ψ, H) rtol = 1.0e-10 end +# Regression for https://github.com/QuantumKitHub/MPSKit.jl/issues/550 +@testset "SvdCut on long-range FiniteMPOHamiltonian with identity components" begin + Random.seed!(1234) + pspace = ℂ^4 + L = 30 + n = TensorMap(ComplexF64[1 0 0 0; 0 0 0 0; 0 0 1 0; 0 0 0 0], pspace ← pspace) + H = FiniteMPOHamiltonian(fill(pspace, L), (5, 25) => n ⊗ n) + + H′ = changebonds(H, SvdCut(; trunc = trunctol(; rtol = 0.0))) + ψ = FiniteMPS(rand, ComplexF64, L, pspace, ℂ^8) + @test expectation_value(ψ, H′) ≈ expectation_value(ψ, H) rtol = 1.0e-10 +end + @testset "SvdCut on InfiniteMPOHamiltonian $(spacetype(pspace))" for (pspace, Dspace) in spacelist Random.seed!(2468) nn = rand(ComplexF64, pspace * pspace, pspace * pspace)