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

Implement Infinite Boundary Conditions for MatrixProduct and ProjectedEntangledPair Types #79

Merged
merged 10 commits into from
Aug 2, 2023

Conversation

jofrevalles
Copy link
Member

Summary

In this PR, we resolve #77 by extending our MatrixProduct and ProjectedEntangledPair types to include support for infinite boundary conditions, materialized in the infinite Matrix Product States (iMPS) and infinite Projected Entangled Pair States (iPEPS). This creates a structure where the tensors cycle periodically, emulating an infinite system by using a finite system unit cell that repeats itself.

The tensors, Base.show and Base.length functions have been extended to support TensorNetworks with Infinte boundary conditions. Additional unit tests have been added to ensure the proper functioning of these new boundary conditions for both the MPS and MPO structures.

Nevertheless, the visualization of infinite boundary types is not yet supported and we should think about how to implement this.

Example

Let's create a MatrixProduct{State, Infinite} which consists of a cell of three tensors that repeat indefinitely:

julia> _arrays = [rand(1, 1, 2), rand(1, 1, 2), rand(1, 1, 2)]
3-element Vector{Array{Float64, 3}}:
 [0.17136137178613753;;; 0.1659622523369414]
 [0.23387611601182623;;; 0.5187233455849274]
 [0.025368244393775274;;; 0.2701565528371912]

julia> ψ = MatrixProduct{State,Infinite}(_arrays, order = (:l, :r, :o))
TensorNetwork{MatrixProduct{State, Infinite}, NamedTuple{(:plug, :interlayer, ), Tuple{Type{<:Plug}, Vector{Bijection{Int64, Symbol}}, Union{Nothing, Int64}}}}(#tensors=∞, #labels=∞)

julia> tensors(ψ, 1) == tensors(ψ, 4) == tensors(ψ, -2)
true

@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Merging #79 (0f14437) into master (9e5349d) will decrease coverage by 0.82%.
The diff coverage is 50.00%.

@@            Coverage Diff             @@
##           master      #79      +/-   ##
==========================================
- Coverage   78.27%   77.46%   -0.82%     
==========================================
  Files           9        9              
  Lines         695      701       +6     
==========================================
- Hits          544      543       -1     
- Misses        151      158       +7     
Files Changed Coverage Δ
src/Quantum/PEP.jl 0.00% <0.00%> (ø)
src/Quantum/Quantum.jl 76.04% <ø> (ø)
src/Tenet.jl 25.00% <ø> (-75.00%) ⬇️
src/Quantum/MP.jl 90.10% <100.00%> (-0.80%) ⬇️

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.

In general is ok, but I think you mixed the PR #78. Please remove anything from that other PR so I can merge this.

Comment on lines 114 to 116
tensors(ψ::TensorNetwork{MatrixProduct{P,Infinite}}, args...) where {P<:Plug} =
throw(ArgumentError("You need to specify the site for an infinite MatrixProduct$P"))

Copy link
Member

Choose a reason for hiding this comment

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

If it doesn't match any method signature, it's better to let Julia throw a MethodError.

Suggested change
tensors::TensorNetwork{MatrixProduct{P,Infinite}}, args...) where {P<:Plug} =
throw(ArgumentError("You need to specify the site for an infinite MatrixProduct$P"))

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I cherry-picked the commits in #78 because I thought was necessary, I will try to remove them now.

Comment on lines 120 to 122
tensors(ψ::TensorNetwork{ProjectedEntangledPair{P,Infinite}}, args...) where {P<:Plug} =
throw(ArgumentError("You need to specify the site for an infinite MatrixProduct$P"))

Copy link
Member

Choose a reason for hiding this comment

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

Same as in MP.jl

Suggested change
tensors::TensorNetwork{ProjectedEntangledPair{P,Infinite}}, args...) where {P<:Plug} =
throw(ArgumentError("You need to specify the site for an infinite MatrixProduct$P"))

@@ -81,7 +83,7 @@ Return the `Tensor` connected to the [`TensorNetwork`](@ref) on `site`.
See also: [`sites`](@ref).
"""
tensors(tn::TensorNetwork{<:Quantum}, site::Integer, args...) = tensors(plug(tn), tn, site, args...)
tensors(::Type{State}, tn::TensorNetwork{<:Quantum}, site) = select(tn, labels(tn, :plug, site)) |> only
tensors(::Union{Type{Operator}, Type{State}}, tn::TensorNetwork{<:Quantum}, site) = select(tn, labels(tn, :plug, site)) |> only
Copy link
Member

Choose a reason for hiding this comment

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

I think you mixed PRs.

Suggested change
tensors(::Union{Type{Operator}, Type{State}}, tn::TensorNetwork{<:Quantum}, site) = select(tn, labels(tn, :plug, site)) |> only
tensors(::Type{State}, tn::TensorNetwork{<:Quantum}, site) = select(tn, labels(tn, :plug, site)) |> only

Comment on lines 79 to 86

@testset "tensors" begin
arrays = [rand(1, 2, 2), rand(1, 1, 2, 2), rand(1, 2, 2)]
ψ = MatrixProduct{Operator,Open}(arrays, order = (:l, :r, :i, :o))

@test tensors(ψ, 1) isa Tensor
@test size(tensors(ψ)) |> first == length(ψ) == 3
end
Copy link
Member

Choose a reason for hiding this comment

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

Again you mixed PRs.

Suggested change
@testset "tensors" begin
arrays = [rand(1, 2, 2), rand(1, 1, 2, 2), rand(1, 2, 2)]
ψ = MatrixProduct{Operator,Open}(arrays, order = (:l, :r, :i, :o))
@test tensors(ψ, 1) isa Tensor
@test size(tensors(ψ)) |> first == length(ψ) == 3
end

@jofrevalles
Copy link
Member Author

@mofeing, your requested changes should be fixed

src/Quantum/MP.jl Outdated Show resolved Hide resolved
src/Quantum/PEP.jl Outdated Show resolved Hide resolved
src/Quantum/MP.jl Show resolved Hide resolved
src/Quantum/PEP.jl Show resolved Hide resolved
src/Quantum/MP.jl Outdated Show resolved Hide resolved
src/Quantum/PEP.jl Outdated Show resolved Hide resolved
Co-authored-by: Sergio Sánchez Ramírez <[email protected]>
@mofeing mofeing merged commit b3fac98 into master Aug 2, 2023
3 of 5 checks passed
@mofeing mofeing deleted the feature/implement-infinite-states branch August 2, 2023 17:50
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.

Implement Infinite boundary conditions for MatrixProduct and ProjectedEntangledPair
2 participants