From 921f3628041464d65a427e670da15157e6efbfc6 Mon Sep 17 00:00:00 2001 From: Brian Dellabetta Date: Thu, 4 Jan 2024 15:04:34 -0600 Subject: [PATCH] [ITensors] Add missing kwargs to `replacebond!` and downstream functions (#1300) --- src/mps/mps.jl | 7 +++ src/tensor_operations/matrix_decomposition.jl | 46 +++++++++++++++++-- test/ITensorLegacyMPS/base/test_mps.jl | 15 ++++++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/mps/mps.jl b/src/mps/mps.jl index 67458f07a9..a6bec60f96 100644 --- a/src/mps/mps.jl +++ b/src/mps/mps.jl @@ -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) @@ -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 diff --git a/src/tensor_operations/matrix_decomposition.jl b/src/tensor_operations/matrix_decomposition.jl index 2ce37a4355..c288b8348d 100644 --- a/src/tensor_operations/matrix_decomposition.jl +++ b/src/tensor_operations/matrix_decomposition.jl @@ -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) @@ -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 @@ -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...)) @@ -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 @@ -780,7 +799,19 @@ 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 @@ -788,7 +819,16 @@ function factorize( 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) diff --git a/test/ITensorLegacyMPS/base/test_mps.jl b/test/ITensorLegacyMPS/base/test_mps.jl index f2a3e73e1e..d7fa17b696 100644 --- a/test/ITensorLegacyMPS/base/test_mps.jl +++ b/test/ITensorLegacyMPS/base/test_mps.jl @@ -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