Skip to content

Commit 0e01ac3

Browse files
Update for MPSKit v0.12 (#42)
* Update for BlockTensors * Bugfix mpoham constructor adds missing end of each term * update compat * `AbstractTensorMap` typesignature changes * always use `AbstractTensorMap` as tensortype of `MPOHamiltonian`s, correct braidingtensor signature * use `SparseBlockTensorMap`s for `MPOHamiltonian`s * allow for different types of tensors at different sites * add new `AbstractFiniteLattice` and `AbstractInfiniteLattice` supertypes for differentiating between finite and infinite models * implement `Base.isfinite` for lattice(types) * add `Base.isfinite` for LatticePoints * make sure finite lattices result in a `FiniteMPOHamiltonian` * change the handling of checking whether a lattice is finite, remove abstract types introduced earlier * account for changes to `right_virtualspace` * update TensorKit compat * Bump version v0.4.0 * Small fixes * Update spinoperators for TensorKit version * update bosonoperators for new TensorKit version * update fermionoperators for new TensorKit version * update hubbardoperators for TensorKit version * update tJ operators for TensorKit version * Revert "allow for different types of tensors at different sites" This reverts commit a09994c. * rework mpoham to use existing functionality * disable type inference testing * Cleanup * update CI --------- Co-authored-by: victor <[email protected]>
1 parent cc5c05e commit 0e01ac3

19 files changed

+181
-218
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,14 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
version:
24-
- '1.8' # LTS version
24+
- 'lts' # LTS version
2525
- '1' # automatically expands to the latest stable 1.x release of Julia
2626
os:
2727
- ubuntu-latest
2828
- macOS-latest
2929
- windows-latest
3030
arch:
3131
- x64
32-
# - x86 # exclude x86 tests - not enough memory and already failing on TensorKt
33-
# exclude:
34-
# - os: macOS-latest
35-
# arch: x86
36-
# - os: windows-latest
37-
# arch: x86
3832
steps:
3933
- uses: actions/checkout@v4
4034
- uses: julia-actions/setup-julia@v2
@@ -52,27 +46,3 @@ jobs:
5246
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5347
with:
5448
file: lcov.info
55-
test-nightly:
56-
needs: test
57-
name: Julia nightly - ${{ matrix.os }} - ${{ matrix.arch }}
58-
runs-on: ${{ matrix.os }}
59-
strategy:
60-
fail-fast: false
61-
matrix:
62-
version:
63-
- 'nightly'
64-
os:
65-
- ubuntu-latest
66-
arch:
67-
- x64
68-
steps:
69-
- uses: actions/checkout@v4
70-
- uses: julia-actions/setup-julia@v2
71-
with:
72-
version: ${{ matrix.version }}
73-
arch: ${{ matrix.arch }}
74-
- uses: julia-actions/cache@v2
75-
- uses: julia-actions/julia-buildpkg@latest
76-
- uses: julia-actions/julia-runtest@latest
77-
env:
78-
JULIA_NUM_THREADS: 4

Project.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MPSKitModels"
22
uuid = "ca635005-6f8c-4cd1-b51d-8491250ef2ab"
33
authors = ["Maarten Van Damme", "Lukas Devos", "Gertian Roose", "Klaas Gunst"]
4-
version = "0.3.6"
4+
version = "0.4.0"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -13,13 +13,13 @@ TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
1313
TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
1414

1515
[compat]
16-
MPSKit = "0.11"
16+
MPSKit = "0.12"
1717
MacroTools = "0.5"
1818
PrecompileTools = "1"
19-
TensorKit = "0.11, 0.12"
20-
TensorOperations = "4"
19+
TensorKit = "0.13,0.14"
20+
TensorOperations = "5"
2121
TupleTools = "1"
22-
julia = "1.8"
22+
julia = "1.10"
2323

2424
[extras]
2525
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/MPSKitModels.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module MPSKitModels
22

33
using TensorKit, MPSKit
44
using MacroTools: @capture, postwalk
5-
using MPSKit: @plansor, _lastspace, _firstspace
5+
using MPSKit: @plansor
66
using TensorOperations
77
using TupleTools
88

src/lattices/chains.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct FiniteChain <: AbstractLattice{1}
2525
end
2626
Base.axes(chain::FiniteChain) = (1:(chain.L),)
2727
Base.isfinite(::Type{FiniteChain}) = true
28+
Base.isfinite(::FiniteChain) = true
2829

2930
const Chain = Union{InfiniteChain,FiniteChain}
3031

src/lattices/latticepoints.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@ end
6161
Base.:-(i::Int, j::LatticePoint{1}) = LatticePoint(i .- j, j.lattice)
6262

6363
Base.isless(i::L, j::L) where {L<:LatticePoint} = linearize_index(i) < linearize_index(j)
64-
64+
function Base.isfinite(::Union{LatticePoint{N,G},Type{<:LatticePoint{N,G}}}) where {N,G}
65+
return isfinite(G)
66+
end
6567
latticetype(::Union{LatticePoint{N,G},Type{<:LatticePoint{N,G}}}) where {N,G} = G

src/models/hamiltonians.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function transverse_field_ising(T::Type{<:Number}=ComplexF64,
4040
S::Union{Type{Trivial},Type{Z2Irrep}}=Trivial,
4141
lattice::AbstractLattice=InfiniteChain(1);
4242
J=1.0, g=1.0)
43-
ZZ = rmul!(σᶻᶻ(T, S), -J)
44-
X = rmul!(σˣ(T, S), g * -J)
43+
ZZ = scale!(σᶻᶻ(T, S), -J)
44+
X = scale!(σˣ(T, S), g * -J)
4545
return @mpoham begin
4646
sum(nearest_neighbours(lattice)) do (i, j)
4747
return ZZ{i,j}
@@ -53,8 +53,13 @@ end
5353
function transverse_field_ising(T::Type{<:Number}, ::Type{fℤ₂},
5454
lattice::AbstractLattice=InfiniteChain(1);
5555
J=1.0, g=1.0)
56-
twosite = axpby!(-J, c_plusmin(T) + c_minplus(T), J, c_plusplus(T) + c_minmin(T))
57-
onesite = axpby!(2g * J, c_number(T), -g * J, id(Matrix{T}, space(twosite, 1)))
56+
hop = add!(c_plusmin(T), c_minplus(T))
57+
sc = add!(c_plusplus(T), c_minmin(T))
58+
twosite = add!(hop, sc, J, -J)
59+
60+
N = c_number(T)
61+
E = id(storagetype(N), space(N, 1))
62+
onesite = add!(N, E, -g * J, 2g * J)
5863

5964
return @mpoham begin
6065
sum(nearest_neighbours(lattice)) do (i, j)

src/models/transfermatrices.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ function classical_ising(elt::Type{<:Number}=ComplexF64, ::Type{Trivial}=Trivial
3030

3131
@tensor o[-1 -2; -3 -4] := O[1 2; 3 4] * nt[-1; 1] * nt[-2; 2] * nt[-3; 3] * nt[-4; 4]
3232

33-
return DenseMPO(TensorMap(o, ℂ^2 *^2, ℂ^2 *^2))
33+
return InfiniteMPO([TensorMap(o, ℂ^2 *^2, ℂ^2 *^2)])
3434
end
3535

3636
function classical_ising(elt::Type{<:Number}, ::Type{Z2Irrep}; beta=log(1 + sqrt(2)) / 2)
3737
x = cosh(beta)
3838
y = sinh(beta)
3939

4040
sec = ℤ₂Space(0 => 1, 1 => 1)
41-
mpo = TensorMap(zeros, elt, sec * sec, sec * sec)
42-
blocks(mpo)[Irrep[ℤ₂](0)] = [2x^2 2x*y; 2x*y 2y^2]
43-
blocks(mpo)[Irrep[ℤ₂](1)] = [2x*y 2x*y; 2x*y 2x*y]
41+
mpo = zeros(elt, sec * sec, sec * sec)
42+
block(mpo, Irrep[ℤ₂](0)) .= [2x^2 2x*y; 2x*y 2y^2]
43+
block(mpo, Irrep[ℤ₂](1)) .= [2x*y 2x*y; 2x*y 2x*y]
4444

45-
return DenseMPO(mpo)
45+
return InfiniteMPO([mpo])
4646
end
4747

4848
#===========================================================================================
@@ -63,23 +63,23 @@ function sixvertex(elt::Type{<:Number}=ComplexF64, ::Type{Trivial}=Trivial; a=1.
6363
0 c b 0
6464
0 b c 0
6565
0 0 0 a]
66-
return DenseMPO(permute(TensorMap(d, ℂ^2 ^2, ℂ^2 ^2), ((1, 2), (4, 3))))
66+
return InfiniteMPO([permute(TensorMap(d, ℂ^2 ^2, ℂ^2 ^2), ((1, 2), (4, 3)))])
6767
end
6868
function sixvertex(elt::Type{<:Number}, ::Type{U1Irrep}; a=1.0, b=1.0, c=1.0)
6969
pspace = U1Space(-1 // 2 => 1, 1 // 2 => 1)
70-
mpo = TensorMap(zeros, elt, pspace pspace, pspace pspace)
71-
blocks(mpo)[Irrep[U₁](0)] = [b c; c b]
72-
blocks(mpo)[Irrep[U₁](1)] = reshape([a], (1, 1))
73-
blocks(mpo)[Irrep[U₁](-1)] = reshape([a], (1, 1))
74-
return DenseMPO(permute(mpo, ((1, 2), (4, 3))))
70+
mpo = zeros(elt, pspace pspace, pspace pspace)
71+
block(mpo, Irrep[U₁](0)) .= [b c; c b]
72+
block(mpo, Irrep[U₁](1)) .= reshape([a], (1, 1))
73+
block(mpo, Irrep[U₁](-1)) .= reshape([a], (1, 1))
74+
return InfiniteMPO([permute(mpo, ((1, 2), (4, 3)))])
7575
end
7676
function sixvertex(elt::Type{<:Number}, ::Type{CU1Irrep}; a=1.0, b=1.0, c=1.0)
7777
pspace = CU1Space(1 // 2 => 1)
78-
mpo = TensorMap(zeros, elt, pspace pspace, pspace pspace)
79-
blocks(mpo)[Irrep[CU₁](0, 0)] = reshape([b + c], (1, 1))
80-
blocks(mpo)[Irrep[CU₁](0, 1)] = reshape([-b + c], (1, 1))
81-
blocks(mpo)[Irrep[CU₁](1, 2)] = reshape([a], (1, 1))
82-
return DenseMPO(permute(mpo, ((1, 2), (4, 3))))
78+
mpo = zeros(elt, pspace pspace, pspace pspace)
79+
block(mpo, Irrep[CU₁](0, 0)) .= reshape([b + c], (1, 1))
80+
block(mpo, Irrep[CU₁](0, 1)) .= reshape([-b + c], (1, 1))
81+
block(mpo, Irrep[CU₁](1, 2)) .= reshape([a], (1, 1))
82+
return InfiniteMPO([permute(mpo, ((1, 2), (4, 3)))])
8383
end
8484

8585
#===========================================================================================
@@ -93,9 +93,9 @@ MPO for the partition function of the two-dimensional hard hexagon model.
9393
"""
9494
function hard_hexagon(elt::Type{<:Number}=ComplexF64)
9595
P = Vect[FibonacciAnyon]( => 1)
96-
O = TensorMap(ones, elt, P P P P)
97-
blocks(O)[FibonacciAnyon(:I)] *= 0
98-
return DenseMPO(O)
96+
O = ones(elt, P P P P)
97+
block(O, FibonacciAnyon(:I)) .*= 0
98+
return InfiniteMPO([O])
9999
end
100100

101101
#===========================================================================================
@@ -116,5 +116,5 @@ function qstate_clock(elt::Type{<:Number}=ComplexF64, ::Type{Trivial}=Trivial;
116116
(comega(i - j) + comega(j - k) + comega(k - l) + comega(l - i)))
117117
end
118118

119-
return DenseMPO(TensorMap(O, ℂ^q *^q, ℂ^q *^q))
119+
return InfiniteMPO([TensorMap(O, ℂ^q *^q, ℂ^q *^q)])
120120
end

src/operators/bosonoperators.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ a_plus(elt::Type{<:Number}; kwargs...) = a_plus(elt, Trivial; kwargs...)
1010
a_plus(symm::Type{<:Sector}; kwargs...) = a_plus(ComplexF64, symm; kwargs...)
1111

1212
function a_plus(elt::Type{<:Number}, ::Type{Trivial}; cutoff::Integer=5)
13-
a⁺ = TensorMap(zeros, elt, ComplexSpace(cutoff + 1), ComplexSpace(cutoff + 1))
13+
a⁺ = zeros(elt, ComplexSpace(cutoff + 1), ComplexSpace(cutoff + 1))
1414
for n in 1:cutoff
1515
a⁺[n + 1, n] = sqrt(n)
1616
end
@@ -21,7 +21,7 @@ function a_plus(elt::Type{<:Number}, ::Type{U1Irrep}; cutoff::Integer=5, side=:L
2121
pspace = U1Space(n => 1 for n in 0:cutoff)
2222
if side === :L
2323
vspace = U1Space(1 => 1)
24-
a⁺ = TensorMap(zeros, elt, pspace pspace vspace)
24+
a⁺ = zeros(elt, pspace pspace vspace)
2525
for (f1, f2) in fusiontrees(a⁺)
2626
c₁, c₂ = f1.uncoupled[1], f2.uncoupled[1]
2727
if c₁.charge == c₂.charge + 1
@@ -30,7 +30,7 @@ function a_plus(elt::Type{<:Number}, ::Type{U1Irrep}; cutoff::Integer=5, side=:L
3030
end
3131
elseif side === :R
3232
vspace = U1Space(-1 => 1)
33-
a⁺ = TensorMap(zeros, elt, vspace pspace pspace)
33+
a⁺ = zeros(elt, vspace pspace pspace)
3434
for (f1, f2) in fusiontrees(a⁺)
3535
c₁, c₂ = f1.uncoupled[2], f2.uncoupled[1]
3636
if c₁.charge == c₂.charge + 1
@@ -57,7 +57,7 @@ a_min(elt::Type{<:Number}; kwargs...) = a_min(elt, Trivial; kwargs...)
5757
a_min(symm::Type{<:Sector}; kwargs...) = a_min(ComplexF64, symm; kwargs...)
5858

5959
function a_min(elt::Type{<:Number}, ::Type{Trivial}; cutoff::Integer=5)
60-
a⁻ = TensorMap(zeros, elt, ComplexSpace(cutoff + 1), ComplexSpace(cutoff + 1))
60+
a⁻ = zeros(elt, ComplexSpace(cutoff + 1), ComplexSpace(cutoff + 1))
6161
for n in 1:cutoff
6262
a⁻[n, n + 1] = sqrt(n)
6363
end
@@ -68,7 +68,7 @@ function a_min(elt::Type{<:Number}, ::Type{U1Irrep}; cutoff::Integer=5, side=:L)
6868
pspace = U1Space(n => 1 for n in 0:cutoff)
6969
if side === :L
7070
vspace = U1Space(-1 => 1)
71-
a⁻ = TensorMap(zeros, elt, pspace pspace vspace)
71+
a⁻ = zeros(elt, pspace pspace vspace)
7272
for (f1, f2) in fusiontrees(a⁻)
7373
c₁, c₂ = f1.uncoupled[1], f2.uncoupled[1]
7474
if c₁.charge + 1 == c₂.charge
@@ -77,7 +77,7 @@ function a_min(elt::Type{<:Number}, ::Type{U1Irrep}; cutoff::Integer=5, side=:L)
7777
end
7878
elseif side === :R
7979
vspace = U1Space(1 => 1)
80-
a⁻ = TensorMap(zeros, elt, vspace pspace pspace)
80+
a⁻ = zeros(elt, vspace pspace pspace)
8181
for (f1, f2) in fusiontrees(a⁻)
8282
c₁, c₂ = f1.uncoupled[2], f2.uncoupled[1]
8383
if c₁.charge + 1 == c₂.charge
@@ -123,7 +123,7 @@ a_number(elt::Type{<:Number}; kwargs...) = a_number(elt, Trivial; kwargs...)
123123
a_number(symm::Type{<:Sector}; kwargs...) = a_number(ComplexF64, symm; kwargs...)
124124

125125
function a_number(elt::Type{<:Number}, ::Type{Trivial}; cutoff::Integer=5)
126-
N = TensorMap(zeros, elt, ComplexSpace(cutoff + 1), ComplexSpace(cutoff + 1))
126+
N = zeros(elt, ComplexSpace(cutoff + 1), ComplexSpace(cutoff + 1))
127127
for n in 0:cutoff
128128
N[n + 1, n + 1] = n
129129
end
@@ -132,7 +132,7 @@ end
132132

133133
function a_number(elt::Type{<:Number}, ::Type{U1Irrep}; cutoff::Integer=5)
134134
pspace = U1Space(n => 1 for n in 0:cutoff)
135-
N = TensorMap(zeros, elt, pspace, pspace)
135+
N = zeros(elt, pspace, pspace)
136136
for (c, b) in blocks(N)
137137
b .= c.charge
138138
end

src/operators/fermionoperators.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ function c_plus(elt::Type{<:Number}=ComplexF64; side=:L)
1212
vspace = Vect[fℤ₂](1 => 1)
1313
if side === :L
1414
pspace = Vect[fℤ₂](0 => 1, 1 => 1)
15-
c⁺ = TensorMap(zeros, elt, pspace pspace vspace)
16-
blocks(c⁺)[fℤ₂(1)] .= one(elt)
15+
c⁺ = zeros(elt, pspace pspace vspace)
16+
block(c⁺, fℤ₂(1)) .= one(elt)
1717
elseif side === :R
1818
C = c_plus(elt; side=:L)
1919
F = isomorphism(storagetype(C), vspace, flip(vspace))
@@ -62,7 +62,7 @@ Fermionic number operator.
6262
"""
6363
function c_number(elt::Type{<:Number}=ComplexF64)
6464
pspace = Vect[fℤ₂](0 => 1, 1 => 1)
65-
n = TensorMap(zeros, elt, pspace pspace)
66-
blocks(n)[fℤ₂(1)] .= one(elt)
65+
n = zeros(elt, pspace pspace)
66+
block(n, fℤ₂(1)) .= one(elt)
6767
return n
6868
end

src/operators/hubbardoperators.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ end
5252
function single_site_operator(T, particle_symmetry::Type{<:Sector},
5353
spin_symmetry::Type{<:Sector})
5454
V = hubbard_space(particle_symmetry, spin_symmetry)
55-
return TensorMap(zeros, T, V V)
55+
return zeros(T, V V)
5656
end
5757

5858
function two_site_operator(T, particle_symmetry::Type{<:Sector},
5959
spin_symmetry::Type{<:Sector})
6060
V = hubbard_space(particle_symmetry, spin_symmetry)
61-
return TensorMap(zeros, T, V V V V)
61+
return zeros(T, V V V V)
6262
end
6363

6464
"""

0 commit comments

Comments
 (0)