Skip to content

Commit

Permalink
Divide some tests into sub-testsets (qutip#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertomercurio authored Jul 11, 2024
2 parents b225542 + e351356 commit 4ad239b
Show file tree
Hide file tree
Showing 10 changed files with 884 additions and 810 deletions.
8 changes: 4 additions & 4 deletions src/qobj/quantum_object.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ Returns the length of the matrix or vector corresponding to the [`QuantumObject`
Base.length(A::QuantumObject{<:AbstractArray{T}}) where {T} = length(A.data)

Base.isequal(A::QuantumObject{<:AbstractArray{T}}, B::QuantumObject{<:AbstractArray{T}}) where {T} =
isequal(A.data, B.data) && isequal(A.type, B.type) && isequal(A.dims, B.dims)
Base.isapprox(A::QuantumObject{<:AbstractArray{T}}, B::QuantumObject{<:AbstractArray{T}}) where {T} =
isapprox(A.data, B.data) && isequal(A.type, B.type) && isequal(A.dims, B.dims)
isequal(A.type, B.type) && isequal(A.dims, B.dims) && isequal(A.data, B.data)
Base.isapprox(A::QuantumObject{<:AbstractArray{T}}, B::QuantumObject{<:AbstractArray{T}}; kwargs...) where {T} =
isequal(A.type, B.type) && isequal(A.dims, B.dims) && isapprox(A.data, B.data; kwargs...)
Base.:(==)(A::QuantumObject{<:AbstractArray{T}}, B::QuantumObject{<:AbstractArray{T}}) where {T} =
(A.data == B.data) && (A.type == B.type) && (A.dims == B.dims)
(A.type == B.type) && (A.dims == B.dims) && (A.data == B.data)

SparseArrays.sparse(A::QuantumObject{<:AbstractArray{T}}) where {T} = QuantumObject(sparse(A.data), A.type, A.dims)
SparseArrays.nnz(A::QuantumObject{<:AbstractSparseArray}) = nnz(A.data)
Expand Down
5 changes: 0 additions & 5 deletions test/aqua.jl

This file was deleted.

11 changes: 11 additions & 0 deletions test/code_quality.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Aqua, JET

@testset "Code quality" verbose = true begin
@testset "Aqua.jl" begin
Aqua.test_all(QuantumToolbox; ambiguities = false)
end

@testset "JET.jl" begin
JET.test_package(QuantumToolbox; target_defined_modules = true, ignore_missing_comparison = true)
end
end
2 changes: 1 addition & 1 deletion test/cuda_ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using CUDA.CUSPARSE
QuantumToolbox.about()
CUDA.versioninfo()

@testset "CUDA Extension" begin
@testset "CUDA Extension" verbose = true begin
ψdi = Qobj(Int64[1, 0])
ψdf = Qobj(Float64[1, 0])
ψdc = Qobj(ComplexF64[1, 0])
Expand Down
5 changes: 0 additions & 5 deletions test/jet.jl

This file was deleted.

56 changes: 29 additions & 27 deletions test/negativity_and_partial_transpose.jl
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
@testset "Negativity and Partial Transpose" begin
# tests for negativity
rho = (1 / 40) * Qobj(
[
15 1 1 15
1 5 -3 1
1 -3 5 1
15 1 1 15
];
dims = [2, 2],
)
Neg = negativity(rho, 1)
@test Neg 0.25
@test negativity(rho, 2) Neg
@test negativity(rho, 1; logarithmic = true) log2(2 * Neg + 1)
@test_throws ArgumentError negativity(rho, 3)
@testset "Negativity and Partial Transpose" verbose = true begin
@testset "negativity" begin
rho = (1 / 40) * Qobj(
[
15 1 1 15
1 5 -3 1
1 -3 5 1
15 1 1 15
];
dims = [2, 2],
)
Neg = negativity(rho, 1)
@test Neg 0.25
@test negativity(rho, 2) Neg
@test negativity(rho, 1; logarithmic = true) log2(2 * Neg + 1)
@test_throws ArgumentError negativity(rho, 3)
end

# tests for partial transpose (PT)
# A (24 * 24)-matrix which contains number 1 ~ 576
A_dense = Qobj(reshape(1:(24^2), (24, 24)), dims = [2, 3, 4])
A_sparse = dense_to_sparse(A_dense)
PT = (true, false)
for s1 in PT
for s2 in PT
for s3 in PT
mask = [s1, s2, s3]
@test partial_transpose(A_dense, mask) == partial_transpose(A_sparse, mask)
@testset "partial_transpose" begin
# A (24 * 24)-matrix which contains number 1 ~ 576
A_dense = Qobj(reshape(1:(24^2), (24, 24)), dims = [2, 3, 4])
A_sparse = dense_to_sparse(A_dense)
PT = (true, false)
for s1 in PT
for s2 in PT
for s3 in PT
mask = [s1, s2, s3]
@test partial_transpose(A_dense, mask) == partial_transpose(A_sparse, mask)
end
end
end
@test_throws ArgumentError partial_transpose(A_dense, [true])
end
@test_throws ArgumentError partial_transpose(rho, [true])
end
Loading

0 comments on commit 4ad239b

Please sign in to comment.