Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Oct 23, 2024
1 parent 17b4543 commit dc09fb9
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 58 deletions.
10 changes: 8 additions & 2 deletions test/base/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ITensors
using Test
using ITensors: ITensors
using Test: @testset

ITensors.Strided.disable_threads()
ITensors.BLAS.set_num_threads(1)
Expand All @@ -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
9 changes: 3 additions & 6 deletions test/base/test_examples.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand All @@ -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
Expand Down
12 changes: 0 additions & 12 deletions test/base/test_exports.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
25 changes: 13 additions & 12 deletions test/base/test_mpo.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@eval module $(gensym())
using Combinatorics
using ITensorMPS
using ITensors
using NDTensors: scalartype
using StableRNGs: StableRNG
Expand Down Expand Up @@ -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"))

Expand Down Expand Up @@ -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)...)
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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])
Expand All @@ -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])
Expand All @@ -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...)
Expand All @@ -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...)
Expand All @@ -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

Expand All @@ -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)])
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/base/test_solvers/runtests.jl
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
3 changes: 1 addition & 2 deletions test/base/test_solvers/test_contract.jl
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
10 changes: 5 additions & 5 deletions test/base/test_solvers/test_dmrg.jl
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/base/test_solvers/test_dmrg_x.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/base/test_solvers/test_examples.jl
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
14 changes: 4 additions & 10 deletions test/base/test_solvers/test_tdvp.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ITensors
using Test
using ITensors: ITensors
using Test: @testset

ITensors.Strided.disable_threads()
ITensors.BLAS.set_num_threads(1)
Expand Down

0 comments on commit dc09fb9

Please sign in to comment.