Skip to content

Commit

Permalink
Use random_itensor and random_mps (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored May 17, 2024
1 parent d1cff25 commit 72d8ece
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 51 deletions.
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

2 comments on commit 72d8ece

@mtfishman
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/107069

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.3 -m "<description of version>" 72d8ece093cb5c360049fd8069c5f188f35e13a6
git push origin v0.2.3

Please sign in to comment.