Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,4 @@ SparseArrays = "1"
SpecialFunctions = "2"
StaticArraysCore = "1"
StochasticDiffEq = "6"
Test = "1"
julia = "1.10"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
6 changes: 6 additions & 0 deletions docs/src/resources/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ The tests are divided into several test groups, where the group names are define
make GROUP=Core test
```

### [Test Item Framework for Core tests](@id doc-Contribute:Test-Item-Framework-for-Core-tests)

The tests in `GROUP=Core` are provided using the [Test Item Framework](https://www.julia-vscode.org/docs/stable/userguide/testitems/), which structures the test codes into `@testitems` and makes it easier to run individually.

The [VS Code](https://code.visualstudio.com/) and its [Julia extension](https://www.julia-vscode.org/) provides us with options to run individual `@testitems`. It is much easier to find the specific core test that failed since the [Julia extension](https://www.julia-vscode.org/) in [VS Code](https://code.visualstudio.com/) will collect all core test failures and then display them in a structured way, directly at the place in the code where a specific core test failed. See [here](https://www.julia-vscode.org/docs/stable/userguide/testitems/) for more details.

## [Julia Code Format](@id doc-Contribute:Julia-Code-Format)

We use [`JuliaFormatter.jl`](https://github.com/domluna/JuliaFormatter.jl) to format all the source codes. The code style and extra formatting options is defined in the file `.JuliaFormatter.toml` in the repository.
Expand Down
12 changes: 12 additions & 0 deletions src/qobj/quantum_object_base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,53 @@
"""
struct Bra <: QuantumObjectType end

Base.show(io::IO, ::Bra) = print(io, "Bra()")

Check warning on line 33 in src/qobj/quantum_object_base.jl

View check run for this annotation

Codecov / codecov/patch

src/qobj/quantum_object_base.jl#L33

Added line #L33 was not covered by tests

@doc raw"""
Ket <: QuantumObjectType
Constructor representing a ket state ``|\psi\rangle``.
"""
struct Ket <: QuantumObjectType end

Base.show(io::IO, ::Ket) = print(io, "Ket()")

Check warning on line 42 in src/qobj/quantum_object_base.jl

View check run for this annotation

Codecov / codecov/patch

src/qobj/quantum_object_base.jl#L42

Added line #L42 was not covered by tests

@doc raw"""
Operator <: QuantumObjectType
Constructor representing an operator ``\hat{O}``.
"""
struct Operator <: QuantumObjectType end

Base.show(io::IO, ::Operator) = print(io, "Operator()")

Check warning on line 51 in src/qobj/quantum_object_base.jl

View check run for this annotation

Codecov / codecov/patch

src/qobj/quantum_object_base.jl#L51

Added line #L51 was not covered by tests

@doc raw"""
SuperOperator <: SuperOperatorType
Constructor representing a super-operator ``\hat{\mathcal{O}}`` acting on vectorized density operator matrices.
"""
struct SuperOperator <: SuperOperatorType end

Base.show(io::IO, ::SuperOperator) = print(io, "SuperOperator()")

Check warning on line 60 in src/qobj/quantum_object_base.jl

View check run for this annotation

Codecov / codecov/patch

src/qobj/quantum_object_base.jl#L60

Added line #L60 was not covered by tests

@doc raw"""
OperatorBra <: QuantumObjectType
Constructor representing a bra state in the [`SuperOperator`](@ref) formalism ``\langle\langle\rho|``.
"""
struct OperatorBra <: QuantumObjectType end

Base.show(io::IO, ::OperatorBra) = print(io, "OperatorBra()")

Check warning on line 69 in src/qobj/quantum_object_base.jl

View check run for this annotation

Codecov / codecov/patch

src/qobj/quantum_object_base.jl#L69

Added line #L69 was not covered by tests

@doc raw"""
OperatorKet <: QuantumObjectType
Constructor representing a ket state in the [`SuperOperator`](@ref) formalism ``|\rho\rangle\rangle``.
"""
struct OperatorKet <: QuantumObjectType end

Base.show(io::IO, ::OperatorKet) = print(io, "OperatorKet()")

Check warning on line 78 in src/qobj/quantum_object_base.jl

View check run for this annotation

Codecov / codecov/patch

src/qobj/quantum_object_base.jl#L78

Added line #L78 was not covered by tests

@doc raw"""
size(A::AbstractQuantumObject)
size(A::AbstractQuantumObject, idx::Int)
Expand Down
14 changes: 14 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"

[compat]
Pkg = "1"
Test = "1"
TestItemRunner = "1"
2 changes: 1 addition & 1 deletion test/core-test/block_diagonal_form.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "Block Diagonal Form" begin
@testitem "Block Diagonal Form" begin
# Block Diagonal Form
N = 20
Δ = 0
Expand Down
1 change: 1 addition & 0 deletions test/core-test/code-quality/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
QuantumToolbox = "6c2fb7c5-b903-41d2-bc5e-5a7c320b9fab"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Aqua = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion test/core-test/correlations_and_spectrum.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "Correlations and Spectrum" begin
@testitem "Correlations and Spectrum" begin
N = 10
Id = qeye(N)
a = destroy(N)
Expand Down
2 changes: 1 addition & 1 deletion test/core-test/dynamical-shifted-fock.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "Dynamical Shifted Fock" begin
@testitem "Dynamical Shifted Fock" begin
F = 3
Δ = 0.25
κ = 1
Expand Down
2 changes: 1 addition & 1 deletion test/core-test/dynamical_fock_dimension_mesolve.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### DYNAMICAL FOCK DIMENSION ###
@testset "Dynamical Fock Dimension" begin
@testitem "Dynamical Fock Dimension" begin
F, Δ, κ = 5, 0.25, 1
t_l = range(0, 15, length = 100)

Expand Down
2 changes: 1 addition & 1 deletion test/core-test/eigenvalues_and_operators.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "Eigenvalues and Operators" begin
@testitem "Eigenvalues and Operators" begin
σx = sigmax()
result = eigenstates(σx, sparse = false)
λd, ψd, Td = result
Expand Down
8 changes: 4 additions & 4 deletions test/core-test/entropy_and_metric.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "entropy" begin
@testitem "entropy" begin
base = 2
λ = rand()
ψ = rand_ket(10)
Expand Down Expand Up @@ -51,7 +51,7 @@
end
end

@testset "entanglement and concurrence" begin
@testitem "entanglement and concurrence" begin
# bell state
ψb = bell_state(Val(1), Val(0))
ρb = ket2dm(ψb)
Expand Down Expand Up @@ -87,7 +87,7 @@ end
end
end

@testset "trace and Hilbert-Schmidt distance" begin
@testitem "trace and Hilbert-Schmidt distance" begin
ψz0 = basis(2, 0)
ψz1 = basis(2, 1)
ρz0 = to_sparse(ket2dm(ψz0))
Expand Down Expand Up @@ -117,7 +117,7 @@ end
end
end

@testset "fidelity, Bures metric, and Hellinger distance" begin
@testitem "fidelity, Bures metric, and Hellinger distance" begin
M0 = rand_dm(5)
ψ1 = rand_ket(5)
ψ2 = rand_ket(5)
Expand Down
6 changes: 5 additions & 1 deletion test/core-test/generalized_master_equation.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
@testset "Generalized Master Equation" begin
@testitem "Generalized Master Equation" default_imports=false begin
using Test
using QuantumToolbox
import LinearAlgebra: triu

N_c = 30
N_trunc = 10
tol = 1e-14
Expand Down
10 changes: 7 additions & 3 deletions test/core-test/low_rank_dynamics.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
@testset "Low Rank Dynamics" begin
@testitem "Low Rank Dynamics" default_imports=false begin
using Test
using QuantumToolbox
import LinearAlgebra: Diagonal, mul!

# Define lattice
Nx, Ny = 2, 3
latt = Lattice(Nx = Nx, Ny = Ny)
Expand All @@ -14,12 +18,12 @@

i = 1
for j in 1:N_modes
i += 1
global i += 1
i <= M && (ϕ[i] = multisite_operator(latt, j => sigmap()) * ϕ[1])
end
for k in 1:(N_modes-1)
for l in (k+1):N_modes
i += 1
global i += 1
i <= M && (ϕ[i] = multisite_operator(latt, k => sigmap(), l => sigmap()) * ϕ[1])
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/core-test/negativity_and_partial_transpose.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "Negativity and Partial Transpose" verbose = true begin
@testitem "Negativity and Partial Transpose" begin
@testset "negativity" begin
rho = (1 / 40) * Qobj(
[
Expand Down
2 changes: 1 addition & 1 deletion test/core-test/progress_bar.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "Progress Bar" begin
@testitem "Progress Bar" begin
bar_width = 30
strLength = 67 + bar_width # including "\r" in the beginning of the string
prog = ProgressBar(bar_width, enable = true, bar_width = bar_width, interval = 0.2)
Expand Down
10 changes: 9 additions & 1 deletion test/core-test/quantum_objects.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
@testset "Quantum Objects" verbose = true begin
@testitem "Quantum Objects" default_imports=false begin
using Test
using QuantumToolbox

# Importing only the necessary functions to keep track the re-export of the functions
import LinearAlgebra: I, triu, tril, triu!, tril!
import SparseArrays: sparse, sprand, spzeros, nnz, SparseVector, SparseMatrixCSC
import StaticArraysCore: SVector

# ArgumentError: type is incompatible with vector or matrix
@testset "ArgumentError" begin
a = rand(ComplexF64, 2)
Expand Down
11 changes: 10 additions & 1 deletion test/core-test/quantum_objects_evo.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
@testset "Quantum Objects Evolution" verbose = true begin
@testitem "Quantum Objects Evolution" default_imports=false begin
using Test
using QuantumToolbox

# Importing only the necessary functions to keep track the re-export of the functions
import LinearAlgebra: I
import SparseArrays: sprand
import StaticArraysCore: SVector
import SciMLOperators: MatrixOperator, NullOperator, IdentityOperator

# DomainError: incompatible between size of array and type
@testset "Thrown Errors" begin
a = MatrixOperator(rand(ComplexF64, 3, 2))
Expand Down
10 changes: 9 additions & 1 deletion test/core-test/states_and_operators.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
@testset "States and Operators" verbose = true begin
@testitem "States and Operators" default_imports=false begin
using Test
using QuantumToolbox
import QuantumToolbox: position, momentum

# Importing only the necessary functions to keep track the re-export of the functions
import LinearAlgebra: I
import SparseArrays: sparse, spzeros, spdiagm, SparseMatrixCSC, AbstractSparseMatrix

@testset "zero state" begin
v1 = zero_ket(4)
v2 = zero_ket((2, 2))
Expand Down
2 changes: 1 addition & 1 deletion test/core-test/steady_state.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "Steady State" begin
@testitem "Steady State" begin
N = 10
a = destroy(N)
a_d = a'
Expand Down
7 changes: 6 additions & 1 deletion test/core-test/time_evolution.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
@testset "Time Evolution and Partial Trace" verbose = true begin
@testitem "Time Evolution and Partial Trace" default_imports=false begin
using Test
using QuantumToolbox
import Random: MersenneTwister
import SciMLOperators: MatrixOperator

# Global definition of the system
N = 10
a = kron(destroy(N), qeye(2))
Expand Down
2 changes: 1 addition & 1 deletion test/core-test/utilities.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "Utilities" verbose = true begin
@testitem "Utilities" begin
@testset "n_thermal" begin
ω1 = rand(Float64)
ω2 = rand(Float64)
Expand Down
2 changes: 1 addition & 1 deletion test/core-test/wigner.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "Wigner" begin
@testitem "Wigner" begin
α = 0.5 + 0.8im
ψ = coherent(30, α)
ρ = to_sparse(ket2dm(ψ), 1e-6)
Expand Down
2 changes: 1 addition & 1 deletion test/ext-test/cpu/autodiff/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
QuantumToolbox = "6c2fb7c5-b903-41d2-bc5e-5a7c320b9fab"
SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
2 changes: 1 addition & 1 deletion test/ext-test/cpu/autodiff/zygote.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "Zygote.jl Autodiff" verbose=true begin
@testset "Zygote Extension" verbose=true begin
@testset "sesolve" begin
coef_Ω(p, t) = p[1]

Expand Down
53 changes: 19 additions & 34 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,49 +1,28 @@
using Test
using TestItemRunner
using Pkg

# Importing only the necessary functions to keep track the re-export of the functions
import LinearAlgebra: Diagonal, I, mul!, triu, tril, triu!, tril!
import SparseArrays: sparse, sprand, spzeros, spdiagm, nnz, SparseVector, SparseMatrixCSC, AbstractSparseMatrix
import StaticArraysCore: SVector
const GROUP_LIST = String["All", "Core", "Code-Quality", "AutoDiff_Ext", "Makie_Ext", "CUDA_Ext"]

const GROUP = get(ENV, "GROUP", "All")
(GROUP in GROUP_LIST) || throw(ArgumentError("Unknown GROUP = $GROUP"))

const testdir = dirname(@__FILE__)

# Put core tests in alphabetical order
core_tests = [
"block_diagonal_form.jl",
"correlations_and_spectrum.jl",
"dynamical_fock_dimension_mesolve.jl",
"dynamical-shifted-fock.jl",
"eigenvalues_and_operators.jl",
"entropy_and_metric.jl",
"generalized_master_equation.jl",
"low_rank_dynamics.jl",
"negativity_and_partial_transpose.jl",
"progress_bar.jl",
"quantum_objects.jl",
"quantum_objects_evo.jl",
"states_and_operators.jl",
"steady_state.jl",
"time_evolution.jl",
"utilities.jl",
"wigner.jl",
]

# Core tests
if (GROUP == "All") || (GROUP == "Core")
using QuantumToolbox
import QuantumToolbox: position, momentum
import Random: MersenneTwister
import SciMLOperators: MatrixOperator, NullOperator, IdentityOperator
import QuantumToolbox

QuantumToolbox.about()

for test in core_tests
include(joinpath(testdir, "core-test", test))
end
println("\nStart running Core tests...\n")
@run_package_tests verbose=true
end

########################################################################
# Use traditional Test.jl instead of TestItemRunner.jl for other tests #
########################################################################

const testdir = dirname(@__FILE__)

if (GROUP == "All") || (GROUP == "Code-Quality")
Pkg.activate("core-test/code-quality")
Pkg.develop(PackageSpec(path = dirname(@__DIR__)))
Expand All @@ -52,6 +31,8 @@ if (GROUP == "All") || (GROUP == "Code-Quality")
using QuantumToolbox
using Aqua, JET

(GROUP == "Code-Quality") && QuantumToolbox.about() # print version info. for code quality CI in GitHub

include(joinpath(testdir, "core-test", "code-quality", "code_quality.jl"))
end

Expand All @@ -65,6 +46,8 @@ if (GROUP == "AutoDiff_Ext")
using Enzyme
using SciMLSensitivity

QuantumToolbox.about()

include(joinpath(testdir, "ext-test", "cpu", "autodiff", "zygote.jl"))
end

Expand All @@ -86,6 +69,8 @@ if (GROUP == "CUDA_Ext")
Pkg.instantiate()

using QuantumToolbox
import LinearAlgebra: Diagonal
import StaticArraysCore: SVector
using CUDA
using CUDA.CUSPARSE
# CUDA.allowscalar(false) # This is already set in the extension script
Expand Down