Skip to content

Commit

Permalink
[ITensors] Add missing kwargs to replacebond! and downstream functi…
Browse files Browse the repository at this point in the history
…ons (#1300)
  • Loading branch information
brian-dellabetta authored Jan 4, 2024
1 parent 41ae408 commit 921f362
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/mps/mps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,11 @@ function replacebond!(
maxdim=nothing,
cutoff=nothing,
eigen_perturbation=nothing,
# svd kwargs
svd_alg=nothing,
use_absolute_cutoff=nothing,
use_relative_cutoff=nothing,
min_blockdim=nothing,
)
normalize = NDTensors.replace_nothing(normalize, false)
swapsites = NDTensors.replace_nothing(swapsites, false)
Expand All @@ -563,6 +567,9 @@ function replacebond!(
eigen_perturbation,
svd_alg,
tags=tags(linkind(M, b)),
use_absolute_cutoff,
use_relative_cutoff,
min_blockdim,
)
M[b] = L
M[b + 1] = R
Expand Down
46 changes: 43 additions & 3 deletions src/tensor_operations/matrix_decomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,9 @@ function factorize_svd(
maxdim=nothing,
cutoff=nothing,
tags=nothing,
use_absolute_cutoff=nothing,
use_relative_cutoff=nothing,
min_blockdim=nothing,
)
leftdir, rightdir = dir, dir
if !isnothing(leftdir)
Expand All @@ -619,6 +622,9 @@ function factorize_svd(
cutoff,
lefttags=tags,
righttags=tags,
use_absolute_cutoff,
use_relative_cutoff,
min_blockdim,
)
if isnothing(USV)
return nothing
Expand Down Expand Up @@ -651,6 +657,8 @@ function factorize_eigen(
maxdim=nothing,
cutoff=nothing,
tags=nothing,
use_absolute_cutoff=nothing,
use_relative_cutoff=nothing,
)
if ortho == "left"
Lis = commoninds(A, indices(Linds...))
Expand All @@ -669,7 +677,18 @@ function factorize_eigen(
delta_A2 = noprime(delta_A2)
A2 += delta_A2
end
F = eigen(A2, Lis, simLis; ishermitian=true, mindim, maxdim, cutoff, tags)
F = eigen(
A2,
Lis,
simLis;
ishermitian=true,
mindim,
maxdim,
cutoff,
tags,
use_absolute_cutoff,
use_relative_cutoff,
)
D, _, spec = F
L = F.Vt
R = dag(L) * A
Expand Down Expand Up @@ -780,15 +799,36 @@ function factorize(
end
if which_decomp == "svd"
LR = factorize_svd(
A, Linds...; mindim, maxdim, cutoff, tags, ortho, alg=svd_alg, dir, singular_values!
A,
Linds...;
mindim,
maxdim,
cutoff,
tags,
ortho,
alg=svd_alg,
dir,
singular_values!,
use_absolute_cutoff,
use_relative_cutoff,
min_blockdim,
)
if isnothing(LR)
return nothing
end
L, R, spec = LR
elseif which_decomp == "eigen"
L, R, spec = factorize_eigen(
A, Linds...; mindim, maxdim, cutoff, tags, ortho, eigen_perturbation
A,
Linds...;
mindim,
maxdim,
cutoff,
tags,
ortho,
eigen_perturbation,
use_absolute_cutoff,
use_relative_cutoff,
)
elseif which_decomp == "qr"
L, R = factorize_qr(A, Linds...; ortho, tags)
Expand Down
15 changes: 15 additions & 0 deletions test/ITensorLegacyMPS/base/test_mps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,21 @@ include(joinpath(@__DIR__, "utils", "util.jl"))
replacebond!(psi, 5, phi; ortho="left")
@test ITensors.leftlim(psi) == 3
@test ITensors.rightlim(psi) == 7

# check that replacebond! runs with svd kwargs
psi = randomMPS(sites)
phi = psi[1] * psi[2]
replacebond!(psi, 1, phi; ortho="left", which_decomp="svd", use_relative_cutoff=true)
phi = psi[5] * psi[6]
replacebond!(
psi,
5,
phi;
ortho="right",
which_decomp="svd",
use_absolute_cutoff=true,
min_blockdim=2,
)
end
end

Expand Down

0 comments on commit 921f362

Please sign in to comment.