From 6cad2ce9c76ae8b7ae76987af2933a50d9a1d08e Mon Sep 17 00:00:00 2001 From: mtfishman Date: Fri, 17 May 2024 12:57:54 -0400 Subject: [PATCH] [ITensorMPS] Fix bug in replace_siteinds --- src/lib/ITensorMPS/src/mps.jl | 4 ++-- src/lib/ITensorMPS/test/base/test_mps.jl | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/ITensorMPS/src/mps.jl b/src/lib/ITensorMPS/src/mps.jl index 42c15b93ab..ef462a8462 100644 --- a/src/lib/ITensorMPS/src/mps.jl +++ b/src/lib/ITensorMPS/src/mps.jl @@ -516,8 +516,8 @@ SiteTypes.siteinds(M::MPS; kwargs...) = siteinds(first, M; kwargs...) function replace_siteinds!(M::MPS, sites) for j in eachindex(M) - sj = siteind(only, M, j) - replaceind!(M[j], sj, sites[j]) + sj = only(siteinds(M, j)) + M[j] = replaceinds(M[j], sj => sites[j]) end return M end diff --git a/src/lib/ITensorMPS/test/base/test_mps.jl b/src/lib/ITensorMPS/test/base/test_mps.jl index 7d07139ed8..8dce11c1e2 100644 --- a/src/lib/ITensorMPS/test/base/test_mps.jl +++ b/src/lib/ITensorMPS/test/base/test_mps.jl @@ -271,6 +271,17 @@ include(joinpath(@__DIR__, "utils", "util.jl")) end end + @testset "replace_siteinds" begin + s = siteinds("S=1/2", 4) + x = MPS(s, j -> isodd(j) ? "↑" : "↓") + @test siteinds(x) == s + t = sim.(s) + y = replace_siteinds(x, t) + @test siteinds(y) == t + # Regression test for https://github.com/ITensor/ITensors.jl/issues/1439. + @test siteinds(x) == s + end + @testset "copy and deepcopy" begin s = siteinds("S=1/2", 3) M1 = random_mps(s; linkdims=3)