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

Replace Gram-Schmidt method by QR for random Chain initialization #175

Merged
merged 6 commits into from
Aug 1, 2024

Conversation

jofrevalles
Copy link
Member

In this PR, we replace the former Gram-Schmidt method for random chain initialization by a QR method, which applies the qr decomposition to some random tensors in order to get a randomly normalized right-canonized MPS.

Additionally, we benchmarked both methods and we conclude that the new method outscales the former in terms of running time, memory required and allocations produced.

Comparison

· Gram-Schmidt method:

julia> using Tenet; using BenchmarkTools

julia> @btime mps = rand(Chain, Open, State; n=50, χ=300)
  2.002 s (53812 allocations: 122.75 MiB)
MPS (inputs=0, outputs=50)


julia> @btime mpo = rand(Chain, Open, Operator; n=50, χ=200)
  1.537 s (63338 allocations: 120.70 MiB)
MPO (inputs=50, outputs=50)

· QR method:

julia> using Tenet; using BenchmarkTools

julia> @btime mps = rand(Chain, Open, State; n=50, χ=300)
  423.495 ms (10480 allocations: 101.18 MiB)
MPS (inputs=0, outputs=50)

julia> @btime mpo = rand(Chain, Open, Operator; n=50, χ=200)
  573.715 ms (28459 allocations: 109.77 MiB)
MPO (inputs=50, outputs=50)

@jofrevalles jofrevalles requested a review from mofeing July 31, 2024 14:33
Copy link
Member

@mofeing mofeing left a comment

Choose a reason for hiding this comment

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

Can't you reuse the map(1:n) do i block but just changing the line A = gramschmidt!(rand(rng, T, χl, χr * p)) for A, _ = qr!(rand(rng, T, χl, χr * p)).

Is there another reason for refactoring to a for loop?

(isodd(n) && i == n ÷ 2 + 1) ? (χl, χl) : (after_mid ? (χr, χl) : (χl, χr))
end
# Left boundary tensor
F = lq!(rand(rng, T, 1, p * min(χ, p)))
Copy link
Member

Choose a reason for hiding this comment

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

Why lq! and not qr!?

Copy link
Member Author

Choose a reason for hiding this comment

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

lq! is useful here since we want the Chain to be in the right-canonical form. We could do it with qr! too but it would involve some permutations and reshapes, which is much elegantly solved with lq!.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we changed lq! for qr! and we reshaped the physical leg with the left bond, we would get a left-canonical Chain.

@jofrevalles
Copy link
Member Author

Can't you reuse the map(1:n) do i block but just changing the line A = gramschmidt!(rand(rng, T, χl, χr * p)) for A, _ = qr!(rand(rng, T, χl, χr * p)).

Is there another reason for refactoring to a for loop?

We can, but then we would have to put conditions for the first and last tensor, which seems more ugly.

src/Ansatz/Chain.jl Outdated Show resolved Hide resolved
src/Ansatz/Chain.jl Outdated Show resolved Hide resolved
src/Ansatz/Chain.jl Show resolved Hide resolved
@mofeing mofeing merged commit 2260133 into master Aug 1, 2024
1 of 6 checks passed
@mofeing mofeing deleted the fix/rand-chain branch August 1, 2024 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants