From 2fd20b06877c4111cad319f41db72374144edfff Mon Sep 17 00:00:00 2001 From: mtfishman Date: Wed, 10 Jan 2024 11:49:35 -0500 Subject: [PATCH 1/3] [ITensors] Fix eigen_perturbation rank --- src/tensor_operations/matrix_decomposition.jl | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/tensor_operations/matrix_decomposition.jl b/src/tensor_operations/matrix_decomposition.jl index c288b8348d..22622c3817 100644 --- a/src/tensor_operations/matrix_decomposition.jl +++ b/src/tensor_operations/matrix_decomposition.jl @@ -781,13 +781,19 @@ function factorize( Lis = commoninds(A, indices(Linds...)) Ris = uniqueinds(A, Lis) dL, dR = dim(Lis), dim(Ris) - # maxdim is forced to be at most the max given SVD - if isnothing(maxdim) - maxdim = min(dL, dR) + if isnothing(eigen_perturbation) + # maxdim is forced to be at most the max given SVD + if isnothing(maxdim) + maxdim = min(dL, dR) + end + maxdim = min(maxdim, min(dL, dR)) + else + if isnothing(maxdim) + maxdim = max(dL, dR) + end + maxdim = min(maxdim, max(dL, dR)) end - maxdim = min(maxdim, min(dL, dR)) might_truncate = !isnothing(cutoff) || maxdim < min(dL, dR) - if isnothing(which_decomp) if !might_truncate && ortho != "none" which_decomp = "qr" From 912fbfaa0301c5a12a98460d271a641015357b58 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Tue, 16 Jan 2024 12:30:02 -0500 Subject: [PATCH 2/3] Add test --- test/base/test_decomp.jl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/base/test_decomp.jl b/test/base/test_decomp.jl index a4c8fc1554..c43c900a28 100644 --- a/test/base/test_decomp.jl +++ b/test/base/test_decomp.jl @@ -136,6 +136,25 @@ end ) end + @testset "factorize with eigen_perturbation dimensions" begin + elt = Float64 + di = 10 + dj = 5 + maxdim = di - 1 + i = Index(di, "i") + j = Index(dj, "j") + a = randomITensor(elt, i, j) + δ = randomITensor(elt, i, j) + δ² = prime(δ, i) * dag(δ) + a² = prime(a, i) * dag(a) + x, y = factorize(a, i; ortho="left", which_decomp="eigen", maxdim) + l = commonind(x, y) + @test dim(l) == dj + xδ, yδ = factorize(a, i; ortho="left", which_decomp="eigen", eigen_perturbation=δ², maxdim) + lδ = commonind(xδ, yδ) + @test dim(lδ) == maxdim + end + @testset "QR/RQ/QL/LQ decomp on MPS dense $elt tensor with all possible collections on Q/R/L" for ninds in [ 0, 1, 2, 3 From 223a55091550c2011fa75edf1466a3f257f5dc21 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Tue, 16 Jan 2024 12:33:35 -0500 Subject: [PATCH 3/3] Format Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- test/base/test_decomp.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/base/test_decomp.jl b/test/base/test_decomp.jl index c43c900a28..99c9781660 100644 --- a/test/base/test_decomp.jl +++ b/test/base/test_decomp.jl @@ -150,7 +150,9 @@ end x, y = factorize(a, i; ortho="left", which_decomp="eigen", maxdim) l = commonind(x, y) @test dim(l) == dj - xδ, yδ = factorize(a, i; ortho="left", which_decomp="eigen", eigen_perturbation=δ², maxdim) + xδ, yδ = factorize( + a, i; ortho="left", which_decomp="eigen", eigen_perturbation=δ², maxdim + ) lδ = commonind(xδ, yδ) @test dim(lδ) == maxdim end