Skip to content

Commit

Permalink
Fix some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Oct 31, 2023
1 parent ffec9de commit 7668e86
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
17 changes: 11 additions & 6 deletions NDTensors/src/blocksparse/linearalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,14 @@ _eigen_eltypes(T::BlockSparseMatrix{ElT}) where {ElT} = complex(ElT), complex(El

function eigen(
T::Union{Hermitian{ElT,<:Tensor{ElT,2,<:BlockSparse}},Tensor{ElT,2,<:BlockSparse}};
kwargs...,
min_blockdim=nothing,
mindim=nothing,
maxdim=nothing,
cutoff=nothing,
use_absolute_cutoff=nothing,
use_relative_cutoff=nothing,
) where {ElT<:Union{Real,Complex}}
truncate = haskey(kwargs, :maxdim) || haskey(kwargs, :cutoff)
truncate = !isnothing(maxdim) || !isnothing(cutoff)

ElD, ElV = _eigen_eltypes(T)

Expand Down Expand Up @@ -247,9 +252,9 @@ function eigen(
sort!(d; rev=true, by=abs)

if truncate
d, truncerr, docut = truncate!!(d; kwargs...)
d, truncerr, docut = truncate!!(d; mindim, maxdim, cutoff, use_absolute_cutoff, use_relative_cutoff)
for n in 1:nnzblocks(T)
blockdim = _truncated_blockdim(Ds[n], docut)
blockdim = _truncated_blockdim(Ds[n], docut; min_blockdim, singular_values=false, truncate)
if blockdim == 0
push!(dropblocks, n)
else
Expand Down Expand Up @@ -340,7 +345,7 @@ qr(T::BlockSparseTensor{<:Any,2}; kwargs...) = qx(qr, T; kwargs...)
# This code thanks to Niklas Tausendpfund
# https://github.com/ntausend/variance_iTensor/blob/main/Hubig_variance_test.ipynb
#
function qx(qx::Function, T::BlockSparseTensor{<:Any,2}; kwargs...)
function qx(qx::Function, T::BlockSparseTensor{<:Any,2}; positive=nothing)
ElT = eltype(T)
# getting total number of blocks
nnzblocksT = nnzblocks(T)
Expand All @@ -351,7 +356,7 @@ function qx(qx::Function, T::BlockSparseTensor{<:Any,2}; kwargs...)

for (jj, b) in enumerate(eachnzblock(T))
blockT = blockview(T, b)
QXb = qx(blockT; kwargs...) #call dense qr at src/linearalgebra.jl 387
QXb = qx(blockT; positive)

if (isnothing(QXb))
return nothing
Expand Down
9 changes: 4 additions & 5 deletions src/mps/mpo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -597,13 +597,12 @@ end

Apply(A::MPO, ψ::MPS; kwargs...) = Applied(apply, (A, ψ), NamedTuple(kwargs))

function contract(A::MPO, ψ::MPS; alg="densitymatrix", kwargs...)
if haskey(kwargs, :method)
# Backwards compatibility, use `method`.
alg = get(kwargs, :method, "densitymatrix")
end
function contract(A::MPO, ψ::MPS; alg=nothing, method=alg, kwargs...)
# TODO: Delete `method` since it is deprecated.
alg = NDTensors.replace_nothing(method, "densitymatrix")

# Keyword argument deprecations
# TODO: Delete these.
if alg == "DensityMatrix"
@warn "In contract, method DensityMatrix is deprecated in favor of densitymatrix"
alg = "densitymatrix"
Expand Down
8 changes: 4 additions & 4 deletions src/tensor_operations/matrix_decomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ function svd(
use_relative_cutoff=nothing,
min_blockdim=nothing,
# Deprecated
utags=nothing,
vtags=nothing,
utags=lefttags,
vtags=righttags,
)
lefttags = NDTensors.replace_nothing(lefttags, ts"Link,u")
righttags = NDTensors.replace_nothing(righttags, ts"Link,v")

# Deprecated
utags = lefttags
vtags = righttags
utags = NDTensors.replace_nothing(utags, ts"Link,u")
vtags = NDTensors.replace_nothing(vtags, ts"Link,v")

Lis = commoninds(A, indices(Linds...))
Ris = uniqueinds(A, Lis)
Expand Down

0 comments on commit 7668e86

Please sign in to comment.