Skip to content

Commit

Permalink
flat_tt comes already normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
stecrotti committed May 2, 2024
1 parent 0f8c218 commit 51933d3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
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

2 comments on commit 51933d3

@stecrotti
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/106028

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.1 -m "<description of version>" 51933d3b16c8056bc6470eb1a0de232057dbf42e
git push origin v0.9.1

Please sign in to comment.