Skip to content

Commit f9a1f49

Browse files
committed
format states
1 parent 864af2a commit f9a1f49

File tree

8 files changed

+440
-344
lines changed

8 files changed

+440
-344
lines changed

src/states/abstractmps.jl

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ Tensor types
88
Tensor type for representing local MPO tensors, with the index convention `W ⊗ S ← N ⊗ E`,
99
where `N`, `E`, `S` and `W` denote the north, east, south and west virtual spaces respectively.
1010
"""
11-
const MPOTensor{S} = AbstractTensorMap{T,S,2,2} where {T}
12-
const MPSBondTensor{S} = AbstractTensorMap{T,S,1,1} where {T}
13-
const GenericMPSTensor{S,N} = AbstractTensorMap{T,S,N,1} where {T} # some functions are also defined for "general mps tensors" (used in peps code)
14-
const MPSTensor{S} = GenericMPSTensor{S,2} # the usual mps tensors on which we work
11+
const MPOTensor{S} = AbstractTensorMap{T, S, 2, 2} where {T}
12+
const MPSBondTensor{S} = AbstractTensorMap{T, S, 1, 1} where {T}
13+
const GenericMPSTensor{S, N} = AbstractTensorMap{T, S, N, 1} where {T} # some functions are also defined for "general mps tensors" (used in peps code)
14+
const MPSTensor{S} = GenericMPSTensor{S, 2} # the usual mps tensors on which we work
1515

1616
"""
1717
MPSTensor([f, eltype], d::Int, left_D::Int, [right_D]::Int])
@@ -32,12 +32,14 @@ Construct an `MPSTensor` with given physical and virtual spaces.
3232
- `left_D::Int`: left virtual dimension
3333
- `right_D::Int`: right virtual dimension
3434
"""
35-
function MPSTensor(::UndefInitializer, eltype, P::Union{S,CompositeSpace{S}}, Vₗ::S,
36-
Vᵣ::S=Vₗ) where {S<:ElementarySpace}
35+
function MPSTensor(
36+
::UndefInitializer, eltype, P::Union{S, CompositeSpace{S}}, Vₗ::S, Vᵣ::S = Vₗ
37+
) where {S <: ElementarySpace}
3738
return TensorMap{eltype}(undef, Vₗ P Vᵣ)
3839
end
39-
function MPSTensor(f, eltype, P::Union{S,CompositeSpace{S}}, Vₗ::S,
40-
Vᵣ::S=Vₗ) where {S<:ElementarySpace}
40+
function MPSTensor(
41+
f, eltype, P::Union{S, CompositeSpace{S}}, Vₗ::S, Vᵣ::S = Vₗ
42+
) where {S <: ElementarySpace}
4143
A = MPSTensor(undef, eltype, P, Vₗ, Vᵣ)
4244
if f === rand
4345
return rand!(A)
@@ -50,8 +52,9 @@ function MPSTensor(f, eltype, P::Union{S,CompositeSpace{S}}, Vₗ::S,
5052
end
5153
end
5254
# TODO: reinstate function initializers?
53-
function MPSTensor(P::Union{S,CompositeSpace{S}}, Vₗ::S,
54-
Vᵣ::S=Vₗ) where {S<:ElementarySpace}
55+
function MPSTensor(
56+
P::Union{S, CompositeSpace{S}}, Vₗ::S, Vᵣ::S = Vₗ
57+
) where {S <: ElementarySpace}
5558
return MPSTensor(rand, Defaults.eltype, P, Vₗ, Vᵣ)
5659
end
5760

@@ -67,15 +70,15 @@ Construct an `MPSTensor` with given physical and virtual dimensions.
6770
- `Dₗ::Int`: left virtual dimension
6871
- `Dᵣ::Int`: right virtual dimension
6972
"""
70-
MPSTensor(f, eltype, d::Int, Dₗ::Int, Dᵣ::Int=Dₗ) = MPSTensor(f, eltype, ℂ^d, ℂ^Dₗ, ℂ^Dᵣ)
71-
MPSTensor(d::Int, Dₗ::Int; Dᵣ::Int=Dₗ) = MPSTensor(ℂ^d, ℂ^Dₗ, ℂ^Dᵣ)
73+
MPSTensor(f, eltype, d::Int, Dₗ::Int, Dᵣ::Int = Dₗ) = MPSTensor(f, eltype, ℂ^d, ℂ^Dₗ, ℂ^Dᵣ)
74+
MPSTensor(d::Int, Dₗ::Int; Dᵣ::Int = Dₗ) = MPSTensor(ℂ^d, ℂ^Dₗ, ℂ^Dᵣ)
7275

7376
"""
7477
MPSTensor(A::AbstractArray)
7578
7679
Convert an array to an `MPSTensor`.
7780
"""
78-
function MPSTensor(A::AbstractArray{T}) where {T<:Number}
81+
function MPSTensor(A::AbstractArray{T}) where {T <: Number}
7982
@assert ndims(A) > 2 "MPSTensor should have at least 3 dims, but has $ndims(A)"
8083
sz = size(A)
8184
t = TensorMap(undef, T, foldl(, ComplexSpace.(sz[1:(end - 1)])) ^sz[end])
@@ -90,7 +93,7 @@ Determine whether the given tensor is full rank, i.e. whether both the map from
9093
virtual space and the physical space to the right virtual space, and the map from the right
9194
virtual space and the physical space to the left virtual space are injective.
9295
"""
93-
function isfullrank(A::GenericMPSTensor; side=:both)
96+
function isfullrank(A::GenericMPSTensor; side = :both)
9497
Vₗ = _firstspace(A)
9598
Vᵣ = _lastspace(A)
9699
P = (space.(Ref(A), 2:(numind(A) - 1))...)
@@ -110,12 +113,12 @@ end
110113
111114
Make the set of MPS tensors full rank by performing a series of orthogonalizations.
112115
"""
113-
function makefullrank!(A::PeriodicVector{<:GenericMPSTensor}; alg=QRpos())
116+
function makefullrank!(A::PeriodicVector{<:GenericMPSTensor}; alg = QRpos())
114117
while true
115118
i = findfirst(!isfullrank, A)
116119
isnothing(i) && break
117-
if !isfullrank(A[i]; side=:left)
118-
L, Q = rightorth!(_transpose_tail(A[i]); alg=alg')
120+
if !isfullrank(A[i]; side = :left)
121+
L, Q = rightorth!(_transpose_tail(A[i]); alg = alg')
119122
A[i] = _transpose_front(Q)
120123
A[i - 1] = A[i - 1] * L
121124
else
@@ -207,7 +210,7 @@ function physicalspace end
207210
physicalspace(A::MPSTensor) = space(A, 2)
208211
physicalspace(A::GenericMPSTensor) = prod(x -> space(A, x), 2:(numind(A) - 1))
209212
physicalspace(O::MPOTensor) = space(O, 2)
210-
physicalspace(O::AbstractBlockTensorMap{<:Any,<:Any,2,2}) = only(space(O, 2))
213+
physicalspace(O::AbstractBlockTensorMap{<:Any, <:Any, 2, 2}) = only(space(O, 2))
211214

212215
"""
213216
eachsite(state::AbstractMPS)

0 commit comments

Comments
 (0)