Skip to content

Commit

Permalink
[ITensorMPS] Fix bug in replace_siteinds
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed May 17, 2024
1 parent d7096d8 commit 6cad2ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/ITensorMPS/src/mps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/lib/ITensorMPS/test/base/test_mps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6cad2ce

Please sign in to comment.