From 9a32b6a7ebaedb7f0aa286408e1c99fcb8874997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=9Amierzchalski?= <53766192+tomsmierz@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:21:14 +0200 Subject: [PATCH] Tests Fix (#26) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * quick fix, checks if gpu available * quick fix, added check if gpu avaiable * fix tuple --------- Co-authored-by: tomsmierz Co-authored-by: Łukasz Pawela --- test/canonise.jl | 5 +++-- test/projectors.jl | 38 ++++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/test/canonise.jl b/test/canonise.jl index 89e44d7..05e9639 100644 --- a/test/canonise.jl +++ b/test/canonise.jl @@ -6,7 +6,8 @@ d = [1, 2, 2, 2, 4, 2, 2] id = Dict(j => d[i] for (i, j) in enumerate(sites)) @testset "Random QMps ($T)" for T in (Float32, Float64) - for toCUDA ∈ (true, false) + checks = CUDA.functional() ? (true, false) : (false, ) + for toCUDA ∈ checks ψ = rand(QMps{T}, id, D) ϕ = rand(QMps{T}, id, D) @test is_consistent(ψ) @@ -35,7 +36,7 @@ id = Dict(j => d[i] for (i, j) in enumerate(sites)) end end -@testset "Measure spectrum($T)" for T in (Float32, Float64) +@testset "Measure spectrum ($T)" for T in (Float32, Float64) svd_mps = TensorMap{T}( 1 => T[ -0.694389933025747 -0.7195989305943268;;; diff --git a/test/projectors.jl b/test/projectors.jl index d255328..de6143a 100644 --- a/test/projectors.jl +++ b/test/projectors.jl @@ -31,23 +31,29 @@ end @testset "Different devices" begin + checks = CUDA.functional() ? (true, false) : (false) for T ∈ [Int16, Int32, Int64] - lp = PoolOfProjectors{T}() - p1 = Vector{T}([1, 1, 2, 2, 3, 3]) - p2 = Vector{T}([1, 2, 1, 3]) - k = add_projector!(lp, p1) - k = add_projector!(lp, p2) - - @test typeof(get_projector!(lp, 2, :CPU)) <: Array{T,1} - @test typeof(get_projector!(lp, 1, :GPU)) <: CuArray{T,1} - @test length(lp, :GPU) == 1 - @test length(lp, :CPU) == 2 - - @test typeof(get_projector!(lp, 1, :GPU)) <: CuArray{T,1} - @test length(lp, :GPU) == 1 - - @test typeof(get_projector!(lp, 2, :GPU)) <: CuArray{T,1} - @test length(lp, :GPU) == 2 + for toCUDA ∈ checks + lp = PoolOfProjectors{T}() + p1 = Vector{T}([1, 1, 2, 2, 3, 3]) + p2 = Vector{T}([1, 2, 1, 3]) + k = add_projector!(lp, p1) + k = add_projector!(lp, p2) + + if toCUDA + @test typeof(get_projector!(lp, 1, :GPU)) <: CuArray{T,1} + @test length(lp, :GPU) == 1 + + @test typeof(get_projector!(lp, 1, :GPU)) <: CuArray{T,1} + @test length(lp, :GPU) == 1 + + @test typeof(get_projector!(lp, 2, :GPU)) <: CuArray{T,1} + @test length(lp, :GPU) == 2 + end + + @test typeof(get_projector!(lp, 2, :CPU)) <: Array{T,1} + @test length(lp, :CPU) == 2 + end end end end