From dc09fb988aec4a872d1f3f0eebbc1c41396fb38e Mon Sep 17 00:00:00 2001 From: mtfishman Date: Wed, 23 Oct 2024 10:31:50 -0400 Subject: [PATCH] Fix more tests --- test/base/runtests.jl | 10 ++++++++-- test/base/test_examples.jl | 9 +++------ test/base/test_exports.jl | 12 ------------ test/base/test_mpo.jl | 25 +++++++++++++------------ test/base/test_solvers/runtests.jl | 6 +++--- test/base/test_solvers/test_contract.jl | 3 +-- test/base/test_solvers/test_dmrg.jl | 10 +++++----- test/base/test_solvers/test_dmrg_x.jl | 4 ++-- test/base/test_solvers/test_examples.jl | 4 ++-- test/base/test_solvers/test_tdvp.jl | 14 ++++---------- test/runtests.jl | 4 ++-- 11 files changed, 43 insertions(+), 58 deletions(-) diff --git a/test/base/runtests.jl b/test/base/runtests.jl index c2fe5a8..68b8126 100644 --- a/test/base/runtests.jl +++ b/test/base/runtests.jl @@ -1,5 +1,5 @@ -using ITensors -using Test +using ITensors: ITensors +using Test: @testset ITensors.Strided.disable_threads() ITensors.BLAS.set_num_threads(1) @@ -13,4 +13,10 @@ ITensors.disable_threaded_blocksparse() println("Running $(@__DIR__)/$filename") @time include(filename) end + + test_dirs = ["test_solvers"] + @testset "Test $(@__DIR__)/$test_dir" for test_dir in test_dirs + println("Running $(@__DIR__)/$test_dir") + @time include(joinpath(@__DIR__, test_dir, "runtests.jl")) + end end diff --git a/test/base/test_examples.jl b/test/base/test_examples.jl index 2ba680e..5267f2d 100644 --- a/test/base/test_examples.jl +++ b/test/base/test_examples.jl @@ -1,5 +1,5 @@ @eval module $(gensym()) -using ITensors: ITensors +using ITensorMPS: ITensorMPS using Suppressor: @capture_out using Test: @test_nowarn, @testset @testset "Example Codes" begin @@ -8,10 +8,7 @@ using Test: @test_nowarn, @testset @capture_out begin include( joinpath( - pkgdir(ITensors), - "src", - "lib", - "ITensorMPS", + pkgdir(ITensorMPS), "examples", "dmrg", "1d_ising_with_observer.jl", @@ -25,7 +22,7 @@ using Test: @test_nowarn, @testset @capture_out begin include( joinpath( - pkgdir(ITensors), "ext", "ITensorsPackageCompilerExt", "precompile_itensors.jl" + pkgdir(ITensorMPS), "ext", "ITensorMPSPackageCompilerExt", "precompile_itensormps.jl" ), ) end diff --git a/test/base/test_exports.jl b/test/base/test_exports.jl index 7515de7..86e9d39 100644 --- a/test/base/test_exports.jl +++ b/test/base/test_exports.jl @@ -1,6 +1,5 @@ @eval module $(gensym()) using ITensorMPS: ITensorMPS -using ITensorTDVP: ITensorTDVP using ITensors: ITensors include("utils/TestITensorMPSExportedNames.jl") using Test: @test, @test_broken, @testset @@ -17,18 +16,7 @@ using Test: @test, @test_broken, @testset ], ) end - @testset "Aliases" begin - @test ITensorMPS.Experimental.dmrg === ITensorTDVP.dmrg - @test ITensorMPS.dmrg === ITensors.ITensorMPS.dmrg - end @testset "Not exported" begin - @test ITensorMPS.sortmergeterms === ITensors.ITensorMPS.sortmergeterms - # Should we fix this in ITensors.jl by adding: - # ```julia - # using .ITensorMPS: sortmergeterms - # ``` - # ? - @test_broken ITensorMPS.sortmergeterms === ITensors.sortmergeterms for f in [ :AbstractProjMPO, :AbstractMPS, diff --git a/test/base/test_mpo.jl b/test/base/test_mpo.jl index 929eaa2..047e738 100644 --- a/test/base/test_mpo.jl +++ b/test/base/test_mpo.jl @@ -1,5 +1,6 @@ @eval module $(gensym()) using Combinatorics +using ITensorMPS using ITensors using NDTensors: scalartype using StableRNGs: StableRNG @@ -195,11 +196,11 @@ end # generic tags and prime levels Kgen = replacetags(K, "Site" => "OpOut"; plev=1) noprime!(replacetags!(Kgen, "Site" => "Kpsi"; plev=0)) - ITensors.sim!(siteinds, Kgen) + ITensorMPS.sim!(siteinds, Kgen) Jgen = replacetags(J, "Site" => "OpOut"; plev=1) noprime!(replacetags!(Jgen, "Site" => "Jphi"; plev=0)) - ITensors.sim!(siteinds, Jgen) + ITensorMPS.sim!(siteinds, Jgen) # make sure operators share site indices replaceinds!.(Jgen, siteinds(Jgen; tags="OpOut"), siteinds(Kgen; tags="OpOut")) @@ -466,7 +467,7 @@ end @test hassameinds(ψ[1], (s[1], s[1]', ls[1])) @test hassameinds(ψ[N], (s[N], s[N]', ls[N - 1])) @test prod(ψ) ≈ A - @test ITensors.orthocenter(ψ) == 4 + @test ITensorMPS.orthocenter(ψ) == 4 @test maxlinkdim(ψ) == 16 A = random_itensor(s..., prime.(s)...) @@ -475,7 +476,7 @@ end @test hassameinds(ψ[1], (s[1], s[1]', ls[1])) @test hassameinds(ψ[N], (s[N], s[N]', ls[N - 1])) @test prod(ψ) ≈ A - @test ITensors.orthocenter(ψ) == 4 + @test ITensorMPS.orthocenter(ψ) == 4 @test maxlinkdim(ψ) == 16 ψ0 = MPO(s, "Id") @@ -485,7 +486,7 @@ end @test hassameinds(ψ[1], (s[1], s[1]', ls[1])) @test hassameinds(ψ[N], (s[N], s[N]', ls[N - 1])) @test prod(ψ) ≈ A - @test ITensors.orthocenter(ψ) == 3 + @test ITensorMPS.orthocenter(ψ) == 3 @test maxlinkdim(ψ) == 1 # Use matrix @@ -499,7 +500,7 @@ end @test hassameinds(ψ[1], (s[1], s[1]', ls[1])) @test hassameinds(ψ[N], (s[N], s[N]', ls[N - 1])) @test prod(ψ) ≈ A - @test ITensors.orthocenter(ψ) == 3 + @test ITensorMPS.orthocenter(ψ) == 3 @test maxlinkdim(ψ) == 1 A = random_itensor(s..., prime.(s)..., l[1], r[1]) @@ -508,7 +509,7 @@ end @test hassameinds(ψ[1], (l[1], s[1], s[1]', ls[1])) @test hassameinds(ψ[N], (r[1], s[N], s[N]', ls[N - 1])) @test prod(ψ) ≈ A - @test ITensors.orthocenter(ψ) == N + @test ITensorMPS.orthocenter(ψ) == N @test maxlinkdim(ψ) == 48 A = random_itensor(s..., prime.(s)..., l[1], r[1]) @@ -517,7 +518,7 @@ end @test hassameinds(ψ[1], (l[1], s[1], s[1]', ls[1])) @test hassameinds(ψ[N], (r[1], s[N], s[N]', ls[N - 1])) @test prod(ψ) ≈ A - @test ITensors.orthocenter(ψ) == N + @test ITensorMPS.orthocenter(ψ) == N @test maxlinkdim(ψ) == 48 A = random_itensor(s..., prime.(s)..., l..., r...) @@ -526,7 +527,7 @@ end @test hassameinds(ψ[1], (l..., s[1], s[1]', ls[1])) @test hassameinds(ψ[N], (r..., s[N], s[N]', ls[N - 1])) @test @set_warn_order 15 prod(ψ) ≈ A - @test ITensors.orthocenter(ψ) == 2 + @test ITensorMPS.orthocenter(ψ) == 2 @test maxlinkdim(ψ) == 144 A = random_itensor(s..., prime.(s)..., l..., r...) @@ -535,7 +536,7 @@ end @test hassameinds(ψ[1], (l..., s[1], s[1]', ls[1])) @test hassameinds(ψ[N], (r..., s[N], s[N]', ls[N - 1])) @test @set_warn_order 15 prod(ψ) ≈ A - @test ITensors.orthocenter(ψ) == 2 + @test ITensorMPS.orthocenter(ψ) == 2 @test maxlinkdim(ψ) == 144 end @@ -551,7 +552,7 @@ end ψ[2:(N - 1)] = ϕ @test prod(ψ) ≈ ψ[1] * A * ψ[N] @test maxlinkdim(ψ) == 4 - @test ITensors.orthocenter(ψ) == 2 + @test ITensorMPS.orthocenter(ψ) == 2 ψ = orthogonalize(ψ0, 1) A = prod(ITensors.data(ψ)[2:(N - 1)]) @@ -564,7 +565,7 @@ end ψ[2:(N - 1), orthocenter=3] = A @test prod(ψ) ≈ ψ[1] * A * ψ[N] @test maxlinkdim(ψ) == 4 - @test ITensors.orthocenter(ψ) == 3 + @test ITensorMPS.orthocenter(ψ) == 3 end @testset "swapbondsites MPO" begin diff --git a/test/base/test_solvers/runtests.jl b/test/base/test_solvers/runtests.jl index 5691f1f..44e961e 100644 --- a/test/base/test_solvers/runtests.jl +++ b/test/base/test_solvers/runtests.jl @@ -1,11 +1,11 @@ @eval module $(gensym()) using Test: @testset -using ITensorTDVP: ITensorTDVP -test_path = joinpath(pkgdir(ITensorTDVP), "test") +using ITensorMPS: ITensorMPS +test_path = joinpath(pkgdir(ITensorMPS), "test") test_files = filter( file -> startswith(file, "test_") && endswith(file, ".jl"), readdir(test_path) ) -@testset "ITensorTDVP.jl" begin +@testset "ITensorMPS.jl" begin @testset "$filename" for filename in test_files println("Running $filename") @time include(joinpath(test_path, filename)) diff --git a/test/base/test_solvers/test_contract.jl b/test/base/test_solvers/test_contract.jl index e0dc288..8fc0390 100644 --- a/test/base/test_solvers/test_contract.jl +++ b/test/base/test_solvers/test_contract.jl @@ -1,7 +1,6 @@ @eval module $(gensym()) using ITensors: ITensors, dag, delta, denseblocks -using ITensors: MPO, OpSum, apply, contract, inner, random_mps, siteinds, truncate! -using ITensorTDVP: ITensorTDVP +using ITensorMPS: MPO, OpSum, apply, contract, inner, random_mps, siteinds, truncate! using StableRNGs: StableRNG using Test: @test, @test_throws, @testset @testset "Contract MPO (eltype=$elt, conserve_qns=$conserve_qns)" for elt in ( diff --git a/test/base/test_solvers/test_dmrg.jl b/test/base/test_solvers/test_dmrg.jl index a7237c8..faa3438 100644 --- a/test/base/test_solvers/test_dmrg.jl +++ b/test/base/test_solvers/test_dmrg.jl @@ -1,6 +1,6 @@ @eval module $(gensym()) -using ITensors: ITensors, MPO, OpSum, inner, random_mps, siteinds -using ITensorTDVP: ITensorTDVP +using ITensors: ITensors +using ITensorMPS: Experimental, MPO, OpSum, inner, random_mps, siteinds using StableRNGs: StableRNG using Test: @test, @test_throws, @testset @testset "DMRG (eltype=$elt, nsite=$nsite, conserve_qns=$conserve_qns)" for elt in ( @@ -23,12 +23,12 @@ using Test: @test, @test_throws, @testset psi = random_mps(rng, elt, s, j -> isodd(j) ? "↑" : "↓"; linkdims=20) nsweeps = 10 maxdim = [10, 20, 40, 100] - @test_throws ErrorException ITensorTDVP.dmrg(H, psi; maxdim, cutoff, nsite) - e, psi = ITensorTDVP.dmrg( + @test_throws ErrorException Experimental.dmrg(H, psi; maxdim, cutoff, nsite) + e, psi = Experimental.dmrg( H, psi; nsweeps, maxdim, cutoff, nsite, updater_kwargs=(; krylovdim=3, maxiter=1) ) @test inner(psi', H, psi) ≈ e - e2, psi2 = ITensors.dmrg(H, psi; nsweeps, maxdim, cutoff, outputlevel=0) + e2, psi2 = dmrg(H, psi; nsweeps, maxdim, cutoff, outputlevel=0) @test ITensors.scalartype(psi2) == elt @test e2 isa real(elt) @test e ≈ e2 rtol = √(eps(real(elt))) * 10 diff --git a/test/base/test_solvers/test_dmrg_x.jl b/test/base/test_solvers/test_dmrg_x.jl index 17c8cf3..ee6b015 100644 --- a/test/base/test_solvers/test_dmrg_x.jl +++ b/test/base/test_solvers/test_dmrg_x.jl @@ -1,6 +1,6 @@ @eval module $(gensym()) -using ITensors: ITensors, MPO, MPS, OpSum, ProjMPO, inner, siteinds -using ITensorTDVP: dmrg_x +using ITensors: ITensors +using ITensorMPS: MPO, MPS, OpSum, ProjMPO, dmrg_x, inner, siteinds using Random: Random using StableRNGs: StableRNG using Test: @test, @test_throws, @testset diff --git a/test/base/test_solvers/test_examples.jl b/test/base/test_solvers/test_examples.jl index 88f0ac7..3e0f481 100644 --- a/test/base/test_solvers/test_examples.jl +++ b/test/base/test_solvers/test_examples.jl @@ -1,12 +1,12 @@ @eval module $(gensym()) using Suppressor: @suppress -using ITensorTDVP: ITensorTDVP +using ITensorMPS: ITensorMPS using Test: @testset @testset "Run examples" begin examples_files = [ "01_tdvp.jl", "02_dmrg-x.jl", "03_tdvp_time_dependent.jl", "04_tdvp_observers.jl" ] - examples_path = joinpath(pkgdir(ITensorTDVP), "examples") + examples_path = joinpath(pkgdir(ITensorMPS), "examples") @testset "Running example file $f" for f in examples_files println("Running example file $f") @suppress include(joinpath(examples_path, f)) diff --git a/test/base/test_solvers/test_tdvp.jl b/test/base/test_solvers/test_tdvp.jl index 3e032d0..a135742 100644 --- a/test/base/test_solvers/test_tdvp.jl +++ b/test/base/test_solvers/test_tdvp.jl @@ -1,22 +1,16 @@ @eval module $(gensym()) -using ITensors: - ITensors, +using ITensorMPS: AbstractObserver, - ITensor, MPO, MPS, OpSum, apply, - dag, expect, inner, - noprime, - op, - prime, random_mps, - scalar, - siteinds -using ITensorTDVP: ITensorTDVP, tdvp + siteinds, + tdvp +using ITensors: ITensors, ITensor, dag, noprime, op, prime, scalar using KrylovKit: exponentiate using LinearAlgebra: norm using Observers: observer diff --git a/test/runtests.jl b/test/runtests.jl index 730a18d..1c7c6bd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ -using ITensors -using Test +using ITensors: ITensors +using Test: @testset ITensors.Strided.disable_threads() ITensors.BLAS.set_num_threads(1)