From 8a2abcec67c8c4b4e518c3873d0dddd2624cb9cf Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Thu, 24 Oct 2024 20:05:28 -0400 Subject: [PATCH] [NDTensors] Remove `ITensors` dependency from tests (#1553) * [NDTensors] Remove `ITensors` dependency from tests * [NDTensors] Bump to v0.3.47 * [ITensors] Move NDTensorsMappedArraysExt test to ITensors testsuite * [ITensors] Bump to v0.6.23 --- NDTensors/Project.toml | 2 +- NDTensors/test/ITensors/Project.toml | 4 -- .../ITensors/TestITensorDMRG/Project.toml | 6 --- .../TestITensorDMRG/TestITensorDMRG.jl | 20 ---------- .../test/ITensors/TestITensorDMRG/dmrg.jl | 35 ------------------ NDTensors/test/ITensors/runtests.jl | 37 ------------------- NDTensors/test/Project.toml | 5 +-- NDTensors/test/ext/runtests.jl | 12 ------ NDTensors/test/runtests.jl | 2 +- NDTensors/test/test_combiner.jl | 34 +++++++++++++++-- Project.toml | 2 +- test/Project.toml | 1 + .../NDTensorsMappedArraysExt}/Project.toml | 3 +- .../ext/NDTensorsMappedArraysExt/runtests.jl | 0 test/runtests.jl | 1 + 15 files changed, 40 insertions(+), 124 deletions(-) delete mode 100644 NDTensors/test/ITensors/Project.toml delete mode 100644 NDTensors/test/ITensors/TestITensorDMRG/Project.toml delete mode 100644 NDTensors/test/ITensors/TestITensorDMRG/TestITensorDMRG.jl delete mode 100644 NDTensors/test/ITensors/TestITensorDMRG/dmrg.jl delete mode 100644 NDTensors/test/ITensors/runtests.jl delete mode 100644 NDTensors/test/ext/runtests.jl rename {NDTensors/test/ext => test/ext/NDTensorsMappedArraysExt}/Project.toml (52%) rename NDTensors/test/ext/test_mappedarraysext.jl => test/ext/NDTensorsMappedArraysExt/runtests.jl (100%) diff --git a/NDTensors/Project.toml b/NDTensors/Project.toml index cdfd6102bb..eb46bba0e9 100644 --- a/NDTensors/Project.toml +++ b/NDTensors/Project.toml @@ -1,7 +1,7 @@ name = "NDTensors" uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" authors = ["Matthew Fishman "] -version = "0.3.46" +version = "0.3.47" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" diff --git a/NDTensors/test/ITensors/Project.toml b/NDTensors/test/ITensors/Project.toml deleted file mode 100644 index 7ee8b76af0..0000000000 --- a/NDTensors/test/ITensors/Project.toml +++ /dev/null @@ -1,4 +0,0 @@ -[deps] -ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" -NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" -SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" diff --git a/NDTensors/test/ITensors/TestITensorDMRG/Project.toml b/NDTensors/test/ITensors/TestITensorDMRG/Project.toml deleted file mode 100644 index 7f3412606e..0000000000 --- a/NDTensors/test/ITensors/TestITensorDMRG/Project.toml +++ /dev/null @@ -1,6 +0,0 @@ -[deps] -ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" -NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/NDTensors/test/ITensors/TestITensorDMRG/TestITensorDMRG.jl b/NDTensors/test/ITensors/TestITensorDMRG/TestITensorDMRG.jl deleted file mode 100644 index fd441d7845..0000000000 --- a/NDTensors/test/ITensors/TestITensorDMRG/TestITensorDMRG.jl +++ /dev/null @@ -1,20 +0,0 @@ -## This is getting closer still working on it. No need to review -## Failing for CUDA mostly with eigen (I believe there is some noise in -## eigen decomp with CUBLAS to give slightly different answer than BLAS) -module TestITensorDMRG -using ITensors -using NDTensors -using NDTensors.AMDGPUExtensions: roc -using NDTensors.CUDAExtensions: cu -using NDTensors.MetalExtensions: mtl -using Random - -reference_energies = Dict([ - (4, -1.6160254037844384), (8, -3.374932598687889), (10, -4.258035207282885) -]) - -is_broken(dev, elt::Type, conserve_qns::Val) = false - -include("dmrg.jl") - -end diff --git a/NDTensors/test/ITensors/TestITensorDMRG/dmrg.jl b/NDTensors/test/ITensors/TestITensorDMRG/dmrg.jl deleted file mode 100644 index 90146dbc91..0000000000 --- a/NDTensors/test/ITensors/TestITensorDMRG/dmrg.jl +++ /dev/null @@ -1,35 +0,0 @@ -using ITensors: MPO, OpSum, dmrg, random_mps, siteinds -using Random: Random -using Test: @test -include("../../NDTensorsTestUtils/NDTensorsTestUtils.jl") -using .NDTensorsTestUtils: default_rtol -# TODO: Include file with `reference_energies`. - -function test_dmrg( - elt, N::Integer; dev::Function, conserve_qns, rtol_scale=true, outputlevel=0 -) - sites = siteinds("S=1/2", N; conserve_qns) - - os = OpSum() - for j in 1:(N - 1) - os += "Sz", j, "Sz", j + 1 - os += 0.5, "S+", j, "S-", j + 1 - os += 0.5, "S-", j, "S+", j + 1 - end - - Random.seed!(1234) - init = j -> isodd(j) ? "↑" : "↓" - psi0 = dev(random_mps(elt, sites, init; linkdims=4)) - H = dev(MPO(elt, os, sites)) - - nsweeps = 3 - cutoff = [1e-3, 1e-13] - noise = [1e-6, 0] - ## running these with nsweeps = 100 and no maxdim - ## all problems do not have a maxlinkdim > 32 - maxdim = 32 - - energy, psi = dmrg(H, psi0; nsweeps, cutoff, maxdim, noise, outputlevel) - - @test energy ≈ reference_energies[N] rtol = rtol_scale * default_rtol(elt) -end diff --git a/NDTensors/test/ITensors/runtests.jl b/NDTensors/test/ITensors/runtests.jl deleted file mode 100644 index 3782d31e2c..0000000000 --- a/NDTensors/test/ITensors/runtests.jl +++ /dev/null @@ -1,37 +0,0 @@ -using SafeTestsets: @safetestset - -##TODO there is an issue with Metal and BlockSparse -@safetestset "Downstream tests for ITensor DMRG" begin - using Test: @testset - include("TestITensorDMRG/TestITensorDMRG.jl") - include("../NDTensorsTestUtils/NDTensorsTestUtils.jl") - using .NDTensorsTestUtils: devices_list, is_supported_eltype - @testset "Test DMRG $dev, $conserve_qns, $elt, $N" for dev in devices_list(ARGS), - conserve_qns in [false, true], - elt in (Float32, ComplexF32, Float64, ComplexF64), - N in [4, 10] - - if !is_supported_eltype(dev, elt) - continue - end - if TestITensorDMRG.is_broken(dev, elt, Val(conserve_qns)) - # TODO: Switch to `@test ... broken=true`, introduced - # in Julia 1.7. - @test_broken TestITensorDMRG.test_dmrg(elt, N; dev, conserve_qns) - else - TestITensorDMRG.test_dmrg(elt, N; dev, conserve_qns, outputlevel=0) - end - end - using ITensors.ITensorsNamedDimsArraysExt: to_nameddimsarray - ## Without this line this test was throwing an error of ``NDTensors` not defined` - using NDTensors: NDTensors - @testset "Test DMRG with NamedDimsArrays" for dev in (NDTensors.cpu,), - conserve_qns in [false], - elt in (Float32, Float64), - N in [4, 10] - - dev = dev ∘ to_nameddimsarray - # TODO: Investigate why this isn't accurate. - TestITensorDMRG.test_dmrg(elt, N; dev, conserve_qns, rtol_scale=10^3, outputlevel=0) - end -end diff --git a/NDTensors/test/Project.toml b/NDTensors/test/Project.toml index 15787f7fbb..5393f6b3f5 100644 --- a/NDTensors/test/Project.toml +++ b/NDTensors/test/Project.toml @@ -7,7 +7,6 @@ Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4" EllipsisNotation = "da5c29d0-fa7d-589e-88eb-ea29b0a81949" FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527" -ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" @@ -23,12 +22,12 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [compat] -cuTENSOR = "2.0" Metal = "1.1.0" +cuTENSOR = "2.0" [extras] AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e" CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" -cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1" Metal = "dde4c033-4e86-420c-a63e-0dd931031962" TBLIS = "48530278-0828-4a49-9772-0f3830dfa1e9" +cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1" diff --git a/NDTensors/test/ext/runtests.jl b/NDTensors/test/ext/runtests.jl deleted file mode 100644 index d9f34a4f70..0000000000 --- a/NDTensors/test/ext/runtests.jl +++ /dev/null @@ -1,12 +0,0 @@ -@eval module $(gensym()) -using Test: @testset -@testset "$(@__DIR__)" begin - filenames = filter(readdir(@__DIR__)) do f - startswith("test_")(f) && endswith(".jl")(f) - end - @testset "Test $(@__DIR__)/$filename" for filename in filenames - println("Running $(@__DIR__)/$filename") - include(filename) - end -end -end diff --git a/NDTensors/test/runtests.jl b/NDTensors/test/runtests.jl index 5a43e4ee90..b073a05e2d 100644 --- a/NDTensors/test/runtests.jl +++ b/NDTensors/test/runtests.jl @@ -7,7 +7,7 @@ using SafeTestsets: @safetestset filenames = filter(readdir(@__DIR__)) do f startswith("test_")(f) && endswith(".jl")(f) end - for dir in ["lib", "ext", "ITensors"] + for dir in ["lib"] push!(filenames, joinpath(dir, "runtests.jl")) end @testset "Test $(@__DIR__)/$filename" for filename in filenames diff --git a/NDTensors/test/test_combiner.jl b/NDTensors/test/test_combiner.jl index 989b0701c9..b9e6d3e77c 100644 --- a/NDTensors/test/test_combiner.jl +++ b/NDTensors/test/test_combiner.jl @@ -1,12 +1,40 @@ @eval module $(gensym()) -using NDTensors -using Test: @testset, @test, @test_throws using GPUArraysCore: @allowscalar +using NDTensors: + NDTensors, + Block, + BlockOffsets, + BlockSparse, + BlockSparseTensor, + Combiner, + Dense, + DenseTensor, + contract, + dim, + dims, + tensor include("NDTensorsTestUtils/NDTensorsTestUtils.jl") using .NDTensorsTestUtils: devices_list, is_supported_eltype +using Test: @testset, @test, @test_throws # Testing generic block indices -using ITensors: QN, Index +struct Index{Space} + space::Space +end +NDTensors.dim(i::Index) = sum(b -> last(b), i.space) +NDTensors.nblocks(i::Index) = length(i.space) +NDTensors.blockdim(i::Index, block::Integer) = last(i.space[block]) +function NDTensors.outer(i1::Index, i2::Index) + return Index(vec( + map(Iterators.product(i1.space, i2.space)) do (b1, b2) + return first(b1) + first(b2) => last(b1) * last(b2) + end, + )) +end +NDTensors.permuteblocks(i::Index, perm::Vector{Int}) = Index(i.space[perm]) + +struct QN end +Base.:+(q1::QN, q2::QN) = QN() @testset "CombinerTensor basic functionality" begin @testset "test device: $dev, eltype: $elt" for dev in devices_list(copy(ARGS)), diff --git a/Project.toml b/Project.toml index f7f9e50b0a..4c9832a432 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ITensors" uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5" authors = ["Matthew Fishman ", "Miles Stoudenmire "] -version = "0.6.22" +version = "0.6.23" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/test/Project.toml b/test/Project.toml index 509e3a49f0..9974c37a38 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -10,6 +10,7 @@ ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" OptimKit = "77e91f04-9b3b-57a6-a776-40b61faaebe0" PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d" diff --git a/NDTensors/test/ext/Project.toml b/test/ext/NDTensorsMappedArraysExt/Project.toml similarity index 52% rename from NDTensors/test/ext/Project.toml rename to test/ext/NDTensorsMappedArraysExt/Project.toml index df085f1623..2236ea0414 100644 --- a/NDTensors/test/ext/Project.toml +++ b/test/ext/NDTensorsMappedArraysExt/Project.toml @@ -1,4 +1,5 @@ [deps] ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" -NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/NDTensors/test/ext/test_mappedarraysext.jl b/test/ext/NDTensorsMappedArraysExt/runtests.jl similarity index 100% rename from NDTensors/test/ext/test_mappedarraysext.jl rename to test/ext/NDTensorsMappedArraysExt/runtests.jl diff --git a/test/runtests.jl b/test/runtests.jl index 88af73a005..a0c92a13a1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -22,6 +22,7 @@ ITensors.disable_threaded_blocksparse() "ext/ITensorsChainRulesCoreExt", "ext/ITensorsPackageCompilerExt", "ext/ITensorsVectorInterfaceExt", + "ext/NDTensorsMappedArraysExt", ] @time for dir in dirs println("\nTest $(@__DIR__)/$(dir)")