Skip to content

Commit 68cc1e8

Browse files
authored
Use default link tags in movesites (#137)
1 parent 08b134d commit 68cc1e8

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/abstractmps.jl

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,20 @@ function setindex!(
19071907
end
19081908
end
19091909

1910-
ψA = MPST(A, sites; leftinds=lind, orthocenter=orthocenter - first(r) + 1, kwargs...)
1910+
# use the first link index if present, otherwise use the default tag
1911+
linktags = TagSet[
1912+
(b = linkind(ψ, i);
1913+
isnothing(b) ? defaultlinkindtags(i) : tags(b)) for i in firstsite:(lastsite - 1)
1914+
]
1915+
1916+
ψA = MPST(
1917+
A,
1918+
sites;
1919+
leftinds=lind,
1920+
orthocenter=orthocenter - first(r) + 1,
1921+
tags=linktags,
1922+
kwargs...,
1923+
)
19111924
#@assert prod(ψA) ≈ A
19121925

19131926
ψ[firstsite:lastsite] = ψA
@@ -1942,11 +1955,20 @@ by site according to the site indices `sites`.
19421955
in `sites` and `leftinds` will be dangling off of the right side of the MPS/MPO.
19431956
- `orthocenter::Integer = length(sites)`: the desired final orthogonality
19441957
center of the output MPS/MPO.
1958+
- `tags = [defaultlinktags(i) for i in 1:(length(sites) - 1)]`:
1959+
the tags to use for the link indices. The length of `tags` must be
1960+
`length(sites) - 1`. The default is to use the default link tags for each
1961+
site.
19451962
- `cutoff`: the desired truncation error at each link.
19461963
- `maxdim`: the maximum link dimension.
19471964
"""
19481965
function (::Type{MPST})(
1949-
A::ITensor, sites; leftinds=nothing, orthocenter::Integer=length(sites), kwargs...
1966+
A::ITensor,
1967+
sites;
1968+
leftinds=nothing,
1969+
orthocenter::Integer=length(sites),
1970+
tags=[defaultlinktags(i) for i in 1:(length(sites) - 1)],
1971+
kwargs...,
19501972
) where {MPST<:AbstractMPS}
19511973
N = length(sites)
19521974
for s in sites
@@ -1967,7 +1989,7 @@ function (::Type{MPST})(
19671989
if !isnothing(l)
19681990
Lis = unioninds(Lis, l)
19691991
end
1970-
L, R = factorize(Ã, Lis; kwargs..., tags="Link,n=$n", ortho="left")
1992+
L, R = factorize(Ã, Lis; kwargs..., tags=tags[n], ortho="left")
19711993
l = commonind(L, R)
19721994
ψ[n] = L
19731995
= R

test/base/test_mps.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,18 @@ end
14241424
end
14251425
end
14261426

1427+
@testset "movesites tags" begin
1428+
N = 4
1429+
s0 = siteinds("S=1/2", N)
1430+
ψ0 = random_mps(s0; linkdims=1)
1431+
for perm in permutations(1:N)
1432+
s = s0[perm]
1433+
ns′ = [findfirst(==(i), s0) for i in s]
1434+
ψ = movesites(ψ0, 1:N .=> ns′; cutoff=1e-15)
1435+
@test ITensorMPS.hasdefaultlinktags(ψ)
1436+
end
1437+
end
1438+
14271439
@testset "product(::Vector{ITensor}, ::MPS)" begin
14281440
N = 6
14291441
s = siteinds("Qubit", N)

0 commit comments

Comments
 (0)