Skip to content

Commit 71b709b

Browse files
Rewrite MPS types to use C instead of CR (and CL) and add ψ.center functionality. (#216)
* change `CLs` field to `Cs` field * update printing * index changes in `FiniteMPS` constructor * rename `CRView` to `CView` * change to `getproperty(::FiniteMPS, :C)` instead of `:CR` * change `center` field to type `Ref{Int}` to allow for mutable integer in unmutable `FiniteMPS` struct * update `copy` and `similar` for `FiniteMPS` to include `center` field * initialize `center` of `FiniteMPS` on the last site * update `left_virtualspace` and `right_virtualspace` to `psi.C` syntax * change `orthview.jl` to use new `CView` syntax * update tests to use `.C` instead of `.CR` * update `+(::FiniteMPS, ::FiniteMPS)` to new `.C` syntax * format `orthoview.jl` * fix `similar` of `center` in `similar(::FiniteMPS)` * change comment * add HalfIntegers.jl as dependency * remove `center` field of `FiniteMPS` * update `FiniteMPS` docstring * add `center` function thats accessed through `getproperty` * rewrite `norm(::FiniteMPS)` without having to guage (implementing 5 year old TODO) * change `getproperty(::MultilineMPS)` to work with `:C` instead of `:CR` * change every instance of `.CR` to `.C` * change `getproperty(::WindowMPS)` to work with `:C` instead of `:CR` * change index in `norm(::FiniteMPS)` * use `HalfIntegers.ishalfodd` to determine if center is a bond tensor or center tensor * add docstring for `center(::FiniteMPS)` * use `center(psi)` instead of `psi.center` in `norm(::FiniteMPS)` * update `center(::FiniteMPS)` * use `center(::FiniteMPS)` in `Base.show(::IOContext, ::FiniteMPS)` * small `show` fix * use `isinteger(::HalfInt)` instead of `!ishalfodd(::HalfInt)` * modify `show(::IOContext, ::FiniteMPS)` using the new `center` `HalfInteger` syntax * formatter * get rid of mention to `CL` and `CR` in docs [skip CI] * docfixes [skip CI] * small changes in `Base.show(::IOContext, ::FiniteMPS)` * fix `Base.show(::IOContext, ::FiniteMPS)` edgecases * formatter * remove printstatement from docs * remove `center` as a function, only keep `mps.center` property * remove commented code * implement `Base.propertynames(ψ::FiniteMPS)` * add `Base.propertynames` for `WindowMPS` and `MultilineMPS`
1 parent e8098f6 commit 71b709b

File tree

32 files changed

+360
-308
lines changed

32 files changed

+360
-308
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ BlockTensorKit = "5f87ffc2-9cf1-4a46-8172-465d160bd8cd"
99
FLoops = "cc61a311-1640-44b5-9fba-1b764f453329"
1010
FastClosures = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a"
1111
FoldsThreads = "9c68100b-dfe1-47cf-94c8-95104e173443"
12+
HalfIntegers = "f0d1745a-41c9-11e9-1dd9-e5d34d218721"
1213
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
1314
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1415
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
@@ -30,6 +31,7 @@ BlockTensorKit = "0.1.1"
3031
FLoops = "0.1, 0.2"
3132
FastClosures = "0.3"
3233
FoldsThreads = "0.1"
34+
HalfIntegers = "1.6.0"
3335
KrylovKit = "0.8.3"
3436
LinearAlgebra = "1.6"
3537
LoggingExtras = "~1.0"

docs/src/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@ represent a vector of these tensors.
7171
```@example finitemps
7272
al = mps.AL[3] # left gauged tensor of the third site
7373
@tensor E[a; b] := al[c, d, b] * conj(al[c, d, a])
74-
@show isapprox(E, id(left_virtualspace(mps, 3)))
74+
@show isapprox(E, id(right_virtualspace(mps, 3)))
7575
```
7676
```@example finitemps
7777
ar = mps.AR[3] # right gauged tensor of the third site
7878
@tensor E[a; b] := ar[a, d, c] * conj(ar[b, d, c])
79-
@show isapprox(E, id(right_virtualspace(mps, 2)))
79+
@show isapprox(E, id(left_virtualspace(mps, 3)))
8080
```
8181

8282
As the mps will be kept in a gauged form, updating a tensor will also update the gauged
8383
tensors. For example, we can set the tensor of the third site to the identity, and the
8484
gauged tensors will be updated accordingly.
8585

8686
```@example finitemps
87-
mps.CR[3] = id(domain(mps.CR[3]))
88-
println(mps)
87+
mps.C[3] = id(domain(mps.C[3]))
88+
mps
8989
```
9090

9191
These objects can then be used to compute observables and expectation values. For example,
@@ -136,16 +136,16 @@ mps = InfiniteMPS(d, D) # random MPS
136136

137137
The `InfiniteMPS` object then handles the gauging of the MPS, which is necessary for many of
138138
the algorithms. This is done automatically upon creation of the object, and the user can
139-
access the gauged tensors by getting and setting the `AL`, `AR`, `CR`/`CL` and `AC` fields,
139+
access the gauged tensors by getting and setting the `AL`, `AR`, `C` and `AC` fields,
140140
which each represent a (periodic) vector of these tensors.
141141

142142
```@example infinitemps
143-
al = mps.AL[1] # left gauged tensor of the third site
143+
al = mps.AL[1] # left gauged tensor of the first site
144144
@tensor E[a; b] := al[c, d, b] * conj(al[c, d, a])
145145
@show isapprox(E, id(left_virtualspace(mps, 1)))
146146
```
147147
```@example infinitemps
148-
ar = mps.AR[1] # right gauged tensor of the third site
148+
ar = mps.AR[1] # right gauged tensor of the first site
149149
@tensor E[a; b] := ar[a, d, c] * conj(ar[b, d, c])
150150
@show isapprox(E, id(right_virtualspace(mps, 2)))
151151
```

docs/src/man/states.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ norm(state) == norm(state.AC[3])
5353
lastly there is also the CR field, with the following property:
5454

5555
```julia
56-
@tensor a[-1 -2;-3] := state.AL[3][-1 -2;1]*state.CR[3][1;-3]
57-
@tensor b[-1 -2;-3] := state.CR[2][-1;1]*state.AR[3][1 -2;-3]
56+
@tensor a[-1 -2;-3] := state.AL[3][-1 -2;1]*state.C[3][1;-3]
57+
@tensor b[-1 -2;-3] := state.C[2][-1;1]*state.AR[3][1 -2;-3]
5858
a state.AC[3];
5959
b state.AC[3];
6060
```
@@ -66,7 +66,7 @@ Behind the scenes, a finite mps has 4 fields
6666
ALs::Vector{Union{Missing,A}}
6767
ARs::Vector{Union{Missing,A}}
6868
ACs::Vector{Union{Missing,A}}
69-
CLs::Vector{Union{Missing,B}}
69+
Cs::Vector{Union{Missing,B}}
7070
```
7171

7272
calling `state.AC` returns an "orthoview" instance, which is a very simple dummy object.
@@ -97,7 +97,7 @@ InfiniteMPS(data);
9797

9898
The above code would create an infinite mps with an A-B structure (a 2 site unit cell).
9999

100-
much like a finite mps, we can again query the fields state.AL, state.AR, state.AC and state.CR. The implementation is much easier, as they are now just plain fields in the struct
100+
much like a finite mps, we can again query the fields state.AL, state.AR, state.AC and state.C. The implementation is much easier, as they are now just plain fields in the struct
101101

102102
```julia
103103
AL::PeriodicArray{A,1}
@@ -142,7 +142,7 @@ You can access properties by calling
142142
state.AL[row,collumn]
143143
state.AC[row,collumn]
144144
state.AR[row,collumn]
145-
state.CR[row,collumn]
145+
state.C[row,collumn]
146146
```
147147

148148
Behind the scenes, we have a type called Multiline, defined as:

src/MPSKit.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using Base.Iterators
99
using RecipesBase
1010
using VectorInterface
1111
using Accessors
12+
using HalfIntegers
1213
import TupleTools as TT
1314

1415
using LinearAlgebra: diag, Diagonal

src/algorithms/ED.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function exact_diagonalization(opp::FiniteMPOHamiltonian;
1414

1515
mpst_type = tensormaptype(spacetype(Ot), 2, 1, storagetype(Ot))
1616
mpsb_type = tensormaptype(spacetype(Ot), 1, 1, storagetype(Ot))
17-
CLs = Vector{Union{Missing,mpsb_type}}(missing, len + 1)
17+
Cs = Vector{Union{Missing,mpsb_type}}(missing, len + 1)
1818
ALs = Vector{Union{Missing,mpst_type}}(missing, len)
1919
ARs = Vector{Union{Missing,mpst_type}}(missing, len)
2020
ACs = Vector{Union{Missing,mpst_type}}(missing, len)
@@ -36,7 +36,7 @@ function exact_diagonalization(opp::FiniteMPOHamiltonian;
3636
normalize!(ACs[middle_site])
3737

3838
#construct the largest possible finite mps of that length
39-
state = FiniteMPS(ALs, ARs, ACs, CLs)
39+
state = FiniteMPS(ALs, ARs, ACs, Cs)
4040
envs = environments(state, opp)
4141

4242
#optimize the middle site. Because there is no truncation, this single site captures the entire possible hilbert space

src/algorithms/approximate/idmrg.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function approximate(ost::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multili
99
LoggingExtras.withlevel(; alg.verbosity) do
1010
@infov 2 loginit!(log, ϵ)
1111
for iter in 1:(alg.maxiter)
12-
C_current = ψ.CR[:, 0]
12+
C_current = ψ.C[:, 0]
1313

1414
# left to right sweep
1515
for col in 1:size(ψ, 2), row in 1:size(ψ, 1)
@@ -18,7 +18,7 @@ function approximate(ost::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multili
1818
ψ.AC[row + 1, col] = h * above.AC[row, col]
1919
normalize!.AC[row + 1, col])
2020

21-
ψ.AL[row + 1, col], ψ.CR[row + 1, col] = leftorth.AC[row + 1, col])
21+
ψ.AL[row + 1, col], ψ.C[row + 1, col] = leftorth.AC[row + 1, col])
2222

2323
tm = TransferMatrix(above.AL[row, col], mpo[row, col], ψ.AL[row + 1, col])
2424
setleftenv!(envs, row, col + 1, normalize(leftenv(envs, row, col) * tm))
@@ -31,14 +31,14 @@ function approximate(ost::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multili
3131
ψ.AC[row + 1, col] = h * above.AC[row, col]
3232
normalize!.AC[row + 1, col])
3333

34-
ψ.CR[row + 1, col - 1], temp = rightorth(_transpose_tail.AC[row + 1, col]))
34+
ψ.C[row + 1, col - 1], temp = rightorth(_transpose_tail.AC[row + 1, col]))
3535
ψ.AR[row + 1, col] = _transpose_front(temp)
3636

3737
tm = TransferMatrix(above.AR[row, col], mpo[row, col], ψ.AR[row + 1, col])
3838
setrightenv!(envs, row, col - 1, normalize(tm * rightenv(envs, row, col)))
3939
end
4040

41-
ϵ = norm(C_current - ψ.CR[:, 0])
41+
ϵ = norm(C_current - ψ.C[:, 0])
4242

4343
if ϵ < alg.tol
4444
@infov 2 logfinish!(log, iter, ϵ)
@@ -69,7 +69,7 @@ function approximate(ost::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multili
6969
LoggingExtras.withlevel(; alg.verbosity) do
7070
@infov 2 loginit!(log, ϵ)
7171
for iter in 1:(alg.maxiter)
72-
C_current = ψ.CR[:, 0]
72+
C_current = ψ.C[:, 0]
7373

7474
# sweep from left to right
7575
for col in 1:size(ψ, 2), row in 1:size(ψ, 1)
@@ -81,7 +81,7 @@ function approximate(ost::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multili
8181
normalize!(c)
8282

8383
ψ.AL[row + 1, col] = al
84-
ψ.CR[row + 1, col] = complex(c)
84+
ψ.C[row + 1, col] = complex(c)
8585
ψ.AR[row + 1, col + 1] = _transpose_front(ar)
8686

8787
setleftenv!(envs, row, col + 1,
@@ -105,7 +105,7 @@ function approximate(ost::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multili
105105
normalize!(c)
106106

107107
ψ.AL[row + 1, col] = al
108-
ψ.CR[row + 1, col] = complex(c)
108+
ψ.C[row + 1, col] = complex(c)
109109
ψ.AR[row + 1, col + 1] = _transpose_front(ar)
110110

111111
setleftenv!(envs, row, col + 1,
@@ -120,7 +120,7 @@ function approximate(ost::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multili
120120
end
121121

122122
# update error
123-
ϵ = sum(zip(C_current, ψ.CR[:, 0])) do (c1, c2)
123+
ϵ = sum(zip(C_current, ψ.C[:, 0])) do (c1, c2)
124124
smallest = infimum(_firstspace(c1), _firstspace(c2))
125125
e1 = isometry(_firstspace(c1), smallest)
126126
e2 = isometry(_firstspace(c2), smallest)

src/algorithms/approximate/vomps.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function approximate(ψ::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multilin
3838
end
3939

4040
alg_gauge = updatetol(alg.alg_gauge, iter, ϵ)
41-
ψ = MultilineMPS(temp_ACs, ψ.CR[:, end]; alg_gauge.tol, alg_gauge.maxiter)
41+
ψ = MultilineMPS(temp_ACs, ψ.C[:, end]; alg_gauge.tol, alg_gauge.maxiter)
4242

4343
alg_environments = updatetol(alg.alg_environments, iter, ϵ)
4444
recalculate!(envs, ψ; alg_environments.tol)

src/algorithms/changebonds/changebonds.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ function _expand!(ψ::InfiniteMPS, AL′::PeriodicVector, AR′::PeriodicVector)
2626

2727
# update C: add vectors, make room for new vectors:
2828
# C -> [C 0; 0 expansion]
29-
l = zerovector!(similar.CR[i], codomain.CR[i]) _firstspace(AR′[i + 1])))
30-
ψ.CR[i] = catdomain.CR[i], l)
31-
r = zerovector!(similar.CR[i], _lastspace(AL′[i])' domain.CR[i])))
32-
ψ.CR[i] = catcodomain.CR[i], r)
29+
l = zerovector!(similar.C[i], codomain.C[i]) _firstspace(AR′[i + 1])))
30+
ψ.C[i] = catdomain.C[i], l)
31+
r = zerovector!(similar.C[i], _lastspace(AL′[i])' domain.C[i])))
32+
ψ.C[i] = catcodomain.C[i], r)
3333

3434
# update AC: recalculate
35-
ψ.AC[i] = ψ.AL[i] * ψ.CR[i]
35+
ψ.AC[i] = ψ.AL[i] * ψ.C[i]
3636
end
3737
return normalize!(ψ)
3838
end

src/algorithms/changebonds/svdcut.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function changebonds(ψ::AbstractFiniteMPS, alg::SvdCut; kwargs...)
1515
end
1616
function changebonds!::AbstractFiniteMPS, alg::SvdCut; normalize::Bool=true)
1717
for i in (length(ψ) - 1):-1:1
18-
U, S, V, = tsvd.CR[i]; trunc=alg.trscheme, alg=TensorKit.SVD())
18+
U, S, V, = tsvd.C[i]; trunc=alg.trscheme, alg=TensorKit.SVD())
1919
AL′ = ψ.AL[i] * U
2020
ψ.AC[i] = (AL′, complex(S))
2121
AR′ = _transpose_front(V * _transpose_tail.AR[i + 1]))
@@ -76,10 +76,10 @@ function changebonds(ψ::MultilineMPS, alg::SvdCut)
7676
end
7777
function changebonds::InfiniteMPS, alg::SvdCut)
7878
copied = complex.(ψ.AL)
79-
ncr = ψ.CR[1]
79+
ncr = ψ.C[1]
8080

8181
for i in 1:length(ψ)
82-
U, ncr, = tsvd.CR[i]; trunc=alg.trscheme, alg=TensorKit.SVD())
82+
U, ncr, = tsvd.C[i]; trunc=alg.trscheme, alg=TensorKit.SVD())
8383
copied[i] = copied[i] * U
8484
copied[i + 1] = _transpose_front(U' * _transpose_tail(copied[i + 1]))
8585
end

src/algorithms/changebonds/vumpssvd.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function changebonds_1(state::InfiniteMPS, H, alg::VUMPSSvdCut,
3535
SvdCut(; trscheme=truncspace(infimum(D1, D2))), nenvs)
3636
end
3737

38-
collapsed = InfiniteMPS([nstate.AL[1]], nstate.CR[1]; tol=alg.tol_gauge)
38+
collapsed = InfiniteMPS([nstate.AL[1]], nstate.C[1]; tol=alg.tol_gauge)
3939

4040
return collapsed, envs
4141
end
@@ -51,7 +51,7 @@ function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environment
5151
nAC2 = vecs[1]
5252

5353
h_c = ∂∂C(loc + 1, state, H, envs)
54-
(vals, vecs, _) = eigsolve(h_c, state.CR[loc + 1], 1, :SR; tol=alg.tol_eigenval,
54+
(vals, vecs, _) = eigsolve(h_c, state.C[loc + 1], 1, :SR; tol=alg.tol_eigenval,
5555
ishermitian=false)
5656
nC2 = vecs[1]
5757

0 commit comments

Comments
 (0)