From 0c5b9cb3ff72f424a82100817c495e24123b8f32 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Tue, 23 Apr 2024 19:01:07 +0800 Subject: [PATCH 01/35] element type conversion for `QuantumObject` --- src/quantum_object.jl | 18 ++++++++++++++---- test/quantum_objects.jl | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/quantum_object.jl b/src/quantum_object.jl index 3a37b4b9..8397b2be 100644 --- a/src/quantum_object.jl +++ b/src/quantum_object.jl @@ -196,10 +196,10 @@ function _check_QuantumObject(type::OperatorBraQuantumObject, prod_dims::Int, m: prod_dims != sqrt(n) ? throw(DimensionMismatch("The dims parameter does not fit the dimension of the Array.")) : nothing end -function QuantumObject(A::QuantumObject{<:AbstractArray}; type::ObjType=A.type, dims=A.dims) where - {ObjType<:QuantumObjectType} - - QuantumObject(A.data, type, dims) +function QuantumObject(A::QuantumObject{<:AbstractArray{T,N}}; type::ObjType=A.type, dims=A.dims) where {T,N,ObjType<:QuantumObjectType} + N == 1 ? Size = (length(A), 1) : Size = size(A) + _check_QuantumObject(type, prod(dims), Size[1], Size[2]) + return QuantumObject(copy(A.data), type, dims) end @doc raw""" @@ -668,3 +668,13 @@ function _spexp(A::SparseMatrixCSC{T,M}; threshold=1e-14, nonzero_tol=1e-20) whe end P end + +# data type conversions +Base.Vector(A::QuantumObject{<:AbstractVector}) = QuantumObject(Vector(A.data), A.type, A.dims) +Base.Vector{T}(A::QuantumObject{<:AbstractVector}) where {T<:Number} = QuantumObject(Vector{T}(A.data), A.type, A.dims) +Base.Matrix(A::QuantumObject{<:AbstractMatrix}) = QuantumObject(Matrix(A.data), A.type, A.dims) +Base.Matrix{T}(A::QuantumObject{<:AbstractMatrix}) where {T<:Number} = QuantumObject(Matrix{T}(A.data), A.type, A.dims) +SparseArrays.SparseVector(A::QuantumObject{<:AbstractVector}) = QuantumObject(SparseVector(A.data), A.type, A.dims) +SparseArrays.SparseVector{T}(A::QuantumObject{<:SparseVector}) where {T<:Number} = QuantumObject(SparseVector{T}(A.data), A.type, A.dims) +SparseArrays.SparseMatrixCSC(A::QuantumObject{<:AbstractMatrix}) = QuantumObject(SparseMatrixCSC(A.data), A.type, A.dims) +SparseArrays.SparseMatrixCSC{T}(A::QuantumObject{<:SparseMatrixCSC}) where {T<:Number} = QuantumObject(SparseMatrixCSC{T}(A.data), A.type, A.dims) \ No newline at end of file diff --git a/test/quantum_objects.jl b/test/quantum_objects.jl index e8073a1a..71fe05ac 100644 --- a/test/quantum_objects.jl +++ b/test/quantum_objects.jl @@ -238,4 +238,24 @@ ρ2 = dense_to_sparse(ρ1) @test tidyup(ρ2, 0.1) != ρ2 @test dense_to_sparse(tidyup(ρ1, 0.1)) == tidyup(ρ2, 0.1) + + # data element type conversion + vd = Qobj(Int64[0, 0]) + vs = Qobj(dense_to_sparse(vd)) + Md = Qobj(Int64[0 0; 0 0]) + Ms = Qobj(dense_to_sparse(Md)) + @test typeof(Vector(vd).data) == Vector{Int64} + @test typeof(Vector(vs).data) == Vector{Int64} + @test typeof(Vector{ComplexF64}(vd).data) == Vector{ComplexF64} + @test typeof(Vector{ComplexF64}(vs).data) == Vector{ComplexF64} + @test typeof(SparseVector(vd).data) == SparseVector{Int64, Int64} + @test typeof(SparseVector(vs).data) == SparseVector{Int64, Int64} + @test typeof(SparseVector{ComplexF64}(vs).data) == SparseVector{ComplexF64, Int64} + @test typeof(Matrix(Md).data) == Matrix{Int64} + @test typeof(Matrix(Ms).data) == Matrix{Int64} + @test typeof(Matrix{ComplexF64}(Ms).data) == Matrix{ComplexF64} + @test typeof(Matrix{ComplexF64}(Md).data) == Matrix{ComplexF64} + @test typeof(SparseMatrixCSC(Md).data) == SparseMatrixCSC{Int64, Int64} + @test typeof(SparseMatrixCSC(Ms).data) == SparseMatrixCSC{Int64, Int64} + @test typeof(SparseMatrixCSC{ComplexF64}(Ms).data) == SparseMatrixCSC{ComplexF64, Int64} end \ No newline at end of file From 19aad184a35be0623834732b8f29bd7b73551da4 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Mon, 29 Apr 2024 23:35:08 +0800 Subject: [PATCH 02/35] add `versioninfo()` and `about()` --- Project.toml | 2 +- docs/src/api.md | 6 ++++ src/QuantumToolbox.jl | 2 ++ src/versioninfo.jl | 76 +++++++++++++++++++++++++++++++++++++++++++ test/runtests.jl | 2 ++ 5 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/versioninfo.jl diff --git a/Project.toml b/Project.toml index d03f936a..20727bc5 100644 --- a/Project.toml +++ b/Project.toml @@ -13,6 +13,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" LinearMaps = "7a12625a-238d-50fd-b39a-03d52299707e" LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" @@ -37,7 +38,6 @@ Test = "<0.0.1, 1" julia = "1.7" [extras] -Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] diff --git a/docs/src/api.md b/docs/src/api.md index b46ce646..c548fb9c 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -135,3 +135,9 @@ _adjM_condition_ratio _pinv! dBdz! ``` + +## [Miscellaneous](@id API: Miscellaneous) +```@docs +QuantumToolbox.versioninfo +QuantumToolbox.about +``` \ No newline at end of file diff --git a/src/QuantumToolbox.jl b/src/QuantumToolbox.jl index ff23a836..9afa9fb6 100644 --- a/src/QuantumToolbox.jl +++ b/src/QuantumToolbox.jl @@ -1,5 +1,6 @@ module QuantumToolbox +using Pkg using Reexport using Distributed @reexport using LinearAlgebra @@ -20,6 +21,7 @@ using LinearAlgebra: BlasFloat, BlasComplex # to achieve better performances for more massive parallelizations BLAS.set_num_threads(1) +include("versioninfo.jl") include("quantum_object.jl") include("quantum_operators.jl") include("general_functions.jl") diff --git a/src/versioninfo.jl b/src/versioninfo.jl new file mode 100644 index 00000000..3df7e93c --- /dev/null +++ b/src/versioninfo.jl @@ -0,0 +1,76 @@ +""" + QuantumToolbox.versioninfo(io::IO=stdout) + +Command line output of information on QuantumToolbox, dependencies, and system information, same as [`QuantumToolbox.about`](@ref). +""" +function versioninfo(io::IO=stdout) + cpu = Sys.cpu_info() + BLAS_info = BLAS.get_config().loaded_libs[1] + Sys.iswindows() ? OS_name = "Windows" : Sys.isapple() ? OS_name = "macOS" : OS_name = Sys.KERNEL + + # print introduction + println(io, + "\n", + " QuantumToolbox.jl: Quantum Toolbox in Julia\n", + "≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡\n", + "Copyright © QuTiP team 2022 and later.\n", + "Current admin team: Alberto Mercurio, Yi-Te Huang\n", + ) + + # print package informations + println(io, + "Package information:\n", + "====================================\n", + "QuantumToolbox Ver. $(_get_pkg_version("QuantumToolbox"))\n", + "LinearSolve Ver. $(_get_pkg_version("LinearSolve"))\n", + "OrdinaryDiffEq Ver. $(_get_pkg_version("OrdinaryDiffEq"))\n" + ) + + # print System informations + println(io, + "System information:\n", + "====================================\n", + "Julia Version: $(VERSION)" + ) + println(io, + """OS : $(OS_name) ($(Sys.MACHINE))""" + ) + println(io, + """CPU : $(length(cpu)) × $(cpu[1].model)""" + ) + println(io, + """Memory : $(round(Sys.total_memory() / 2 ^ 30, digits=3)) GB""" + ) + println(io, + """WORD_SIZE: $(Sys.WORD_SIZE)""" + ) + println(io, + """LIBM : $(Base.libm_name)""" + ) + println(io, + """LLVM : libLLVM-$(Base.libllvm_version) ($(Sys.JIT), $(Sys.CPU_NAME))""" + ) + println(io, + """BLAS : $(basename(BLAS_info.libname)) ($(BLAS_info.interface))""" + ) + println(io, + """Threads : $(Threads.nthreads(:default)) default, $(Threads.nthreads(:interactive)) interactive, $(Threads.ngcthreads()) GC (on $(Sys.CPU_THREADS) virtual cores)""" + ) + print(io, "\n") +end + +""" + QuantumToolbox.about(io::IO=stdout) + +Command line output of information on QuantumToolbox, dependencies, and system information, same as [`QuantumToolbox.versioninfo`](@ref). +""" +about(io::IO=stdout) = versioninfo(io) + +function _get_pkg_version(pkg_name::String) + D = Pkg.dependencies() + for uuid in keys(D) + if D[uuid].name == pkg_name + return D[uuid].version + end + end +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index e8bc8a5c..1905743c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,6 +31,8 @@ if (GROUP == "All") || (GROUP == "Code-Quality") end if (GROUP == "All") || (GROUP == "Core") + QuantumToolbox.about() + for test in core_tests include(joinpath(testdir, test)) end From 7be0ebe3463be3d726eb8bb39c3b44fa82e91287 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Mon, 29 Apr 2024 23:42:14 +0800 Subject: [PATCH 03/35] fix typo in `Project.toml [targets]` --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 20727bc5..597bb168 100644 --- a/Project.toml +++ b/Project.toml @@ -41,4 +41,4 @@ julia = "1.7" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Pkg", "Test"] +test = ["Test"] From 4cc8963f9bcdec91db5bbd1aa58c59443f632a0b Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Mon, 29 Apr 2024 23:57:19 +0800 Subject: [PATCH 04/35] support for Julia v1.8 --- src/versioninfo.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/versioninfo.jl b/src/versioninfo.jl index 3df7e93c..6603beb1 100644 --- a/src/versioninfo.jl +++ b/src/versioninfo.jl @@ -54,7 +54,7 @@ function versioninfo(io::IO=stdout) """BLAS : $(basename(BLAS_info.libname)) ($(BLAS_info.interface))""" ) println(io, - """Threads : $(Threads.nthreads(:default)) default, $(Threads.nthreads(:interactive)) interactive, $(Threads.ngcthreads()) GC (on $(Sys.CPU_THREADS) virtual cores)""" + """Threads : $(Threads.nthreads()) on $(Sys.CPU_THREADS) virtual cores""" ) print(io, "\n") end From c29c97b7fcb8c1dda4e3175b93c80df207325d30 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Tue, 30 Apr 2024 02:04:06 +0800 Subject: [PATCH 05/35] minor change --- src/versioninfo.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/versioninfo.jl b/src/versioninfo.jl index 6603beb1..e93a972c 100644 --- a/src/versioninfo.jl +++ b/src/versioninfo.jl @@ -54,7 +54,7 @@ function versioninfo(io::IO=stdout) """BLAS : $(basename(BLAS_info.libname)) ($(BLAS_info.interface))""" ) println(io, - """Threads : $(Threads.nthreads()) on $(Sys.CPU_THREADS) virtual cores""" + """Threads : $(Threads.nthreads()) (on $(Sys.CPU_THREADS) virtual cores)""" ) print(io, "\n") end From fbb26cc41c1e8981178d4d91bd36cd808d42385c Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Wed, 1 May 2024 01:58:56 +0800 Subject: [PATCH 06/35] update admin team --- src/versioninfo.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/versioninfo.jl b/src/versioninfo.jl index e93a972c..abd20a4d 100644 --- a/src/versioninfo.jl +++ b/src/versioninfo.jl @@ -14,7 +14,8 @@ function versioninfo(io::IO=stdout) " QuantumToolbox.jl: Quantum Toolbox in Julia\n", "≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡\n", "Copyright © QuTiP team 2022 and later.\n", - "Current admin team: Alberto Mercurio, Yi-Te Huang\n", + "Current admin team:\n", + " Alberto Mercurio, Luca Gravina, Yi-Te Huang\n" ) # print package informations From d1b51e05bee9b92a3ad136691adf762c3099fd1e Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Wed, 1 May 2024 01:59:22 +0800 Subject: [PATCH 07/35] minor change --- src/QuantumToolbox.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QuantumToolbox.jl b/src/QuantumToolbox.jl index 9afa9fb6..de474c28 100644 --- a/src/QuantumToolbox.jl +++ b/src/QuantumToolbox.jl @@ -1,6 +1,6 @@ module QuantumToolbox -using Pkg +import Pkg using Reexport using Distributed @reexport using LinearAlgebra From 1759ffeb1a83476d89becf85073b1b2b47b1ce0e Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Wed, 1 May 2024 13:26:05 +0800 Subject: [PATCH 08/35] remove `mutable` structure --- src/quantum_object.jl | 4 ++-- src/spin_lattice.jl | 6 ++---- src/time_evolution/time_evolution.jl | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/quantum_object.jl b/src/quantum_object.jl index 8397b2be..0b5687e1 100644 --- a/src/quantum_object.jl +++ b/src/quantum_object.jl @@ -96,7 +96,7 @@ A constant representing the type of [`OperatorKetQuantumObject`](@ref) const OperatorKet = OperatorKetQuantumObject() @doc raw""" - mutable struct QuantumObject{MT<:AbstractArray,ObjType<:QuantumObjectType} + struct QuantumObject{MT<:AbstractArray,ObjType<:QuantumObjectType} data::MT type::ObjType dims::Vector{Int} @@ -120,7 +120,7 @@ julia> a isa QuantumObject true ``` """ -mutable struct QuantumObject{MT<:AbstractArray,ObjType<:QuantumObjectType} <: AbstractQuantumObject +struct QuantumObject{MT<:AbstractArray,ObjType<:QuantumObjectType} <: AbstractQuantumObject data::MT type::ObjType dims::Vector{Int} diff --git a/src/spin_lattice.jl b/src/spin_lattice.jl index c3c54a9f..6a5f9f9d 100644 --- a/src/spin_lattice.jl +++ b/src/spin_lattice.jl @@ -7,7 +7,7 @@ sm = (sx - 1im*sy)/2 sp = (sx + 1im*sy)/2 #Lattice structure -Base.@kwdef mutable struct Lattice{TN<:Integer, TLI<:LinearIndices, TCI<:CartesianIndices} +Base.@kwdef struct Lattice{TN<:Integer, TLI<:LinearIndices, TCI<:CartesianIndices} Nx::TN Ny::TN N::TN = Nx*Ny @@ -18,9 +18,7 @@ end #Definition of many-body operators function mb(s::QuantumObject{<:AbstractArray{T1},OperatorQuantumObject}, i::Integer, N::Integer) where {T1} T = s.dims[1] - op = kron(kron(eye(T^(i-1)), s), eye(T^(N-i))) - op.dims=ones(Int,N)*2 - op + QuantumObject(kron(eye(T^(i-1)), s, eye(T^(N-i))); dims=fill(2, N)) end mb(s::QuantumObject{<:AbstractArray{T1},OperatorQuantumObject}, i::Integer, latt::Lattice) where {T1} = mb(s, i, latt.N) mb(s::QuantumObject{<:AbstractArray{T1},OperatorQuantumObject}, row::Integer, col::Integer, latt::Lattice) where {T1} = mb(s, latt.idx[row,col], latt.N) diff --git a/src/time_evolution/time_evolution.jl b/src/time_evolution/time_evolution.jl index e2fbb5be..7af67651 100644 --- a/src/time_evolution/time_evolution.jl +++ b/src/time_evolution/time_evolution.jl @@ -39,7 +39,7 @@ ContinuousLindbladJumpCallback(;interp_points::Int=10) = ContinuousLindbladJumpC ## Sum of operators -mutable struct OperatorSum{CT<:Vector{<:Number},OT<:Vector{<:QuantumObject}} <: AbstractQuantumObject +struct OperatorSum{CT<:Vector{<:Number},OT<:Vector{<:QuantumObject}} <: AbstractQuantumObject coefficients::CT operators::OT function OperatorSum(coefficients::CT, operators::OT) where {CT<:Vector{<:Number},OT<:Vector{<:QuantumObject}} @@ -76,7 +76,7 @@ end y end -mutable struct TimeDependentOperatorSum{CFT,OST<:OperatorSum} +struct TimeDependentOperatorSum{CFT,OST<:OperatorSum} coefficient_functions::CFT operator_sum::OST end From b38f2682420d9bc2f6e0a9dcff2389dd2665edb5 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Wed, 1 May 2024 13:39:16 +0800 Subject: [PATCH 09/35] update runtests CI --- .github/workflows/CI.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 147ef774..6e444fbf 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -28,10 +28,9 @@ jobs: strategy: fail-fast: false matrix: - # for core tests + # for core tests (latest and oldest supported versions) version: - - '1.8' - - '1.9' + - '1.7' - '1.10' os: - ubuntu-latest @@ -42,8 +41,18 @@ jobs: group: - Core - # for code quality tests include: + # for core tests (intermediate versions) + - version: '1.8' + os: 'ubuntu-latest' + arch: 'x64' + group: 'Core' + - version: '1.9' + os: 'ubuntu-latest' + arch: 'x64' + group: 'Core' + + # for code quality tests - version: '1' os: 'ubuntu-latest' arch: 'x64' From 5f946d4183e420aa6a90aec693ea2893933498a3 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Wed, 1 May 2024 08:31:02 +0200 Subject: [PATCH 10/35] Set version to v0.8.0 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 597bb168..7501448b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "QuantumToolbox" uuid = "6c2fb7c5-b903-41d2-bc5e-5a7c320b9fab" authors = ["Alberto Mercurio"] -version = "0.7.2" +version = "0.8.0" [deps] DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def" From 2dd23a343c8d6701e0b94a012111d460191d2543 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang <44385685+ytdHuang@users.noreply.github.com> Date: Wed, 1 May 2024 17:38:26 +0800 Subject: [PATCH 11/35] Fix local `JET` runtest --- test/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 1905743c..400e9df9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -24,7 +24,7 @@ core_tests = [ "wigner.jl", ] -if (GROUP == "All") || (GROUP == "Code-Quality") +if ((GROUP == "All") || (GROUP == "Code-Quality")) && (VERSION >= v"1.9") Pkg.add(["Aqua", "JET"]) include(joinpath(testdir, "aqua.jl")) include(joinpath(testdir, "jet.jl")) @@ -36,4 +36,4 @@ if (GROUP == "All") || (GROUP == "Core") for test in core_tests include(joinpath(testdir, test)) end -end \ No newline at end of file +end From d2b7b305f9722146a7e6283de460c82d72d82ce8 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Wed, 1 May 2024 17:45:33 +0800 Subject: [PATCH 12/35] gather keywords `import` and `using` to the main file --- src/QuantumToolbox.jl | 37 +++++++++++++++++++++++++------------ src/eigsolve.jl | 13 ------------- src/quantum_object.jl | 4 ---- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/QuantumToolbox.jl b/src/QuantumToolbox.jl index de474c28..6eab5400 100644 --- a/src/QuantumToolbox.jl +++ b/src/QuantumToolbox.jl @@ -1,21 +1,34 @@ module QuantumToolbox -import Pkg -using Reexport -using Distributed +# Re-export: +# 1. basic functions in LinearAlgebra and SparseArrays +# 2. the solvers in ODE and LinearSolve +import Reexport: @reexport @reexport using LinearAlgebra @reexport using SparseArrays @reexport using OrdinaryDiffEq -@reexport using DiffEqCallbacks -using Random -using Graphs -using FFTW -using SpecialFunctions -using LinearSolve -using LinearMaps: LinearMap -using IncompleteLU +@reexport using LinearSolve + +# other functions in LinearAlgebra +import LinearAlgebra: BlasReal, BlasInt, BlasFloat, BlasComplex, checksquare +import LinearAlgebra.BLAS: @blasfunc +if VERSION < v"1.10" + import LinearAlgebra: chkstride1 + import LinearAlgebra.BLAS: libblastrampoline + import LinearAlgebra.LAPACK: chklapackerror + import Base: require_one_based_indexing +else + import LinearAlgebra.LAPACK: hseqr! +end -using LinearAlgebra: BlasFloat, BlasComplex +# other dependencies (in alphabetical order) +import DiffEqCallbacks: DiscreteCallback, PeriodicCallback, PresetTimeCallback +import FFTW: fft, fftshift +import Graphs: connected_components, DiGraph +import IncompleteLU: ilu +import LinearMaps: LinearMap +import Pkg +import SpecialFunctions: loggamma # Setting the number of threads to 1 allows # to achieve better performances for more massive parallelizations diff --git a/src/eigsolve.jl b/src/eigsolve.jl index 3c9470e3..97a602d6 100644 --- a/src/eigsolve.jl +++ b/src/eigsolve.jl @@ -1,16 +1,3 @@ -using LinearAlgebra.BLAS: @blasfunc, BlasReal, BlasInt, BlasFloat, BlasComplex -using LinearAlgebra: checksquare - -if VERSION < v"1.10" - using LinearAlgebra.BLAS: libblastrampoline - using LinearAlgebra: chkstride1 - using LinearAlgebra.LAPACK: chklapackerror - using Base: require_one_based_indexing -else - using LinearAlgebra.LAPACK: hseqr! -end - - @doc raw""" struct EigsolveResult{T1<:Vector{<:Number}, T2<:AbstractMatrix{<:Number}, ObjType<:Union{Nothing,OperatorQuantumObject,SuperOperatorQuantumObject}} values::T1 diff --git a/src/quantum_object.jl b/src/quantum_object.jl index 0b5687e1..fed97738 100644 --- a/src/quantum_object.jl +++ b/src/quantum_object.jl @@ -1,7 +1,3 @@ -using LinearAlgebra -using LinearAlgebra: checksquare, BlasFloat, BlasComplex, BlasReal, BlasInt -import LinearAlgebra - abstract type AbstractQuantumObject end abstract type QuantumObjectType end From 07ff8fac8750341c4fd34b8d505b5e959814541f Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Wed, 1 May 2024 17:46:57 +0800 Subject: [PATCH 13/35] Remove `Random` and `Distributed` from `[deps]` --- Project.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Project.toml b/Project.toml index 7501448b..84a362a8 100644 --- a/Project.toml +++ b/Project.toml @@ -5,7 +5,6 @@ version = "0.8.0" [deps] DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def" -Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" IncompleteLU = "40713840-3770-5561-ab4c-a76e7d0d7895" @@ -14,14 +13,12 @@ LinearMaps = "7a12625a-238d-50fd-b39a-03d52299707e" LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" [compat] DiffEqCallbacks = "2, 3" -Distributed = "<0.0.1, 1" FFTW = "1.5" Graphs = "1.7" IncompleteLU = "0.2" @@ -30,7 +27,6 @@ LinearMaps = "3" LinearSolve = "2" OrdinaryDiffEq = "6" Pkg = "<0.0.1, 1" -Random = "<0.0.1, 1" Reexport = "1" SparseArrays = "<0.0.1, 1" SpecialFunctions = "2" From 8100b92e8ccfc35b2fb59b5b1912b72373e409b5 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Wed, 1 May 2024 18:34:01 +0800 Subject: [PATCH 14/35] change abstract type `SteadyStateDirectSolver` empty struct --- src/time_evolution/time_evolution.jl | 35 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/time_evolution/time_evolution.jl b/src/time_evolution/time_evolution.jl index 7af67651..b76c7804 100644 --- a/src/time_evolution/time_evolution.jl +++ b/src/time_evolution/time_evolution.jl @@ -1,12 +1,14 @@ export OperatorSum, TimeDependentOperatorSum abstract type LiouvillianSolver end + struct LiouvillianDirectSolver{T<:Real} <: LiouvillianSolver tol::T end abstract type SteadyStateSolver end -abstract type SteadyStateDirectSolver <: SteadyStateSolver end + +struct SteadyStateDirectSolver <: SteadyStateSolver end struct TimeEvolutionSol{TT<:Vector{<:Real}, TS<:AbstractVector, TE<:Matrix{ComplexF64}} times::TT @@ -139,7 +141,7 @@ liouvillian(H::QuantumObject{MT1,SuperOperatorQuantumObject}, Id_cache::Diagonal function liouvillian_floquet(L₀::QuantumObject{<:AbstractArray{T1},SuperOperatorQuantumObject}, Lₚ::QuantumObject{<:AbstractArray{T2},SuperOperatorQuantumObject}, Lₘ::QuantumObject{<:AbstractArray{T3},SuperOperatorQuantumObject}, - ω::Real; n_max::Int=4, solver::LSolver=LiouvillianDirectSolver()) where {T1,T2,T3,LSolver<:LiouvillianSolver} + ω::Real; n_max::Int=4, solver::LiouvillianSolver=LiouvillianDirectSolver()) where {T1,T2,T3} ((L₀.dims == Lₚ.dims) && (L₀.dims == Lₘ.dims)) || throw(ErrorException("The operators are not of the same Hilbert dimension.")) @@ -150,11 +152,10 @@ function liouvillian_floquet(H::QuantumObject{<:AbstractArray{T1},OpType1}, c_ops::AbstractVector, Hₚ::QuantumObject{<:AbstractArray{T2},OpType2}, Hₘ::QuantumObject{<:AbstractArray{T3},OpType3}, - ω::Real; n_max::Int=4, solver::LSolver=LiouvillianDirectSolver()) where {T1,T2,T3, + ω::Real; n_max::Int=4, solver::LiouvillianSolver=LiouvillianDirectSolver()) where {T1,T2,T3, OpType1<:Union{OperatorQuantumObject, SuperOperatorQuantumObject}, OpType2<:Union{OperatorQuantumObject, SuperOperatorQuantumObject}, - OpType3<:Union{OperatorQuantumObject, SuperOperatorQuantumObject}, - LSolver<:LiouvillianSolver} + OpType3<:Union{OperatorQuantumObject, SuperOperatorQuantumObject}} liouvillian_floquet(liouvillian(H, c_ops), liouvillian(Hₚ), liouvillian(Hₘ), ω, solver=solver, n_max=n_max) end @@ -244,20 +245,20 @@ function _liouvillian_floquet(L₀::QuantumObject{<:AbstractArray{T1},SuperOpera end function steadystate(L::QuantumObject{<:AbstractArray{T},SuperOperatorQuantumObject}; - solver::Type{SSSolver}=SteadyStateDirectSolver) where {T,SSSolver<:SteadyStateSolver} + solver::SteadyStateSolver=SteadyStateDirectSolver()) where {T} _steadystate(L, solver) end function steadystate(H::QuantumObject{<:AbstractArray{T},OpType}, c_ops::Vector, - solver::Type{SSSolver}=SteadyStateDirectSolver) where {T,OpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},SSSolver<:SteadyStateSolver} + solver::SteadyStateSolver=SteadyStateDirectSolver()) where {T,OpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}} L = liouvillian(H, c_ops) steadystate(L, solver=solver) end function _steadystate(L::QuantumObject{<:AbstractArray{T},SuperOperatorQuantumObject}, - solver::Type{SteadyStateDirectSolver}) where {T} + solver::SteadyStateSolver) where {T} L_tmp = copy(L.data) N = prod(L.dims) @@ -277,8 +278,8 @@ end steadystate_floquet(H_0::QuantumObject, c_ops::Vector, H_p::QuantumObject, H_m::QuantumObject, - ω::Real; n_max::Int=4, lf_solver::LSolver=LiouvillianDirectSolver(), - ss_solver::Type{SSSolver}=SteadyStateDirectSolver) + ω::Real; n_max::Int=4, lf_solver::LiouvillianSolver=LiouvillianDirectSolver(), + ss_solver::SteadyStateSolver=SteadyStateDirectSolver()) Calculates the steady state of a periodically driven system. Here `H_0` is the Hamiltonian or the Liouvillian of the undriven system. @@ -292,11 +293,10 @@ and `ss_solver` is the solver used to solve the steady state. function steadystate_floquet(H_0::QuantumObject{<:AbstractArray{T1},OpType1}, c_ops::AbstractVector, H_p::QuantumObject{<:AbstractArray{T2},OpType2}, H_m::QuantumObject{<:AbstractArray{T3},OpType3}, - ω::Real; n_max::Int=4, lf_solver::LSolver=LiouvillianDirectSolver(), - ss_solver::Type{SSSolver}=SteadyStateDirectSolver) where {T1,T2,T3,OpType1<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}, + ω::Real; n_max::Int=4, lf_solver::LiouvillianSolver=LiouvillianDirectSolver(), + ss_solver::SteadyStateSolver=SteadyStateDirectSolver()) where {T1,T2,T3,OpType1<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}, OpType2<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}, - OpType3<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}, - LSolver<:LiouvillianSolver,SSSolver<:SteadyStateSolver} + OpType3<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}} L_0 = liouvillian(H_0, c_ops) L_p = liouvillian(H_p) @@ -308,11 +308,10 @@ end function steadystate_floquet(H_0::QuantumObject{<:AbstractArray{T1},OpType1}, H_p::QuantumObject{<:AbstractArray{T2},OpType2}, H_m::QuantumObject{<:AbstractArray{T3},OpType3}, - ω::Real; n_max::Int=4, lf_solver::LSolver=LiouvillianDirectSolver(), - ss_solver::Type{SSSolver}=SteadyStateDirectSolver) where {T1,T2,T3,OpType1<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}, + ω::Real; n_max::Int=4, lf_solver::LiouvillianSolver=LiouvillianDirectSolver(), + ss_solver::SteadyStateSolver=SteadyStateDirectSolver()) where {T1,T2,T3,OpType1<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}, OpType2<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}, - OpType3<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}, - LSolver<:LiouvillianSolver,SSSolver<:SteadyStateSolver} + OpType3<:Union{OperatorQuantumObject,SuperOperatorQuantumObject}} L_0 = liouvillian(H_0) L_p = liouvillian(H_p) From b84396d582abaa91d8b6722526afaae014c3de72 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Wed, 1 May 2024 18:35:48 +0800 Subject: [PATCH 15/35] separate all `export` keyword to individual files --- src/QuantumToolbox.jl | 24 ------------------- src/correlations.jl | 5 ++++ src/eigsolve.jl | 3 +++ src/general_functions.jl | 7 ++++++ src/negativity.jl | 2 ++ src/permutation.jl | 2 ++ src/quantum_object.jl | 7 ++++++ src/quantum_operators.jl | 6 +++++ src/time_evolution/mcsolve.jl | 3 ++- src/time_evolution/time_evolution.jl | 7 ++++++ .../time_evolution_dynamical.jl | 2 ++ src/wigner.jl | 4 ++++ 12 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/QuantumToolbox.jl b/src/QuantumToolbox.jl index 6eab5400..498a7694 100644 --- a/src/QuantumToolbox.jl +++ b/src/QuantumToolbox.jl @@ -52,28 +52,4 @@ include("arnoldi.jl") include("eigsolve.jl") include("negativity.jl") include("progress_bar.jl") - -export QuantumObject, Qobj, BraQuantumObject, KetQuantumObject, OperatorQuantumObject, OperatorBraQuantumObject, OperatorKetQuantumObject, SuperOperatorQuantumObject, TimeEvolutionSol -export Bra, Ket, Operator, OperatorBra, OperatorKet, SuperOperator -export isket, isbra, isoper, isoperbra, isoperket, issuper, ket2dm -export spre, spost, sprepost, lindblad_dissipator -export fock, basis, coherent -export sigmam, sigmap, sigmax, sigmay, sigmaz -export destroy, create, eye, qeye, projection, rand_dm -export tensor, ⊗ -export sinm, cosm -export expect -export WignerClenshaw, WignerLaguerre, wigner -export row_major_reshape, tidyup, tidyup!, gaussian, meshgrid, sparse_to_dense, dense_to_sparse -export get_data, mat2vec, vec2mat -export ptrace, entropy_vn, entanglement -export negativity, partial_transpose -export get_coherence, n_th -export dfd_mesolve, dsf_mesolve, dsf_mcsolve -export liouvillian, liouvillian_floquet, liouvillian_generalized, steadystate, steadystate_floquet -export LiouvillianDirectSolver, SteadyStateDirectSolver -export bdf, get_bdf_blocks -export FFTCorrelation, ExponentialSeries -export correlation_3op_2t, correlation_2op_2t, correlation_2op_1t, spectrum -export EigsolveResult, eigenenergies, eigenstates, eigsolve, eigsolve_al end diff --git a/src/correlations.jl b/src/correlations.jl index 2b645991..d518fb68 100644 --- a/src/correlations.jl +++ b/src/correlations.jl @@ -1,5 +1,10 @@ +export SpectrumSolver, FFTCorrelation, ExponentialSeries +export correlation_3op_2t, correlation_2op_2t, correlation_2op_1t, spectrum + abstract type SpectrumSolver end + struct FFTCorrelation <: SpectrumSolver end + struct ExponentialSeries <: SpectrumSolver tol::Real calc_steadystate::Bool diff --git a/src/eigsolve.jl b/src/eigsolve.jl index 97a602d6..56d81747 100644 --- a/src/eigsolve.jl +++ b/src/eigsolve.jl @@ -1,3 +1,6 @@ +export EigsolveResult +export eigenenergies, eigenstates, eigsolve, eigsolve_al + @doc raw""" struct EigsolveResult{T1<:Vector{<:Number}, T2<:AbstractMatrix{<:Number}, ObjType<:Union{Nothing,OperatorQuantumObject,SuperOperatorQuantumObject}} values::T1 diff --git a/src/general_functions.jl b/src/general_functions.jl index d2bc93cd..b063fe90 100644 --- a/src/general_functions.jl +++ b/src/general_functions.jl @@ -1,3 +1,10 @@ +export get_data, get_coherence, expect, ptrace +export mat2vec, vec2mat +export entropy_vn, entanglement +export gaussian, n_th + +export row_major_reshape, tidyup, tidyup!, meshgrid, sparse_to_dense, dense_to_sparse + """ row_major_reshape(Q::AbstractArray, shapes...) diff --git a/src/negativity.jl b/src/negativity.jl index 3651d515..7e003d56 100644 --- a/src/negativity.jl +++ b/src/negativity.jl @@ -1,3 +1,5 @@ +export negativity, partial_transpose + @doc raw""" negativity(ρ::QuantumObject, subsys::Int; logarithmic::Bool=false) diff --git a/src/permutation.jl b/src/permutation.jl index 4f8b328f..2cf88ffb 100644 --- a/src/permutation.jl +++ b/src/permutation.jl @@ -1,3 +1,5 @@ +export bdf, get_bdf_blocks + function bdf(A::SparseMatrixCSC{T,M}) where {T,M} n = LinearAlgebra.checksquare(A) diff --git a/src/quantum_object.jl b/src/quantum_object.jl index fed97738..cc258224 100644 --- a/src/quantum_object.jl +++ b/src/quantum_object.jl @@ -1,3 +1,10 @@ +export AbstractQuantumObject, QuantumObject, Qobj +export QuantumObjectType, BraQuantumObject, KetQuantumObject, OperatorQuantumObject, OperatorBraQuantumObject, OperatorKetQuantumObject, SuperOperatorQuantumObject +export Bra, Ket, Operator, OperatorBra, OperatorKet, SuperOperator + +export isket, isbra, isoper, isoperbra, isoperket, issuper, ket2dm +export tensor, ⊗ + abstract type AbstractQuantumObject end abstract type QuantumObjectType end diff --git a/src/quantum_operators.jl b/src/quantum_operators.jl index ea525366..b0649e7e 100644 --- a/src/quantum_operators.jl +++ b/src/quantum_operators.jl @@ -1,3 +1,9 @@ +export spre, spost, sprepost, lindblad_dissipator +export fock, basis, coherent +export sigmam, sigmap, sigmax, sigmay, sigmaz +export destroy, create, eye, qeye, projection, rand_dm +export sinm, cosm + @doc raw""" spre(O::QuantumObject, Id_cache=I(size(O,1))) diff --git a/src/time_evolution/mcsolve.jl b/src/time_evolution/mcsolve.jl index 6cf916e1..901286b6 100644 --- a/src/time_evolution/mcsolve.jl +++ b/src/time_evolution/mcsolve.jl @@ -1,4 +1,5 @@ -export mcsolveProblem, mcsolveEnsembleProblem, mcsolve, ContinuousLindbladJumpCallback, DiscreteLindbladJumpCallback +export mcsolveProblem, mcsolveEnsembleProblem, mcsolve +export ContinuousLindbladJumpCallback, DiscreteLindbladJumpCallback function _save_func_mcsolve(integrator) internal_params = integrator.p diff --git a/src/time_evolution/time_evolution.jl b/src/time_evolution/time_evolution.jl index b76c7804..d1313fe7 100644 --- a/src/time_evolution/time_evolution.jl +++ b/src/time_evolution/time_evolution.jl @@ -1,4 +1,11 @@ export OperatorSum, TimeDependentOperatorSum +export TimeEvolutionSol, TimeEvolutionMCSol + +export liouvillian, liouvillian_floquet, liouvillian_generalized +export LiouvillianSolver, LiouvillianDirectSolver + +export steadystate, steadystate_floquet +export SteadyStateSolver, SteadyStateDirectSolver abstract type LiouvillianSolver end diff --git a/src/time_evolution/time_evolution_dynamical.jl b/src/time_evolution/time_evolution_dynamical.jl index d4093d67..96bbdc01 100644 --- a/src/time_evolution/time_evolution_dynamical.jl +++ b/src/time_evolution/time_evolution_dynamical.jl @@ -1,3 +1,5 @@ +export dfd_mesolve, dsf_mesolve, dsf_mcsolve + ### DYNAMICAL FOCK DIMENSION ### function _reduce_dims(QO::AbstractArray{T}, dims::Vector{<:Integer}, sel::AbstractVector, reduce::AbstractVector) where {T} diff --git a/src/wigner.jl b/src/wigner.jl index 06d35553..5754f372 100644 --- a/src/wigner.jl +++ b/src/wigner.jl @@ -1,5 +1,9 @@ +export WignerSolver, WignerClenshaw, WignerLaguerre, wigner + abstract type WignerSolver end + struct WignerClenshaw <: WignerSolver end + struct WignerLaguerre <: WignerSolver parallel::Bool tol::Float64 From 6991167d9871ef57371217860148096fbd34aa96 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Wed, 1 May 2024 19:11:01 +0800 Subject: [PATCH 16/35] Re-add `Random` to `[deps]` --- Project.toml | 2 ++ src/QuantumToolbox.jl | 1 + 2 files changed, 3 insertions(+) diff --git a/Project.toml b/Project.toml index 84a362a8..6f251c57 100644 --- a/Project.toml +++ b/Project.toml @@ -13,6 +13,7 @@ LinearMaps = "7a12625a-238d-50fd-b39a-03d52299707e" LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" @@ -27,6 +28,7 @@ LinearMaps = "3" LinearSolve = "2" OrdinaryDiffEq = "6" Pkg = "<0.0.1, 1" +Random = "<0.0.1, 1" Reexport = "1" SparseArrays = "<0.0.1, 1" SpecialFunctions = "2" diff --git a/src/QuantumToolbox.jl b/src/QuantumToolbox.jl index 498a7694..d8564aac 100644 --- a/src/QuantumToolbox.jl +++ b/src/QuantumToolbox.jl @@ -28,6 +28,7 @@ import Graphs: connected_components, DiGraph import IncompleteLU: ilu import LinearMaps: LinearMap import Pkg +import Random import SpecialFunctions: loggamma # Setting the number of threads to 1 allows From 8867987f37372e36dea962719b1e6b51156c7d17 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sat, 4 May 2024 16:58:39 +0200 Subject: [PATCH 17/35] Add benchmark tracking --- .github/workflows/Benchmarks.yml | 60 ++++++++++++++++++++++++++++++++ benchmarks/.gitignore | 1 + benchmarks/Project.toml | 2 ++ benchmarks/runbenchmarks.jl | 29 +++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 .github/workflows/Benchmarks.yml create mode 100644 benchmarks/.gitignore create mode 100644 benchmarks/Project.toml create mode 100644 benchmarks/runbenchmarks.jl diff --git a/.github/workflows/Benchmarks.yml b/.github/workflows/Benchmarks.yml new file mode 100644 index 00000000..53a6c990 --- /dev/null +++ b/.github/workflows/Benchmarks.yml @@ -0,0 +1,60 @@ +name: Benchmark Tracking +on: + push: + branches: + - main + pull_request: + branches: + - main + +permissions: + contents: write + deployments: write + +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} + +jobs: + benchmark: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: '1' + arch: x64 + - uses: actions/cache@v4 + env: + cache-name: cache-artifacts + with: + path: ~/.julia/artifacts + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + restore-keys: | + ${{ runner.os }}-test-${{ env.cache-name }}- + ${{ runner.os }}-test- + ${{ runner.os }}- + - name: Run benchmark + run: | + cd benchmarks + julia --project --threads=2 --color=yes -e ' + using Pkg; + Pkg.develop(PackageSpec(path=joinpath(pwd(), ".."))); + Pkg.instantiate(); + include("runbenchmarks.jl")' + + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 + with: + name: Julia benchmark result + tool: "julia" + output-file-path: benchmarks/benchmarks_output.json + github-token: ${{ secrets.GITHUB_TOKEN }} + auto-push: ${{ github.event_name != 'pull_request' }} + # Show alert with commit comment on detecting possible performance regression + alert-threshold: "200%" + comment-on-alert: true + fail-on-alert: true + alert-comment-cc-users: "@ktrz,@findmyway" diff --git a/benchmarks/.gitignore b/benchmarks/.gitignore new file mode 100644 index 00000000..866cecaf --- /dev/null +++ b/benchmarks/.gitignore @@ -0,0 +1 @@ +/benchmarks_output.json \ No newline at end of file diff --git a/benchmarks/Project.toml b/benchmarks/Project.toml new file mode 100644 index 00000000..05a4894b --- /dev/null +++ b/benchmarks/Project.toml @@ -0,0 +1,2 @@ +[deps] +BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" diff --git a/benchmarks/runbenchmarks.jl b/benchmarks/runbenchmarks.jl new file mode 100644 index 00000000..1b461ca6 --- /dev/null +++ b/benchmarks/runbenchmarks.jl @@ -0,0 +1,29 @@ +using BenchmarkTools +using QuantumToolbox + +fib(n) = n <= 1 ? 1 : fib(n - 2) + fib(n - 1) + +suite = BenchmarkGroup() + +suite["steadystate"] = BenchmarkGroup(["steadystate"]) + + +## steadystate ## + +N = 50 +Δ = 0.1 +F = 2 +γ = 1 +a = destroy(N) +H = Δ * a' * a + F * (a + a') +c_ops = [sqrt(γ) * a] + +suite["steadystate"]["driven-dissipative harmonic oscillator"] = @benchmarkable steadystate($H, $c_ops) + +## end ## + + +tune!(suite) +results = run(suite, verbose = true) + +BenchmarkTools.save("benchmarks_output.json", mean(results)) \ No newline at end of file From 612a43591a3e67e13299c81fa6488d0731b6ad87 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sat, 4 May 2024 17:29:44 +0200 Subject: [PATCH 18/35] Fix error and minor changes --- .github/workflows/Benchmarks.yml | 12 ++++++------ benchmarks/Project.toml | 1 + benchmarks/runbenchmarks.jl | 5 +++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/Benchmarks.yml b/.github/workflows/Benchmarks.yml index 53a6c990..54041006 100644 --- a/.github/workflows/Benchmarks.yml +++ b/.github/workflows/Benchmarks.yml @@ -45,16 +45,16 @@ jobs: Pkg.instantiate(); include("runbenchmarks.jl")' - - name: Store benchmark result + - name: Parse & Upload Benchmark Results uses: benchmark-action/github-action-benchmark@v1 with: - name: Julia benchmark result + name: Benchmark results tool: "julia" output-file-path: benchmarks/benchmarks_output.json + summary-always: true github-token: ${{ secrets.GITHUB_TOKEN }} - auto-push: ${{ github.event_name != 'pull_request' }} - # Show alert with commit comment on detecting possible performance regression + comment-always: true alert-threshold: "200%" - comment-on-alert: true fail-on-alert: true - alert-comment-cc-users: "@ktrz,@findmyway" + benchmark-data-dir-path: benchmarks + auto-push: ${{ github.event_name != 'pull_request' }} diff --git a/benchmarks/Project.toml b/benchmarks/Project.toml index 05a4894b..32e8b0b0 100644 --- a/benchmarks/Project.toml +++ b/benchmarks/Project.toml @@ -1,2 +1,3 @@ [deps] BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +QuantumToolbox = "6c2fb7c5-b903-41d2-bc5e-5a7c320b9fab" diff --git a/benchmarks/runbenchmarks.jl b/benchmarks/runbenchmarks.jl index 1b461ca6..4a568dac 100644 --- a/benchmarks/runbenchmarks.jl +++ b/benchmarks/runbenchmarks.jl @@ -23,7 +23,8 @@ suite["steadystate"]["driven-dissipative harmonic oscillator"] = @benchmarkable ## end ## -tune!(suite) +BenchmarkTools.tune!(suite) results = run(suite, verbose = true) +display(median(results)) -BenchmarkTools.save("benchmarks_output.json", mean(results)) \ No newline at end of file +BenchmarkTools.save(joinpath(@__DIR__, "benchmarks_output.json"), median(results)) \ No newline at end of file From 67a333fc7a7ce87f3bb9d9a09e0d022c1ae40e57 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sat, 4 May 2024 19:29:07 +0200 Subject: [PATCH 19/35] Remove Fibonacci function --- benchmarks/runbenchmarks.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/benchmarks/runbenchmarks.jl b/benchmarks/runbenchmarks.jl index 4a568dac..dea58b58 100644 --- a/benchmarks/runbenchmarks.jl +++ b/benchmarks/runbenchmarks.jl @@ -1,8 +1,6 @@ using BenchmarkTools using QuantumToolbox -fib(n) = n <= 1 ? 1 : fib(n - 2) + fib(n - 1) - suite = BenchmarkGroup() suite["steadystate"] = BenchmarkGroup(["steadystate"]) From 12786face0cee88bf4a6c6214462f5d1ddd022ba Mon Sep 17 00:00:00 2001 From: Yi-Te Huang <44385685+ytdHuang@users.noreply.github.com> Date: Sun, 5 May 2024 15:39:24 +0800 Subject: [PATCH 20/35] Modify Benchmarks.yml --- .github/workflows/Benchmarks.yml | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/Benchmarks.yml b/.github/workflows/Benchmarks.yml index 54041006..43d3f565 100644 --- a/.github/workflows/Benchmarks.yml +++ b/.github/workflows/Benchmarks.yml @@ -2,12 +2,22 @@ name: Benchmark Tracking on: push: branches: - - main + - 'main' + paths-ignore: + - 'docs/**' pull_request: branches: - - main + - 'main' + paths-ignore: + - 'docs/**' + types: + - opened + - reopened + - synchronize + - ready_for_review permissions: + actions: write contents: write deployments: write @@ -20,22 +30,14 @@ concurrency: jobs: benchmark: runs-on: ubuntu-latest + if: ${{ !github.event.pull_request.draft }} steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 with: version: '1' arch: x64 - - uses: actions/cache@v4 - env: - cache-name: cache-artifacts - with: - path: ~/.julia/artifacts - key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} - restore-keys: | - ${{ runner.os }}-test-${{ env.cache-name }}- - ${{ runner.os }}-test- - ${{ runner.os }}- + - uses: julia-actions/cache@v1 - name: Run benchmark run: | cd benchmarks From d61667db1e643eef221db9a91dcbcaafdca8c9f1 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Sun, 5 May 2024 17:49:05 +0800 Subject: [PATCH 21/35] modify `.gitignore` --- .gitignore | 5 ++++- benchmarks/.gitignore | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) delete mode 100644 benchmarks/.gitignore diff --git a/.gitignore b/.gitignore index 31d66670..483c0b92 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ .DS_Store + *.jl.*.cov *.jl.cov *.jl.mem Manifest.toml docs/build/ -.vscode \ No newline at end of file + +.vscode +*.json \ No newline at end of file diff --git a/benchmarks/.gitignore b/benchmarks/.gitignore deleted file mode 100644 index 866cecaf..00000000 --- a/benchmarks/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/benchmarks_output.json \ No newline at end of file From 348dd7f23d0dfa5e609d1f7e798189d45b4c8ce4 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sun, 5 May 2024 12:24:43 +0200 Subject: [PATCH 22/35] Change README Zenodo Badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f1ec5f0f..c29b4e17 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Build Status](https://github.com/albertomercurio/QuantumToolbox.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/albertomercurio/QuantumToolbox.jl/actions/workflows/CI.yml?query=branch%3Amain) [![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) [![Coverage](https://codecov.io/gh/albertomercurio/QuantumToolbox.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/albertomercurio/QuantumToolbox.jl) -[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10822817.svg)](https://doi.org/10.5281/zenodo.10822817) +[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.11096277.svg)](https://doi.org/10.5281/zenodo.11096277) ## Introduction [QuantumToolbox.jl](https://github.com/albertomercurio/QuantumToolbox.jl) is a cutting-edge Julia package designed for quantum physics simulations, closely emulating the popular Python [QuTiP](https://github.com/qutip/qutip) package. It uniquely combines the simplicity and power of Julia with advanced features like GPU acceleration and distributed computing, making simulation of quantum systems more accessible and efficient. From f86f15e2f66ea3900e26c8f523b3073ea8aeeb1c Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sun, 5 May 2024 19:16:22 +0200 Subject: [PATCH 23/35] Add more benchmarks --- benchmarks/correlations_and_spectrum.jl | 30 ++++++++++++++++ benchmarks/dynamical_fock_dimension.jl | 33 +++++++++++++++++ benchmarks/eigenvalues.jl | 22 ++++++++++++ benchmarks/runbenchmarks.jl | 30 +++++----------- benchmarks/steadystate.jl | 15 ++++++++ benchmarks/timeevolution.jl | 48 +++++++++++++++++++++++++ docs/make.jl | 4 +-- 7 files changed, 159 insertions(+), 23 deletions(-) create mode 100644 benchmarks/correlations_and_spectrum.jl create mode 100644 benchmarks/dynamical_fock_dimension.jl create mode 100644 benchmarks/eigenvalues.jl create mode 100644 benchmarks/steadystate.jl create mode 100644 benchmarks/timeevolution.jl diff --git a/benchmarks/correlations_and_spectrum.jl b/benchmarks/correlations_and_spectrum.jl new file mode 100644 index 00000000..6cb7b141 --- /dev/null +++ b/benchmarks/correlations_and_spectrum.jl @@ -0,0 +1,30 @@ +function benchmark_correlations_and_spectrum() + ωc = 1 + ωq = 1 + g = 0.05 + ωd = 0.95 + F = 0.1 + nth = 7 + γ = 0.1 + + Δc = ωc - ωd + Δq = ωq - ωd + + # Operators definition + N = 50 # cutoff for the cavity Hilbert space + a = tensor(destroy(N), qeye(2)) + σm = tensor(qeye(N), sigmam()) + σz = tensor(qeye(N), sigmaz()) + + # Hamiltonian + H = Δc * a' * a + Δq * σz / 2 + g * (a' * σm + a * σm') + F * (a + a') + c_ops = [sqrt(γ * (nth + 1)) * a, sqrt(γ * nth) * a', sqrt(γ) * σm] + + ω_l = range(0, 3, length=1000) + + SUITE["Correlations and Spectrum"]["FFT Correlation"] = @benchmarkable spectrum($H, $ω_l, $(a'), $a, $c_ops, solver=FFTCorrelation(), progress_bar=false) + + SUITE["Correlations and Spectrum"]["Exponential Series"] = @benchmarkable spectrum($H, $ω_l, $(a'), $a, $c_ops) +end + +benchmark_correlations_and_spectrum() \ No newline at end of file diff --git a/benchmarks/dynamical_fock_dimension.jl b/benchmarks/dynamical_fock_dimension.jl new file mode 100644 index 00000000..9b4e5acb --- /dev/null +++ b/benchmarks/dynamical_fock_dimension.jl @@ -0,0 +1,33 @@ +function H_dfd2(dims, p) + Δ = p.Δ + F = p.F + J = p.J + a = tensor(destroy(dims[1]), qeye(dims[2])) + b = tensor(qeye(dims[1]), destroy(dims[2])) + Δ * a' * a + F * (a + a') + Δ * b' * b + J * (a' * b + a * b') +end +function c_ops_dfd2(dims, p) + κ = p.κ + a = tensor(destroy(dims[1]), qeye(dims[2])) + b = tensor(qeye(dims[1]), destroy(dims[2])) + [√κ * a, √κ * b] +end +function e_ops_dfd2(dims, p) + a = tensor(destroy(dims[1]), qeye(dims[2])) + b = tensor(qeye(dims[1]), destroy(dims[2])) + [a' * a, b' * b] +end + +function benchmark_dfd() + F, Δ, κ, J = 1.5, 0.25, 1, 0.05 + maxdims = [50, 50] + + ψ0 = tensor(fock(3, 0), fock(20, 15)) + dfd_params = (Δ=Δ, F=F, κ=κ, J=J) + + tlist = range(0, 15 / κ, 100) + + SUITE["Time Evolution"]["Dynamical Fock Dymension"] = @benchmarkable dfd_mesolve(H_dfd2, $ψ0, $tlist, c_ops_dfd2, $maxdims, $dfd_params, e_ops=e_ops_dfd2, progress_bar=false) +end + +benchmark_dfd() \ No newline at end of file diff --git a/benchmarks/eigenvalues.jl b/benchmarks/eigenvalues.jl new file mode 100644 index 00000000..dcb48e2c --- /dev/null +++ b/benchmarks/eigenvalues.jl @@ -0,0 +1,22 @@ +function benchmark_eigenvalues() + N = 5 + a = tensor(destroy(N), qeye(N)) + a_d = a' + b = tensor(qeye(N), destroy(N)) + b_d = b' + + ωc = 1 + ωb = 1 + g = 0.2 + κ = 0.01 + n_thermal = 0.1 + + H = ωc * a_d * a + ωb * b_d * b + g * (a + a_d) * (b + b_d) + c_ops = [√((1+n_thermal)*κ) * a, √κ * b, √(n_thermal*κ) * a_d] + L = liouvillian(H, c_ops) + + SUITE["Eigenvalues"]["eigenstates"]["dense"] = @benchmarkable eigenstates($L) + SUITE["Eigenvalues"]["eigenstates"]["sparse"] = @benchmarkable eigenstates($L, sparse=true, sigma=0.01, k=5) +end + +benchmark_eigenvalues() \ No newline at end of file diff --git a/benchmarks/runbenchmarks.jl b/benchmarks/runbenchmarks.jl index dea58b58..f7d4a62c 100644 --- a/benchmarks/runbenchmarks.jl +++ b/benchmarks/runbenchmarks.jl @@ -1,28 +1,16 @@ using BenchmarkTools using QuantumToolbox -suite = BenchmarkGroup() +const SUITE = BenchmarkGroup() -suite["steadystate"] = BenchmarkGroup(["steadystate"]) +include("correlations_and_spectrum.jl") +include("dynamical_fock_dimension.jl") +include("eigenvalues.jl") +include("steadystate.jl") +include("timeevolution.jl") - -## steadystate ## - -N = 50 -Δ = 0.1 -F = 2 -γ = 1 -a = destroy(N) -H = Δ * a' * a + F * (a + a') -c_ops = [sqrt(γ) * a] - -suite["steadystate"]["driven-dissipative harmonic oscillator"] = @benchmarkable steadystate($H, $c_ops) - -## end ## - - -BenchmarkTools.tune!(suite) -results = run(suite, verbose = true) +BenchmarkTools.tune!(SUITE) +results = BenchmarkTools.run(SUITE, verbose = true) display(median(results)) -BenchmarkTools.save(joinpath(@__DIR__, "benchmarks_output.json"), median(results)) \ No newline at end of file +BenchmarkTools.save("benchmarks_output.json", median(results)) \ No newline at end of file diff --git a/benchmarks/steadystate.jl b/benchmarks/steadystate.jl new file mode 100644 index 00000000..84379b91 --- /dev/null +++ b/benchmarks/steadystate.jl @@ -0,0 +1,15 @@ +function benchmark_steadystate() + N = 50 + Δ = 0.1 + F = 2 + γ = 1 + nth = 5 + + a = destroy(N) + H = Δ * a' * a + F * (a + a') + c_ops = [sqrt(γ * (nth + 1)) * a, sqrt(γ * nth) * a'] + + SUITE["Steadystate"]["Direct"] = @benchmarkable steadystate($H, $c_ops) +end + +benchmark_steadystate() \ No newline at end of file diff --git a/benchmarks/timeevolution.jl b/benchmarks/timeevolution.jl new file mode 100644 index 00000000..50b58cda --- /dev/null +++ b/benchmarks/timeevolution.jl @@ -0,0 +1,48 @@ +function benchmark_timeevolution() + ωc = 1 + ωq = 1 + g = 0.05 + ωd = 0.95 + F = 0.1 + + Δc = ωc - ωd + Δq = ωq - ωd + + # Operators definition + N = 50 # cutoff for the cavity Hilbert space + a = tensor(destroy(N), qeye(2)) + σm = tensor(qeye(N), sigmam()) + σz = tensor(qeye(N), sigmaz()) + + # Hamiltonian + H = Δc * a' * a + Δq * σz / 2 + g * (a' * σm + a * σm') + F * (a + a') + + e_ops = [a'*a, σz] + + # Initial state + ψ0 = tensor(coherent(N, 0), fock(2, 1)) + + ## sesolve ## + + tlist = range(0, 2π * 10 / g, 1000) + + SUITE["Time Evolution"]["time-independent"]["sesolve"] = @benchmarkable sesolve($H, $ψ0, $tlist, e_ops=$e_ops, progress_bar=false) + + ## mesolve ## + + nth = 7 + γ = 0.1 + c_ops = [sqrt(γ * (nth + 1)) * a, sqrt(γ * nth) * a', sqrt(γ) * σm] + + tlist = range(0, 10/γ, 100) + + SUITE["Time Evolution"]["time-independent"]["mesolve"] = @benchmarkable mesolve($H, $ψ0, $tlist, $c_ops, e_ops=$e_ops, progress_bar=false) + + ## mcsolve ## + + ntraj = 100 + + SUITE["Time Evolution"]["time-independent"]["mcsolve"] = @benchmarkable mcsolve($H, $ψ0, $tlist, $c_ops, n_traj=ntraj, e_ops=$e_ops) +end + +benchmark_timeevolution() \ No newline at end of file diff --git a/docs/make.jl b/docs/make.jl index 5e0dd525..70819977 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -8,7 +8,6 @@ DocMeta.setdocmeta!(QuantumToolbox, :DocTestSetup, :(using QuantumToolbox); recu makedocs(; modules=[QuantumToolbox], authors="Alberto Mercurio", - # repo="https://github.com/albertomercurio/QuantumToolbox.jl/blob/{commit}{path}#{line}", repo = Remotes.GitHub("albertomercurio", "QuantumToolbox.jl"), sitename="QuantumToolbox.jl", format=Documenter.HTML(; @@ -30,7 +29,8 @@ makedocs(; "api.md", "Users Guide" => [ "Low Rank Master Equation" => "lowrank.md", - ] + ], + "Benchmarks" => "benchmarks/index.html" ], ) From d6f3a449304b359dcd35696a197a95c9b50a85c3 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sun, 5 May 2024 19:24:17 +0200 Subject: [PATCH 24/35] Solve link issue --- docs/make.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 70819977..c0999563 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -30,7 +30,7 @@ makedocs(; "Users Guide" => [ "Low Rank Master Equation" => "lowrank.md", ], - "Benchmarks" => "benchmarks/index.html" + "Benchmarks" => "https://albertomercurio.github.io/QuantumToolbox.jl/benchmarks/" ], ) From 768ddf7ac3f840bbcecd859c5c07c5f662de7142 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sun, 5 May 2024 19:40:37 +0200 Subject: [PATCH 25/35] Fix link error --- docs/make.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index c0999563..39871d45 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -30,7 +30,9 @@ makedocs(; "Users Guide" => [ "Low Rank Master Equation" => "lowrank.md", ], - "Benchmarks" => "https://albertomercurio.github.io/QuantumToolbox.jl/benchmarks/" + "Benchmarks" => [ + "Benchmark History" => "https://albertomercurio.github.io/QuantumToolbox.jl/benchmarks/", + ] ], ) From 0853bffb6c035c9af37dcecf90fc579e3532fefc Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sun, 5 May 2024 20:05:35 +0200 Subject: [PATCH 26/35] Fix url link --- docs/make.jl | 2 +- docs/src/benchmarks/benchmark_history.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 docs/src/benchmarks/benchmark_history.md diff --git a/docs/make.jl b/docs/make.jl index 39871d45..6edc551e 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -31,7 +31,7 @@ makedocs(; "Low Rank Master Equation" => "lowrank.md", ], "Benchmarks" => [ - "Benchmark History" => "https://albertomercurio.github.io/QuantumToolbox.jl/benchmarks/", + "Benchmark History" => "benchmarks/benchmark_history.md", ] ], ) diff --git a/docs/src/benchmarks/benchmark_history.md b/docs/src/benchmarks/benchmark_history.md new file mode 100644 index 00000000..d0dc9682 --- /dev/null +++ b/docs/src/benchmarks/benchmark_history.md @@ -0,0 +1 @@ + \ No newline at end of file From 25cc1c79cc391e10b3cb63ed2c7127fdff2bb3a3 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sun, 5 May 2024 21:11:25 +0200 Subject: [PATCH 27/35] Fix benchmark stack --- benchmarks/correlations_and_spectrum.jl | 26 +++++++------------------ benchmarks/dynamical_fock_dimension.jl | 4 ++-- benchmarks/runbenchmarks.jl | 2 ++ benchmarks/timeevolution.jl | 16 +++++++-------- 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/benchmarks/correlations_and_spectrum.jl b/benchmarks/correlations_and_spectrum.jl index 6cb7b141..2d15d200 100644 --- a/benchmarks/correlations_and_spectrum.jl +++ b/benchmarks/correlations_and_spectrum.jl @@ -1,24 +1,12 @@ function benchmark_correlations_and_spectrum() - ωc = 1 - ωq = 1 - g = 0.05 - ωd = 0.95 - F = 0.1 - nth = 7 + N = 15 + ω = 1 γ = 0.1 - - Δc = ωc - ωd - Δq = ωq - ωd - - # Operators definition - N = 50 # cutoff for the cavity Hilbert space - a = tensor(destroy(N), qeye(2)) - σm = tensor(qeye(N), sigmam()) - σz = tensor(qeye(N), sigmaz()) - - # Hamiltonian - H = Δc * a' * a + Δq * σz / 2 + g * (a' * σm + a * σm') + F * (a + a') - c_ops = [sqrt(γ * (nth + 1)) * a, sqrt(γ * nth) * a', sqrt(γ) * σm] + nth = 0.02 + + a = destroy(N) + H = ω * a' * a + c_ops = [sqrt(γ * (nth + 1)) * a, sqrt(γ * nth) * a'] ω_l = range(0, 3, length=1000) diff --git a/benchmarks/dynamical_fock_dimension.jl b/benchmarks/dynamical_fock_dimension.jl index 9b4e5acb..b37f0180 100644 --- a/benchmarks/dynamical_fock_dimension.jl +++ b/benchmarks/dynamical_fock_dimension.jl @@ -19,7 +19,7 @@ function e_ops_dfd2(dims, p) end function benchmark_dfd() - F, Δ, κ, J = 1.5, 0.25, 1, 0.05 + F, Δ, κ, J = 1, 0.25, 1, 0.05 maxdims = [50, 50] ψ0 = tensor(fock(3, 0), fock(20, 15)) @@ -27,7 +27,7 @@ function benchmark_dfd() tlist = range(0, 15 / κ, 100) - SUITE["Time Evolution"]["Dynamical Fock Dymension"] = @benchmarkable dfd_mesolve(H_dfd2, $ψ0, $tlist, c_ops_dfd2, $maxdims, $dfd_params, e_ops=e_ops_dfd2, progress_bar=false) + SUITE["Time Evolution"]["Dynamical Fock Dimension"] = @benchmarkable dfd_mesolve(H_dfd2, $ψ0, $tlist, c_ops_dfd2, $maxdims, $dfd_params, e_ops=e_ops_dfd2, progress_bar=false) end benchmark_dfd() \ No newline at end of file diff --git a/benchmarks/runbenchmarks.jl b/benchmarks/runbenchmarks.jl index f7d4a62c..6dc699d5 100644 --- a/benchmarks/runbenchmarks.jl +++ b/benchmarks/runbenchmarks.jl @@ -1,6 +1,8 @@ using BenchmarkTools using QuantumToolbox +BLAS.set_num_threads(1) + const SUITE = BenchmarkGroup() include("correlations_and_spectrum.jl") diff --git a/benchmarks/timeevolution.jl b/benchmarks/timeevolution.jl index 50b58cda..941552ce 100644 --- a/benchmarks/timeevolution.jl +++ b/benchmarks/timeevolution.jl @@ -1,15 +1,15 @@ function benchmark_timeevolution() ωc = 1 ωq = 1 - g = 0.05 - ωd = 0.95 - F = 0.1 + g = 0.1 + ωd = 0.99 + F = 0.07 Δc = ωc - ωd Δq = ωq - ωd # Operators definition - N = 50 # cutoff for the cavity Hilbert space + N = 20 # cutoff for the cavity Hilbert space a = tensor(destroy(N), qeye(2)) σm = tensor(qeye(N), sigmam()) σz = tensor(qeye(N), sigmaz()) @@ -30,8 +30,8 @@ function benchmark_timeevolution() ## mesolve ## - nth = 7 - γ = 0.1 + nth = 0.01 + γ = 0.05 c_ops = [sqrt(γ * (nth + 1)) * a, sqrt(γ * nth) * a', sqrt(γ) * σm] tlist = range(0, 10/γ, 100) @@ -40,9 +40,7 @@ function benchmark_timeevolution() ## mcsolve ## - ntraj = 100 - - SUITE["Time Evolution"]["time-independent"]["mcsolve"] = @benchmarkable mcsolve($H, $ψ0, $tlist, $c_ops, n_traj=ntraj, e_ops=$e_ops) + SUITE["Time Evolution"]["time-independent"]["mcsolve"] = @benchmarkable mcsolve($H, $ψ0, $tlist, $c_ops, n_traj=100, e_ops=$e_ops, progress_bar=false) end benchmark_timeevolution() \ No newline at end of file From 7a8fdf03bb32e96009afb22a355dbb2bd027c801 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sun, 5 May 2024 22:17:47 +0200 Subject: [PATCH 28/35] Try to changve cache --- .github/workflows/Benchmarks.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Benchmarks.yml b/.github/workflows/Benchmarks.yml index 43d3f565..f7c920ac 100644 --- a/.github/workflows/Benchmarks.yml +++ b/.github/workflows/Benchmarks.yml @@ -37,7 +37,17 @@ jobs: with: version: '1' arch: x64 - - uses: julia-actions/cache@v1 + # - uses: julia-actions/cache@v1 + - uses: actions/cache@v4 + env: + cache-name: cache-artifacts + with: + path: ~/.julia/artifacts + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + restore-keys: | + ${{ runner.os }}-test-${{ env.cache-name }}- + ${{ runner.os }}-test- + ${{ runner.os }}- - name: Run benchmark run: | cd benchmarks @@ -50,7 +60,7 @@ jobs: - name: Parse & Upload Benchmark Results uses: benchmark-action/github-action-benchmark@v1 with: - name: Benchmark results + name: Benchmark Results tool: "julia" output-file-path: benchmarks/benchmarks_output.json summary-always: true From b844d06306f3fea5ae14e6a31f60c4be6c819d38 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Sun, 5 May 2024 22:51:38 +0200 Subject: [PATCH 29/35] Add serial version of mcsolve --- benchmarks/timeevolution.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmarks/timeevolution.jl b/benchmarks/timeevolution.jl index 941552ce..aa9e47fc 100644 --- a/benchmarks/timeevolution.jl +++ b/benchmarks/timeevolution.jl @@ -40,7 +40,8 @@ function benchmark_timeevolution() ## mcsolve ## - SUITE["Time Evolution"]["time-independent"]["mcsolve"] = @benchmarkable mcsolve($H, $ψ0, $tlist, $c_ops, n_traj=100, e_ops=$e_ops, progress_bar=false) + SUITE["Time Evolution"]["time-independent"]["mcsolve"]["Serial"] = @benchmarkable mcsolve($H, $ψ0, $tlist, $c_ops, n_traj=100, e_ops=$e_ops, progress_bar=false, ensemble_method=EnsembleSerial()) + SUITE["Time Evolution"]["time-independent"]["mcsolve"]["Multithreaded"] = @benchmarkable mcsolve($H, $ψ0, $tlist, $c_ops, n_traj=100, e_ops=$e_ops, progress_bar=false, ensemble_method=EnsembleThreads()) end benchmark_timeevolution() \ No newline at end of file From d28a50d904b5c8ec24232e0f140970794f576be2 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Mon, 6 May 2024 01:48:06 +0200 Subject: [PATCH 30/35] Fix Benchmark page and replace Plots.jl with CairoMakie.jl --- docs/Project.toml | 3 +-- docs/src/benchmarks/benchmark_history.md | 4 ++- docs/src/lowrank.md | 34 +++++++++++++----------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/docs/Project.toml b/docs/Project.toml index bfecd61a..e3e6bc6b 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,4 +1,3 @@ [deps] +CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" -Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" diff --git a/docs/src/benchmarks/benchmark_history.md b/docs/src/benchmarks/benchmark_history.md index d0dc9682..d146ba15 100644 --- a/docs/src/benchmarks/benchmark_history.md +++ b/docs/src/benchmarks/benchmark_history.md @@ -1 +1,3 @@ - \ No newline at end of file +```@raw html + +``` \ No newline at end of file diff --git a/docs/src/lowrank.md b/docs/src/lowrank.md index 5c4fc889..1148418a 100644 --- a/docs/src/lowrank.md +++ b/docs/src/lowrank.md @@ -3,9 +3,9 @@ We start by importing the packages ```@example lowrank -using Plots -using LaTeXStrings -using QuantumToolbox; +using QuantumToolbox +using CairoMakie +CairoMakie.enable_only_mime!(MIME"image/svg+xml"()) ``` Define lattice @@ -134,19 +134,21 @@ opt = LRMesolveOptions( Plot the results ```@example lowrank -fig = plot(layout=(1,2), size=(800,400), legend=:topleft, xlabel=L"\gamma t") - m_me = real(mesol.expect[3,:])/Nx/Ny m_lr = real(lrsol.expvals[3,:])/Nx/Ny -plot!(fig[1], tl, m_lr, label=raw"LR $[M=M(t)]$", lw=2) -plot!(fig[1], tl, m_me, ls=:dash, label="Fock", lw=2) -ylabel!(fig[1], L"M_{z}") - -plot!(fig[2], tl, 1 .-real(lrsol.funvals[1,:]), label=L"$1-P$", lw=2) -plot!(fig[2], tl, 1 .-real(lrsol.funvals[3,:]), c=:orange, label=L"$1-\rm{Tr}(\rho)$", lw=2, ls=:dash) -plot!(fig[2], tl, real(lrsol.funvals[2,:])/Nx/Ny, c=:blue, label=L"S", lw=2) -hline!(fig[2], [Strue], c=:blue, ls=:dash, lw=2, label=L"S^{\rm \,true}_{\rm ss}") -ylabel!(fig[2], "value") -xlabel!(fig[2], L"\gamma t") -``` \ No newline at end of file +fig = Figure(size=(800, 400), fontsize=15) +ax = Axis(fig[1, 1], xlabel=L"\gamma t", ylabel=L"M_{z}", xlabelsize=20, ylabelsize=20) +lines!(ax, tl, m_lr, label=L"LR $[M=M(t)]$", linewidth=2) +lines!(ax, tl, m_me, label="Fock", linewidth=2, linestyle=:dash) +axislegend(ax, position=:rb) + +ax2 = Axis(fig[1, 2], xlabel=L"\gamma t", ylabel="Value", xlabelsize=20, ylabelsize=20) +lines!(ax2, tl, 1 .-real(lrsol.funvals[1,:]), label=L"$1-P$", linewidth=2) +lines!(ax2, tl, 1 .-real(lrsol.funvals[3,:]), label=L"$1-\mathrm{Tr}(\rho)$", linewidth=2, linestyle=:dash, color=:orange) +lines!(ax2, tl, real(lrsol.funvals[2,:])/Nx/Ny, color=:blue, label=L"S", linewidth=2) +hlines!(ax2, [Strue], color=:blue, linestyle=:dash, linewidth=2, label=L"S^{\,\mathrm{true}}_{\mathrm{ss}}") +axislegend(ax2, position=:rb) + +fig +``` From 5b08e04fbd7827272fe5f5d2f98d02b27cb3fd26 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 05:32:34 +0000 Subject: [PATCH 31/35] Bump julia-actions/cache from 1 to 2 Bumps [julia-actions/cache](https://github.com/julia-actions/cache) from 1 to 2. - [Release notes](https://github.com/julia-actions/cache/releases) - [Commits](https://github.com/julia-actions/cache/compare/v1...v2) --- updated-dependencies: - dependency-name: julia-actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/CI.yml | 2 +- .github/workflows/documentation.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 6e444fbf..f15631ce 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -64,7 +64,7 @@ jobs: with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - - uses: julia-actions/cache@v1 + - uses: julia-actions/cache@v2 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 env: diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 781721ab..9cbf3f77 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -27,7 +27,7 @@ jobs: - uses: julia-actions/setup-julia@v2 with: version: '1' - - uses: julia-actions/cache@v1 + - uses: julia-actions/cache@v2 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-docdeploy@v1 env: From 6ba2efecd3759a668494b1605f4afb44a552c503 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Mon, 6 May 2024 19:16:13 +0200 Subject: [PATCH 32/35] Use cache v2 also for benchmarks CI --- .github/workflows/Benchmarks.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/Benchmarks.yml b/.github/workflows/Benchmarks.yml index f7c920ac..68323744 100644 --- a/.github/workflows/Benchmarks.yml +++ b/.github/workflows/Benchmarks.yml @@ -37,17 +37,17 @@ jobs: with: version: '1' arch: x64 - # - uses: julia-actions/cache@v1 - - uses: actions/cache@v4 - env: - cache-name: cache-artifacts - with: - path: ~/.julia/artifacts - key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} - restore-keys: | - ${{ runner.os }}-test-${{ env.cache-name }}- - ${{ runner.os }}-test- - ${{ runner.os }}- + - uses: julia-actions/cache@v2 + # - uses: actions/cache@v4 + # env: + # cache-name: cache-artifacts + # with: + # path: ~/.julia/artifacts + # key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + # restore-keys: | + # ${{ runner.os }}-test-${{ env.cache-name }}- + # ${{ runner.os }}-test- + # ${{ runner.os }}- - name: Run benchmark run: | cd benchmarks From ee51151ac38e93e58f31d968c2070fe13045acd3 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Mon, 6 May 2024 19:47:05 +0200 Subject: [PATCH 33/35] Minor change --- .github/workflows/Benchmarks.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/Benchmarks.yml b/.github/workflows/Benchmarks.yml index 68323744..c595df48 100644 --- a/.github/workflows/Benchmarks.yml +++ b/.github/workflows/Benchmarks.yml @@ -38,16 +38,6 @@ jobs: version: '1' arch: x64 - uses: julia-actions/cache@v2 - # - uses: actions/cache@v4 - # env: - # cache-name: cache-artifacts - # with: - # path: ~/.julia/artifacts - # key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} - # restore-keys: | - # ${{ runner.os }}-test-${{ env.cache-name }}- - # ${{ runner.os }}-test- - # ${{ runner.os }}- - name: Run benchmark run: | cd benchmarks From c21a0c051d40816286602c60f26b3217c9961582 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Mon, 6 May 2024 20:09:56 +0200 Subject: [PATCH 34/35] Change to DOCUMENTER_KEY --- .github/workflows/Benchmarks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Benchmarks.yml b/.github/workflows/Benchmarks.yml index c595df48..1a108ae7 100644 --- a/.github/workflows/Benchmarks.yml +++ b/.github/workflows/Benchmarks.yml @@ -54,7 +54,7 @@ jobs: tool: "julia" output-file-path: benchmarks/benchmarks_output.json summary-always: true - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.DOCUMENTER_KEY }} comment-always: true alert-threshold: "200%" fail-on-alert: true From 4dcf581192d9c9f5edf86ec0bf79441a95c4b5c0 Mon Sep 17 00:00:00 2001 From: Alberto Mercurio Date: Mon, 6 May 2024 20:27:27 +0200 Subject: [PATCH 35/35] Remove concurrency --- .github/workflows/Benchmarks.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/Benchmarks.yml b/.github/workflows/Benchmarks.yml index 1a108ae7..7ae6ce58 100644 --- a/.github/workflows/Benchmarks.yml +++ b/.github/workflows/Benchmarks.yml @@ -21,12 +21,6 @@ permissions: contents: write deployments: write -concurrency: - # Skip intermediate builds: always. - # Cancel intermediate builds: only if it is a pull request build. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} - jobs: benchmark: runs-on: ubuntu-latest @@ -53,10 +47,9 @@ jobs: name: Benchmark Results tool: "julia" output-file-path: benchmarks/benchmarks_output.json - summary-always: true - github-token: ${{ secrets.DOCUMENTER_KEY }} - comment-always: true + github-token: ${{ secrets.GITHUB_TOKEN }} alert-threshold: "200%" fail-on-alert: true benchmark-data-dir-path: benchmarks + max-items-in-chart: 100 auto-push: ${{ github.event_name != 'pull_request' }}