Skip to content

Commit 5f28eb8

Browse files
committed
update expansion
1 parent 08e171d commit 5f28eb8

6 files changed

Lines changed: 337 additions & 22 deletions

File tree

src/algorithms/changebonds/localexpand.jl

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
struct NoExpand <: Algorithm end
22

33
function changebonds_left(AL, Cs, alg; kwargs...)
4+
@info "Old size: $(dim(right_virtualspace(AL)))"
45
AL, Cs = changebonds(; expand_rightspace = AL, embed_leftspace = Cs, alg, kwargs...)[[2,end]]
5-
return Cs, AL
6+
@info "New size: $(dim(right_virtualspace(AL)))"
7+
return AL, Cs
68
end
79
function changebonds_right(Cs, AR, alg; kwargs...)
810
Cs, AR = changebonds(; expand_leftspace = AR, embed_rightspace = Cs, alg, kwargs...)[[1,4]]
@@ -29,28 +31,34 @@ function changebonds(;
2931
expansion_leftspace, expansion_rightspace
3032
)
3133
end
32-
const MissingOrTuple = Union{Missing, Tuple{<:Any}}
34+
const MissingOrTuple = Union{Missing, <:Tuple}
3335
function changebonds(
3436
embed_rightspace::MissingOrTuple, expand_rightspace, embed_both::MissingOrTuple, expand_leftspace, embed_leftspace::MissingOrTuple, alg;
3537
expansion_leftspace, expansion_rightspace
3638
)
3739
if !ismissing(expand_rightspace)
38-
expand_rightspace = _expand_leftisometry(expand_rightspace, alg, expansion_leftspace)
39-
if !ismissing(embed_rightspace)
40-
embed_rightspace = (_embed_left_space(expand_rightspace, A, alg) for A in embed_rightspace)
41-
end
42-
if !ismissing(embed_both)
43-
embed_both = (_embed_left_space(expand_rightspace, A, alg) for A in embed_both)
40+
expand_rightspace_new = _expand_leftisometry(expand_rightspace, alg, expansion_leftspace)
41+
if space(expand_rightspace) != space(expand_rightspace_new) || true
42+
if !ismissing(embed_leftspace)
43+
embed_leftspace = (_embed_left_space(expand_rightspace_new, A, alg) for A in embed_leftspace)
44+
end
45+
if !ismissing(embed_both)
46+
embed_both = (_embed_left_space(expand_rightspace_new, A, alg) for A in embed_both)
47+
end
4448
end
49+
expand_rightspace = expand_rightspace_new
4550
end
4651
if !ismissing(expand_leftspace)
47-
expand_leftspace = _expand_rightisometry(expand_leftspace, alg, expansion_rightspace)
48-
if !ismissing(embed_leftspace)
49-
embed_leftspace = (_embed_right_space(A, expand_leftspace, alg) for A in embed_leftspace)
50-
end
51-
if !ismissing(embed_both)
52-
embed_both = (_embed_right_space(A, expand_leftspace, alg) for A in embed_both)
52+
expand_leftspace_new = _expand_rightisometry(expand_leftspace, alg, expansion_rightspace)
53+
if space(expand_leftspace) != space(expand_leftspace_new) || true
54+
if !ismissing(embed_rightspace)
55+
embed_rightspace = (_embed_right_space(A, expand_leftspace_new, alg) for A in embed_rightspace)
56+
end
57+
if !ismissing(embed_both)
58+
embed_both = (_embed_right_space(A, expand_leftspace_new, alg) for A in embed_both)
59+
end
5360
end
61+
expand_leftspace = expand_leftspace_new
5462
end
5563
return embed_rightspace, expand_rightspace, embed_both, expand_leftspace, embed_leftspace
5664
end
@@ -65,7 +73,8 @@ function sup_inf_space(ac2)
6573
return supremum(VL, VR) infimum(VL, VR)
6674
end
6775
function _sample_space(space, sup, trscheme)
68-
return sample_space(infimum(space, sup), trscheme)
76+
sp = ismissing(sup) ? space : infimum(space, sup)
77+
return sample_space(sp, trscheme)
6978
end
7079
function _expand_leftisometry(A::MPSTensor, alg, expansion_leftspace)
7180
VL = left_null(A)
@@ -109,3 +118,14 @@ function _embed_right_space(Anext::MPSTensor, A::AbstractTensorMap, alg)
109118
Anext′ = TensorKit.absorb!(Anext′, Anext)
110119
return Anext′
111120
end
121+
122+
123+
extract_sector_types(::Type{GradedSpace{S,D}}) where {S<:Sector,D} = (S,)
124+
extract_sector_types(::Type{GradedSpace{ProductSector{T},D}}) where {T<:Tuple,D} = Tuple(T.parameters)
125+
extract_sector_types(sp::GradedSpace) = extract_sector_types(typeof(sp))
126+
function generate_sampling_space(psi::MPSKit.AbstractMPS, cutoff::Integer=100)
127+
sp = physicalspace(psi.AL[1])
128+
x = extract_sector_types(sp)
129+
iterator = Iterators.product((Iterators.take(values(T),cutoff) for T in x)...)
130+
return typeof(sp)([T=>1 for T in iterator])
131+
end

src/algorithms/changebonds/randexpand.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ are distributed uniformly, and then truncating according to the given `strategy`
8181
"""
8282
function sample_space(V, strategy)
8383
S = TensorKit.SectorVector{Float64}(undef, V)
84+
# fill!(S, 1.0)
8485
Random.rand!(parent(S))
8586
ind = MatrixAlgebraKit.findtruncated(S, strategy)
8687
return TensorKit.Factorizations.truncate_space(V, ind)
8788
end
89+
include("tensorkit.jl")
8890

8991

9092

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
function MatrixAlgebraKit.findtruncated(values::TensorKit.SectorVector, strategy::MatrixAlgebraKit.TruncationUnion)
3+
inds = map(Base.Fix1(MatrixAlgebraKit.findtruncated, values), strategy.components)
4+
@assert TensorKit._allequal(keys, inds) "missing blocks are not supported right now"
5+
sectors = keys(first(inds))
6+
vals = map(keys(first(inds))) do c
7+
mapreduce(Base.Fix2(getindex, c), MatrixAlgebraKit._ind_union, inds)
8+
end
9+
return TensorKit.SectorDict{eltype(sectors), eltype(vals)}(sectors, vals)
10+
end
11+
function MatrixAlgebraKit.findtruncated_svd(values::TensorKit.SectorVector, strategy::MatrixAlgebraKit.TruncationUnion)
12+
inds = map(Base.Fix1(MatrixAlgebraKit.findtruncated_svd, values), strategy.components)
13+
@assert TensorKit._allequal(keys, inds) "missing blocks are not supported right now"
14+
sectors = keys(first(inds))
15+
vals = map(keys(first(inds))) do c
16+
mapreduce(Base.Fix2(getindex, c), MatrixAlgebraKit._ind_union, inds)
17+
end
18+
return TensorKit.SectorDict{eltype(sectors), eltype(vals)}(sectors, vals)
19+
end

0 commit comments

Comments
 (0)