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

Use random_itensor and random_mps #9

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ITensorGPU"
uuid = "d89171c1-af8f-46b3-badf-d2a472317c15"
authors = ["Katharine Hyatt", "Matthew Fishman <[email protected]>"]
version = "0.2.2"
version = "0.2.3"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand All @@ -12,6 +12,6 @@ ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
[compat]
Adapt = "3, 4"
CUDA = "4, 5"
ITensorMPS = "0.1"
ITensors = "0.3, 0.4, 0.5, 0.6"
ITensorMPS = "0.2.2"
ITensors = "0.6.8"
julia = "1.6"
4 changes: 2 additions & 2 deletions jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pipeline {
}
steps {
sh '''
julia -e 'using Pkg; Pkg.activate(temp=true); Pkg.develop(path="."); Pkg.test("ITensorGPU")'
julia -e 'using Pkg; Pkg.activate(temp=true); Pkg.Registry.update(); Pkg.update(); Pkg.develop(path="."); Pkg.test("ITensorGPU")'
'''
}
}
Expand All @@ -51,7 +51,7 @@ pipeline {
}
steps {
sh '''
julia -e 'using Pkg; Pkg.activate(temp=true); Pkg.develop(path="."); Pkg.test("ITensorGPU")'
julia -e 'using Pkg; Pkg.activate(temp=true); Pkg.Registry.update(); Pkg.update(); Pkg.develop(path="."); Pkg.test("ITensorGPU")'
'''
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/ITensorGPU.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ export cu
using ITensors: cpu
export cpu

using ITensors: ITensor, cpu, cu, randomITensor
using ITensors: ITensor, cpu, cu, random_itensor
function cuITensor(args...; kwargs...)
return adapt(CuArray, ITensor(args...; kwargs...))
end
function randomCuITensor(args...; kwargs...)
return adapt(CuArray, randomITensor(args...; kwargs...))
return adapt(CuArray, random_itensor(args...; kwargs...))
end
export cuITensor, randomCuITensor

using ITensorMPS: MPO, MPS, randomMPO, randomMPS
using ITensorMPS: MPO, MPS, random_mpo, random_mps
function cuMPS(args...; kwargs...)
return adapt(CuArray, MPS(args...; kwargs...))
end
Expand All @@ -23,14 +23,14 @@ function productCuMPS(args...; kwargs...)
return adapt(CuArray, MPS(args...; kwargs...))
end
function randomCuMPS(args...; kwargs...)
return adapt(CuArray, randomMPS(args...; kwargs...))
return adapt(CuArray, random_mps(args...; kwargs...))
end
function cuMPO(args...; kwargs...)
return adapt(CuArray, MPO(args...; kwargs...))
end
cuMPO(tn::MPO) = adapt(CuArray, tn)
function randomCuMPO(args...; kwargs...)
return adapt(CuArray, randomMPO(args...; kwargs...))
return adapt(CuArray, random_mpo(args...; kwargs...))
end
export cuMPO, cuMPS, productCuMPS, randomCuMPO, randomCuMPS
end
38 changes: 19 additions & 19 deletions test/test_cucontract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ using Test: @test, @testset
l = Index(ml, "l")
a = Index(ma, "a")
@testset "Test contract cuITensors" begin
A = cuITensor(randomITensor(T))
B = cuITensor(randomITensor(T))
Ai = cuITensor(randomITensor(T, i))
Bi = cuITensor(randomITensor(T, i))
Aj = cuITensor(randomITensor(T, j))
Aij = cuITensor(randomITensor(T, i, j))
Aji = cuITensor(randomITensor(T, j, i))
Bij = cuITensor(randomITensor(T, i, j))
Aik = cuITensor(randomITensor(T, i, k))
Ajk = cuITensor(randomITensor(T, j, k))
Ajl = cuITensor(randomITensor(T, j, l))
Akl = cuITensor(randomITensor(T, k, l))
Aijk = cuITensor(randomITensor(T, i, j, k))
Ajkl = cuITensor(randomITensor(T, j, k, l))
Aikl = cuITensor(randomITensor(T, i, k, l))
Akla = cuITensor(randomITensor(T, k, l, a))
Aijkl = cuITensor(randomITensor(T, i, j, k, l))
A = cuITensor(random_itensor(T))
B = cuITensor(random_itensor(T))
Ai = cuITensor(random_itensor(T, i))
Bi = cuITensor(random_itensor(T, i))
Aj = cuITensor(random_itensor(T, j))
Aij = cuITensor(random_itensor(T, i, j))
Aji = cuITensor(random_itensor(T, j, i))
Bij = cuITensor(random_itensor(T, i, j))
Aik = cuITensor(random_itensor(T, i, k))
Ajk = cuITensor(random_itensor(T, j, k))
Ajl = cuITensor(random_itensor(T, j, l))
Akl = cuITensor(random_itensor(T, k, l))
Aijk = cuITensor(random_itensor(T, i, j, k))
Ajkl = cuITensor(random_itensor(T, j, k, l))
Aikl = cuITensor(random_itensor(T, i, k, l))
Akla = cuITensor(random_itensor(T, k, l, a))
Aijkl = cuITensor(random_itensor(T, i, j, k, l))
@testset "Test contract cuITensor (Scalar*Scalar -> Scalar)" begin
C = A * B
@test scalar(C) ≈ scalar(A) * scalar(B)
Expand Down Expand Up @@ -198,8 +198,8 @@ using Test: @test, @testset
a_only_inds = [Index(2) for ii in 1:7]
b_only_inds = [Index(2) for ii in 1:7]
shared_inds = [Index(2) for ii in 1:7]
A = randomITensor(vcat(a_only_inds, shared_inds))
B = randomITensor(vcat(b_only_inds, shared_inds))
A = random_itensor(vcat(a_only_inds, shared_inds))
B = random_itensor(vcat(b_only_inds, shared_inds))
cA = cuITensor(A)
cB = cuITensor(B)
inds_a = vcat(a_only_inds, shared_inds)
Expand Down
8 changes: 4 additions & 4 deletions test/test_cudense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ using Test: @test, @testset
@testset "Test2 add CuDense" begin
for i1 in indices, i2 in indices
i1 == i2 && continue
A = randomITensor(SType, i1, i2)
B = randomITensor(SType, i1, i2)
A = random_itensor(SType, i1, i2)
B = random_itensor(SType, i1, i2)
cuA = cu(A)
cuB = cu(B)
C = A + B
Expand All @@ -34,8 +34,8 @@ using Test: @test, @testset
@testset "Test2 subtract CuDense" begin
for i1 in indices, i2 in indices
i1 == i2 && continue
A = randomITensor(SType, i1, i2)
B = randomITensor(SType, i1, i2)
A = random_itensor(SType, i1, i2)
B = random_itensor(SType, i1, i2)
cuA = cu(A)
cuB = cu(B)
C = A - B
Expand Down
20 changes: 10 additions & 10 deletions test/test_cudiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ using Test: @test, @test_broken, @testset
l = Index(ml, "l")
a = Index(ma, "a")
@testset "Test contract cuITensors" begin
Aij = cuITensor(randomITensor(T, i, j))
Aji = cuITensor(randomITensor(T, j, i))
Bij = cuITensor(randomITensor(T, i, j))
Aik = cuITensor(randomITensor(T, i, k))
Ajk = cuITensor(randomITensor(T, j, k))
Ajl = cuITensor(randomITensor(T, j, l))
Akl = cuITensor(randomITensor(T, k, l))
Aij = cuITensor(random_itensor(T, i, j))
Aji = cuITensor(random_itensor(T, j, i))
Bij = cuITensor(random_itensor(T, i, j))
Aik = cuITensor(random_itensor(T, i, k))
Ajk = cuITensor(random_itensor(T, j, k))
Ajl = cuITensor(random_itensor(T, j, l))
Akl = cuITensor(random_itensor(T, k, l))
Dv = rand(T, mi)
D = itensor(ITensors.tensor(NDTensors.Diag(CuVector(Dv)), (i, i')))
Ev = rand(T, mi)
Expand Down Expand Up @@ -64,9 +64,9 @@ end
l = Index(ml, "l")
a = Index(ma, "a")
@testset "Test contract cuITensors" begin
Aij = cuITensor(randomITensor(T1, i, j))
Aji = cuITensor(randomITensor(T1, j, i))
Bij = cuITensor(randomITensor(T1, i, j))
Aij = cuITensor(random_itensor(T1, i, j))
Aji = cuITensor(random_itensor(T1, j, i))
Bij = cuITensor(random_itensor(T1, i, j))
Dv = rand(T2, mi)
D = itensor(ITensors.tensor(NDTensors.Diag(CuVector(Dv)), (i, i')))
Ev = rand(T2, mi)
Expand Down
2 changes: 1 addition & 1 deletion test/test_cuitensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ using Test: @test, @testset
end
@testset "Test permute(cuITensor,Index...) for large tensors" begin
inds = [Index(2) for ii in 1:14]
A = randomITensor(SType, (inds))
A = random_itensor(SType, (inds))
CA = cuITensor(A)
for shuffle_count in 1:20
perm_inds = Random.shuffle(inds)
Expand Down
2 changes: 1 addition & 1 deletion test/test_cumpo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using Test: @test, @testset
@test all(ITensors.data(K) .== ITensors.data(K_))

s = siteinds("S=1/2", N)
L = randomMPO(s)
L = random_mpo(s)
K = cuMPO(L)
@test all(ITensors.data(cpu(K)) .== ITensors.data(cpu(L)))
@testset "orthogonalize" begin
Expand Down
10 changes: 5 additions & 5 deletions test/test_cumps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using Test: @test, @testset
psi[1] = cuITensor(sites[1])
@test hasind(psi[1], sites[1])

L = randomMPS(sites)
L = random_mps(sites)
K = cuMPS(L)
@test all(ITensors.data(cpu(K)) .== ITensors.data(cpu(L)))

Expand Down Expand Up @@ -60,7 +60,7 @@ using Test: @test, @testset
end
end

@testset "randomMPS" begin
@testset "random_mps" begin
phi = randomCuMPS(sites)
@test hasind(phi[1], sites[1])
@test norm(phi[1]) ≈ 1.0
Expand All @@ -69,8 +69,8 @@ using Test: @test, @testset
end

@testset "inner different MPS" begin
phi = randomMPS(sites)
psi = randomMPS(sites)
phi = random_mps(sites)
psi = random_mps(sites)
phipsi = dag(phi[1]) * psi[1]
for j in 2:N
phipsi *= dag(phi[j]) * psi[j]
Expand Down Expand Up @@ -101,7 +101,7 @@ using Test: @test, @testset
end

@testset "add MPS" begin
psi = randomMPS(sites)
psi = random_mps(sites)
phi = deepcopy(psi)
xi = add(psi, phi)
@test inner(xi, xi) ≈ 4.0 * inner(psi, psi)
Expand Down
2 changes: 1 addition & 1 deletion test/test_dmrg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ end
s = siteinds("S=1/2", n)

H = device(MPO(heisenberg(n), s))
ψ0 = device(randomMPS(s))
ψ0 = device(random_mps(s))

dmrg_params = (; nsweeps=4, maxdim=10, cutoff=1e-8, noise=1e-8, outputlevel=0)
observer = DMRGObserver(["Z"], s; energy_tol=1e-4, minsweeps=10)
Expand Down
Loading