Skip to content

Commit ef39e51

Browse files
Katharine Hyattkshyatt
authored andcommitted
New truncation strategy for degenerate clusters
1 parent b4b94b4 commit ef39e51

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎Project.toml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ FiniteDifferences = "0.12"
5757
GPUArrays = "11.4.1"
5858
LRUCache = "1.6"
5959
LinearAlgebra = "1"
60-
MatrixAlgebraKit = "0.6.9"
60+
MatrixAlgebraKit = "0.6.11"
6161
Mooncake = "0.5.27"
6262
OhMyThreads = "0.8.0"
6363
PrecompileTools = "1"
@@ -72,3 +72,6 @@ TimerOutputs = "1"
7272
TupleTools = "1.5"
7373
VectorInterface = "0.6, 0.7"
7474
julia = "1.10"
75+
76+
[sources]
77+
MatrixAlgebraKit = {url = "https://github.com/quantumkithub/matrixalgebrakit.jl/", rev = "main"}

‎src/TensorKit.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export @tensor, @tensoropt, @ncon, ncon, @planar, @plansor
9999
export scalar, add!, contract!
100100

101101
# truncation schemes
102-
export notrunc, truncrank, trunctol, truncfilter, truncspace, truncerror
102+
export notrunc, truncrank, trunctol, truncfilter, truncspace, truncerror, truncmultiplets
103103

104104
# cache management
105105
export empty_globalcaches!

‎src/factorizations/factorizations.jl‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ using MatrixAlgebraKit
2323
import MatrixAlgebraKit as MAK
2424
using MatrixAlgebraKit: AbstractAlgorithm, TruncatedAlgorithm, DiagonalAlgorithm
2525
using MatrixAlgebraKit: TruncationStrategy, NoTruncation, TruncationByValue, TruncationByError,
26-
TruncationIntersection, TruncationUnion, TruncationByFilter, TruncationByOrder
26+
TruncationIntersection, TruncationUnion, TruncationByFilter, TruncationByOrder,
27+
TruncationMultiplets
2728
using MatrixAlgebraKit: diagview
2829

2930
include("utility.jl")

‎src/factorizations/truncation.jl‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,34 @@ function MAK.findtruncated_svd(values::SectorVector, strategy::TruncationUnion)
337337
return SectorDict{eltype(sectors), eltype(vals)}(sectors, vals)
338338
end
339339

340+
# Degenerate values can occur in different blocks, for example when the sectors are related by
341+
# a symmetry, so groups of degenerate values are determined across all blocks simultaneously.
342+
function MAK.findtruncated(values::SectorVector, strategy::TruncationMultiplets)
343+
return _findtruncated_multiplets(values, MAK.findtruncated(values, strategy.trunc), strategy)
344+
end
345+
function MAK.findtruncated_svd(values::SectorVector, strategy::TruncationMultiplets)
346+
return _findtruncated_multiplets(values, MAK.findtruncated_svd(values, strategy.trunc), strategy)
347+
end
348+
349+
function _findtruncated_multiplets(values::SectorVector, inds, strategy::TruncationMultiplets)
350+
keep = similar(values, Bool)
351+
to_keep = collect(parent(_ind_to_mask!(keep, inds)))
352+
kept_values = collect(parent(values))
353+
perm = sortperm(kept_values; by = abs, rev = true)
354+
MAK._keep_multiplets!(to_keep, kept_values, perm, strategy)
355+
copyto!(parent(keep), to_keep)
356+
return keep
357+
end
358+
359+
_ind_to_mask!(keep::SectorVector{Bool}, inds::SectorVector{Bool}) = copyto!(keep, inds)
360+
function _ind_to_mask!(keep::SectorVector{Bool}, inds::SectorDict)
361+
fill!(parent(keep), false)
362+
for (c, ind) in pairs(inds)
363+
keep[c][ind] .= true
364+
end
365+
return keep
366+
end
367+
340368
# Truncation error
341369
# ----------------
342370
MAK.truncation_error(values::SectorVector, ind) = MAK.truncation_error!(copy(values), ind)

0 commit comments

Comments
 (0)