From d2b7b305f9722146a7e6283de460c82d72d82ce8 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Wed, 1 May 2024 17:45:33 +0800 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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