From 72d8ece093cb5c360049fd8069c5f188f35e13a6 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Fri, 17 May 2024 09:28:05 -0400 Subject: [PATCH] Use `random_itensor` and `random_mps` (#9) --- Project.toml | 6 +++--- jenkins/Jenkinsfile | 4 ++-- src/ITensorGPU.jl | 10 +++++----- test/test_cucontract.jl | 38 +++++++++++++++++++------------------- test/test_cudense.jl | 8 ++++---- test/test_cudiag.jl | 20 ++++++++++---------- test/test_cuitensor.jl | 2 +- test/test_cumpo.jl | 2 +- test/test_cumps.jl | 10 +++++----- test/test_dmrg.jl | 2 +- 10 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Project.toml b/Project.toml index 169a095..cf3f2b6 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ITensorGPU" uuid = "d89171c1-af8f-46b3-badf-d2a472317c15" authors = ["Katharine Hyatt", "Matthew Fishman "] -version = "0.2.2" +version = "0.2.3" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" @@ -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" diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index 35357fa..528a38a 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -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")' ''' } } @@ -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")' ''' } } diff --git a/src/ITensorGPU.jl b/src/ITensorGPU.jl index 96e7900..fc8f9b7 100644 --- a/src/ITensorGPU.jl +++ b/src/ITensorGPU.jl @@ -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 @@ -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 diff --git a/test/test_cucontract.jl b/test/test_cucontract.jl index 786f392..af671f4 100644 --- a/test/test_cucontract.jl +++ b/test/test_cucontract.jl @@ -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) @@ -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) diff --git a/test/test_cudense.jl b/test/test_cudense.jl index c6c3def..61755b9 100644 --- a/test/test_cudense.jl +++ b/test/test_cudense.jl @@ -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 @@ -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 diff --git a/test/test_cudiag.jl b/test/test_cudiag.jl index 6919d72..c676bd1 100644 --- a/test/test_cudiag.jl +++ b/test/test_cudiag.jl @@ -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) @@ -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) diff --git a/test/test_cuitensor.jl b/test/test_cuitensor.jl index 7bb7736..025ffa6 100644 --- a/test/test_cuitensor.jl +++ b/test/test_cuitensor.jl @@ -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) diff --git a/test/test_cumpo.jl b/test/test_cumpo.jl index 3444a66..9f42ff6 100644 --- a/test/test_cumpo.jl +++ b/test/test_cumpo.jl @@ -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 diff --git a/test/test_cumps.jl b/test/test_cumps.jl index b7c435f..b53191b 100644 --- a/test/test_cumps.jl +++ b/test/test_cumps.jl @@ -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))) @@ -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 @@ -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] @@ -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) diff --git a/test/test_dmrg.jl b/test/test_dmrg.jl index 590b496..bab9136 100644 --- a/test/test_dmrg.jl +++ b/test/test_dmrg.jl @@ -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)