Skip to content

Commit 71d9098

Browse files
committed
Add some MPS + CUDA tests
1 parent 5939792 commit 71d9098

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

test/cuda/states.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using MPSKit
2+
using MPSKit: GeometryStyle, InfiniteChainStyle, TransferMatrix
3+
using TensorKit
4+
using TensorKit:
5+
using Adapt, CUDA
6+
7+
@testset "CuMPS ($(sectortype(D)), $elt)" for (D, d, elt) in
8+
[(ℙ^10, ℙ^2, ComplexF64), (Rep[U₁](1 => 3), Rep[U₁](0 => 1), ComplexF64)]
9+
tol = Float64(eps(real(elt)) * 100)
10+
11+
ψ = adapt(CuArray, InfiniteMPS([rand(elt, D * d, D), rand(elt, D * d, D)]; tol))
12+
@test TensorKit.storagetype(ψ) = CuVector{ComplexF64}
13+
@test eltype(ψ) == eltype(typeof(ψ))
14+
15+
for i in 1:length(ψ)
16+
@plansor difference[-1 -2; -3] := ψ.AL[i][-1 -2; 1] * ψ.C[i][1; -3] -
17+
ψ.C[i - 1][-1; 1] * ψ.AR[i][1 -2; -3]
18+
@test norm(difference, Inf) < tol * 10
19+
20+
@test l_LL(ψ, i) * TransferMatrix.AL[i], ψ.AL[i]) l_LL(ψ, i + 1)
21+
@test l_LR(ψ, i) * TransferMatrix.AL[i], ψ.AR[i]) l_LR(ψ, i + 1)
22+
@test l_RL(ψ, i) * TransferMatrix.AR[i], ψ.AL[i]) l_RL(ψ, i + 1)
23+
@test l_RR(ψ, i) * TransferMatrix.AR[i], ψ.AR[i]) l_RR(ψ, i + 1)
24+
25+
@test TransferMatrix.AL[i], ψ.AL[i]) * r_LL(ψ, i) r_LL(ψ, i + 1)
26+
@test TransferMatrix.AL[i], ψ.AR[i]) * r_LR(ψ, i) r_LR(ψ, i + 1)
27+
@test TransferMatrix.AR[i], ψ.AL[i]) * r_RL(ψ, i) r_RL(ψ, i + 1)
28+
@test TransferMatrix.AR[i], ψ.AR[i]) * r_RR(ψ, i) r_RR(ψ, i + 1)
29+
end
30+
31+
L = rand(3:20)
32+
ψ = adapt(CuArray, FiniteMPS(rand, elt, L, d, D))
33+
@test TensorKit.storagetype(ψ) = CuVector{ComplexF64}
34+
@test eltype(ψ) == eltype(typeof(ψ))
35+
ovl = dot(ψ, ψ)
36+
37+
@test ovl norm.AC[1])^2
38+
39+
for i in 1:length(ψ)
40+
@test ψ.AC[i] ψ.AL[i] * ψ.C[i]
41+
@test ψ.AC[i] _transpose_front.C[i - 1] * _transpose_tail.AR[i]))
42+
end
43+
44+
@test ComplexF64 == scalartype(ψ)
45+
ψ = ψ * 3
46+
@test ovl * 9 norm(ψ)^2
47+
ψ = 3 * ψ
48+
@test ovl * 9 * 9 norm(ψ)^2
49+
50+
@test norm(2 * ψ + ψ - 3 * ψ) 0.0 atol = sqrt(eps(real(ComplexF64)))
51+
end

0 commit comments

Comments
 (0)