Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flat tensor train comes already normalized #30

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/periodic_tensor_train.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ end
flat_periodic_tt(bondsizes::AbstractVector{<:Integer}, q...)
flat_periodic_tt(d::Integer, L::Integer, q...)

Construct a Tensor Train with periodic boundary conditions full of 1's, by specifying either:
Construct a (normalized) Tensor Train with periodic boundary conditions filled with a constant, by specifying either:
- `bondsizes`: the size of each bond
- `d` a fixed size for all bonds, `L` the length
and
- `q` a Tuple/Vector specifying the number of values taken by each variable on a single site
"""
function flat_periodic_tt(bondsizes::AbstractVector{<:Integer}, q...)
tensors = [ones(bondsizes[t], bondsizes[mod1(t+1,length(bondsizes))], q...) for t in eachindex(bondsizes)]
x = 1 / (prod(bondsizes)^(1/length(bondsizes))*prod(q))
tensors = [fill(x, bondsizes[t], bondsizes[mod1(t+1,length(bondsizes))], q...) for t in eachindex(bondsizes)]
PeriodicTensorTrain(tensors)
end
flat_periodic_tt(d::Integer, L::Integer, q...) = flat_periodic_tt(fill(d, L-1), q...)
Expand Down
6 changes: 4 additions & 2 deletions src/tensor_train.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ end
flat_tt(bondsizes::AbstractVector{<:Integer}, q...)
flat_tt(d::Integer, L::Integer, q...)

Construct a Tensor Train full of 1's, by specifying either:
Construct a (normalized) Tensor Train filled with a constant, by specifying either:
- `bondsizes`: the size of each bond
- `d` a fixed size for all bonds, `L` the length
and
- `q` a Tuple/Vector specifying the number of values taken by each variable on a single site
"""
function flat_tt(bondsizes::AbstractVector{<:Integer}, q...)
TensorTrain([ones(bondsizes[t], bondsizes[t+1], q...) for t in 1:length(bondsizes)-1])
L = length(bondsizes) - 1
x = 1 / (prod(bondsizes)^(1/L)*prod(q))
TensorTrain([fill(x, bondsizes[t], bondsizes[t+1], q...) for t in 1:L])
end
flat_tt(d::Integer, L::Integer, q...) = flat_tt([1; fill(d, L-1); 1], q...)

Expand Down
8 changes: 8 additions & 0 deletions test/periodic_tensor_train.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
@test evaluate(A + A, x) evaluate(B + B, x)
end

@testset "Flat" begin
L = 5
bondsizes = rand(1:4, L)
q = (2,4,3)
C = flat_periodic_tt(bondsizes, q...)
@assert normalization(C) 1
end

@testset "Random" begin
svd_trunc = TruncBondThresh(20, 0.0)
L = 5
Expand Down
8 changes: 4 additions & 4 deletions test/tensor_train.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ end
@test e3 e1
end

@testset "Uniform" begin
L = 5
@testset "Flat" begin
q = (2, 4)
d = 3
C = flat_tt(d, L, q...)
bondsizes = [1, 3, 5, 2, 1]
C = flat_tt(bondsizes, q...)
@test normalization(C) 1
x = [[rand(1:q[1]), rand(1:q[2])] for _ in C]
e1 = evaluate(C, x)

Expand Down
Loading