Skip to content

Commit

Permalink
nicer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
araujoms committed Dec 17, 2024
1 parent dd66a8e commit 4f3dda2
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 167 deletions.
29 changes: 11 additions & 18 deletions test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
@testset "Kets" begin
@test isa(ket(1, 3), Vector{Bool})
@test isa(proj(1, 3), Hermitian{Bool})
for R in [Int64, Float64, Double64, Float128, BigFloat]
ψ = ket(R, 2, 3)
P = proj(R, 2, 3)
@test ψ == [0, 1, 0]
@test isa(ψ, Vector{R})
@test isa(P, Hermitian{R})
@test P == ketbra(ψ)
T = Complex{R}
for R (Int64, Float64, Double64, Float128, BigFloat), T (R, Complex{R})
ψ = ket(T, 2, 3)
P = proj(T, 2, 3)
@test ψ == [0, 1, 0]
Expand All @@ -22,7 +15,7 @@
@test isa(shift(4), Matrix{ComplexF64})
@test clock(4) == Diagonal([1, im, -1, -im])
@test isa(clock(4), Diagonal{ComplexF64})
for R in [Float64, Double64, Float128, BigFloat]
for R (Float64, Double64, Float128, BigFloat)
T = Complex{R}
@test shift(T, 3) == [0 0 1; 1 0 0; 0 1 0]
@test clock(T, 3) Diagonal([1, exp(2 * T(π) * im / 3), exp(-2 * T(π) * im / 3)])
Expand All @@ -31,7 +24,7 @@
end
end
@testset "Pauli" begin
for R in [Int64, Float64, Double64, Float128, BigFloat]
for R (Int64, Float64, Double64, Float128, BigFloat)
@test pauli(R, 0) == Matrix{R}(I, 2, 2)
@test pauli(R, "x") == [0 1; 1 0]
@test pauli(Complex{R}, 2) == [0 -im; im 0]
Expand All @@ -41,7 +34,7 @@
end
end
@testset "Gell-Mann" begin
for R in [Int64, Float64, Double64, Float128, BigFloat]
for R (Int64, Float64, Double64, Float128, BigFloat)
@test gellmann(R, 1, 1) == Matrix{R}(I, 3, 3)
@test gellmann(R, 1, 2) == [0 1 0; 1 0 0; 0 0 0]
@test gellmann(R, 1, 3) == [0 0 1; 0 0 0; 1 0 0]
Expand All @@ -55,9 +48,9 @@
@test gellmann(1, 1, 4) == Matrix{Float64}(I, 4, 4)
end
@testset "Cleanup" begin
for R in [Float64, Double64, Float128, BigFloat]
for R (Float64, Double64, Float128, BigFloat)
a = zeros(R, 2, 2)
a[1] = 0.5 * Ket._eps(R)
a[1] = 0.5 * _eps(R)
a[4] = 1
b = Hermitian(copy(a))
c = UpperTriangular(copy(a))
Expand All @@ -72,8 +65,8 @@
@test d == [0 0; 0 1]
T = Complex{R}
a = zeros(T, 2, 2)
a[1] = 0.5 * Ket._eps(T) + im
a[3] = 1 + 0.5 * Ket._eps(T) * im
a[1] = 0.5 * _eps(T) + im
a[3] = 1 + 0.5 * _eps(T) * im
a[4] = 1
b = Hermitian(copy(a))
c = UpperTriangular(copy(a))
Expand All @@ -89,15 +82,15 @@
end
end
@testset "Orthonormal range" begin
for R in [Float64, Double64, Float128, BigFloat, ComplexF64]
for T (Float64, Double64, Float128, BigFloat, ComplexF64)
for _ in 1:10
d1 = rand(5:20)
d2 = rand(5:20)
a = rand(R, d1, d2)
a = rand(T, d1, d2)
s = orthonormal_range(a; mode = 1)
@test size(s, 2) == rank(a)
@test rank(hcat(s, a)) == size(s, 2)
if R == Float64 || R == ComplexF64
if T == Float64 || T == ComplexF64
q = orthonormal_range(SparseArrays.sparse(a); mode = 0)
@test size(s, 2) == size(q, 2)
@test rank(hcat(q, a)) == size(q, 2)
Expand Down
20 changes: 4 additions & 16 deletions test/entanglement.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@testset "Entanglement " begin
@testset "Schmidt decomposition" begin
for R in [Float64, Double64, Float128, BigFloat]
for R (Float64, Double64, Float128, BigFloat)
T = Complex{R}
ψ = random_state_ket(T, 6)
λ, U, V = schmidt_decomposition(ψ, [2, 3])
Expand All @@ -11,14 +11,8 @@
end
end
@testset "Entanglement entropy" begin
for R in [Float64, Double64] #Float128 and BigFloat take too long
for R (Float64, Double64), T (R, Complex{R}) #Float128 and BigFloat take too long
Random.seed!(8) #makes all states entangled
ψ = random_state_ket(R, 6)
@test entanglement_entropy(ψ, [2, 3]) entanglement_entropy(ketbra(ψ), [2, 3])[1] atol = 1.0e-3 rtol = 1.0e-3
ρ = random_state(R, 4)
h, σ = entanglement_entropy(ρ)
@test Ket._test_entanglement_entropy_qubit(h, ρ, σ)
T = Complex{R}
ψ = random_state_ket(T, 6)
@test entanglement_entropy(ψ, [2, 3]) entanglement_entropy(ketbra(ψ), [2, 3])[1] atol = 1.0e-3 rtol = 1.0e-3
ρ = random_state(T, 4)
Expand All @@ -27,13 +21,7 @@
end
end
@testset "DPS hierarchy" begin
for R in [Float64, Double64]
ρ = state_ghz(R, 2, 2)
s, W = random_robustness(ρ)
@test eltype(W) == R
@test s 0.5 atol = 1.0e-5 rtol = 1.0e-5
@test dot(ρ, W) -s atol = 1.0e-5 rtol = 1.0e-5
T = Complex{R}
for R (Float64, Double64), T (R, Complex{R})
ρ = state_ghz(T, 2, 2)
s, W = random_robustness(ρ)
@test eltype(W) == T
Expand All @@ -51,7 +39,7 @@
@test schmidt_number(random_state(Float64, 6), 2, [2, 3], 1; solver = SCS.Optimizer) <= 0
end
@testset "GME entanglement" begin
for R in [Float64, Double64]
for R (Float64, Double64)
ρ = state_ghz(R, 2, 3)

v, W = ppt_mixture(ρ, [2, 2, 2])
Expand Down
Loading

0 comments on commit 4f3dda2

Please sign in to comment.