-
Notifications
You must be signed in to change notification settings - Fork 1
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
Implement an MPS method initializing the tensors to identity (copy-tensors) #218
Changes from 4 commits
0ac258f
b348911
c3800a8
d18f894
347b7bf
a5b07de
36a43f4
0112833
36ad5c2
50d5b3c
b7917c9
984ba14
b582cca
e4e719c
3d32a5c
31f5482
5e2ac42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -62,6 +62,30 @@ function MPS(arrays::Vector{<:AbstractArray}; order=defaultorder(MPS)) | |||||
return MPS(ansatz, NonCanonical()) | ||||||
end | ||||||
|
||||||
MPS(arraysdims::NTuple{N,<:Vector{Int}}; order=defaultorder(MPS)) where {N} = MPS(collect(arraysdims); order=order) | ||||||
MPS(arraysdims::Vector{<:Tuple{Vararg{Int}}}; order=defaultorder(MPS)) = MPS(collect.(arraysdims); order=order) | ||||||
function MPS(arraysdims::NTuple{N,Tuple{Vararg{Int}}}; order=defaultorder(MPS)) where {N} | ||||||
return MPS(collect(collect.(arraysdims)); order=order) | ||||||
end | ||||||
function MPS(arraysdims::Vector{<:Vector{Int}}; order=defaultorder(MPS)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was one possibility along with the one @jofrevalles suggested below of using |
||||||
@assert length(arraysdims[1]) == 2 "First array must have 2 dimensions" | ||||||
@assert all(==(3) ∘ length, arraysdims[2:(end - 1)]) "All arrays must have 3 dimensions" | ||||||
@assert length(arraysdims[end]) == 2 "Last array must have 2 dimensions" | ||||||
issetequal(order, defaultorder(MPS)) || | ||||||
throw(ArgumentError("order must be a permutation of $(String.(defaultorder(MPS)))")) | ||||||
|
||||||
return MPS( | ||||||
map(arraysdims) do arrdims | ||||||
mindim = minimum(arrdims) | ||||||
arr = zeros(ComplexF64, arrdims...) | ||||||
deltas = ntuple(x -> ntuple(_ -> x, length(arrdims)), mindim) | ||||||
broadcast(delta -> arr[delta...] = 1.0, deltas) | ||||||
arr | ||||||
end; | ||||||
order=order, | ||||||
Todorbsc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
) | ||||||
end | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not create another constructor for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I said above, I agree it is better to not implement another constructor. The option that fits the best for me is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, in general I agree with @jofrevalles but I think I think |
||||||
function Base.convert(::Type{MPS}, tn::Product) | ||||||
@assert socket(tn) == State() | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
@testset "Ansatz" begin | ||
end | ||
@testset "Ansatz" begin end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,28 @@ | |
@test inds(ψ; at=site"3", dir=:left) == inds(ψ; at=site"2", dir=:right) !== nothing | ||
@test all(i -> size(ψ, inds(ψ; at=Site(i))) == 2, 1:nsites(ψ)) | ||
|
||
dispatch_arraysdims = [ | ||
([2, 4], [5, 4, 3], [2, 3]), | ||
[(2, 4), (5, 4, 3), (2, 3)], | ||
((2, 4), (5, 4, 3), (2, 3)), | ||
[[2, 4], [5, 4, 3], [2, 3]], | ||
] | ||
for arraysdims in dispatch_arraysdims | ||
ψ = MPS(arraysdims) # Default order (:o, :l, :r) | ||
@test size(tensors(ψ; at=site"1")) == (2, 4) | ||
@test size(tensors(ψ; at=site"2")) == (5, 4, 3) | ||
@test size(tensors(ψ; at=site"3")) == (2, 3) | ||
t1 = tensors(ψ; at=site"1") | ||
@test t1[1, 1] == t1[2, 2] == 1 | ||
@test sum(t1) == 2 | ||
t2 = tensors(ψ; at=site"2") | ||
@test t2[1, 1, 1] == t2[2, 2, 2] == t2[3, 3, 3] == 1 | ||
@test sum(t2) == 3 | ||
t3 = tensors(ψ; at=site"3") | ||
@test t3[1, 1] == t3[2, 2] == 1 | ||
@test sum(t3) == 2 | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap this into a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
@testset "Site" begin | ||
ψ = MPS([rand(2, 2), rand(2, 2, 2), rand(2, 2)]) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would currently just delete these methods for now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed them