Skip to content

Commit

Permalink
Merge pull request #94 from ytdHuang/opt/imports
Browse files Browse the repository at this point in the history
Reorganize keywords: `import`, `using`, and `export`
  • Loading branch information
albertomercurio authored May 1, 2024
2 parents 1c1567c + 6991167 commit 0f43c6e
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 72 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -21,7 +20,6 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"

[compat]
DiffEqCallbacks = "2, 3"
Distributed = "<0.0.1, 1"
FFTW = "1.5"
Graphs = "1.7"
IncompleteLU = "0.2"
Expand Down
62 changes: 26 additions & 36 deletions src/QuantumToolbox.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
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

using LinearAlgebra: BlasFloat, BlasComplex
# 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

# 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 Random
import SpecialFunctions: loggamma

# Setting the number of threads to 1 allows
# to achieve better performances for more massive parallelizations
Expand All @@ -39,28 +53,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
5 changes: 5 additions & 0 deletions src/correlations.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 2 additions & 12 deletions src/eigsolve.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
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

export EigsolveResult
export eigenenergies, eigenstates, eigsolve, eigsolve_al

@doc raw"""
struct EigsolveResult{T1<:Vector{<:Number}, T2<:AbstractMatrix{<:Number}, ObjType<:Union{Nothing,OperatorQuantumObject,SuperOperatorQuantumObject}}
Expand Down
7 changes: 7 additions & 0 deletions src/general_functions.jl
Original file line number Diff line number Diff line change
@@ -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...)
Expand Down
2 changes: 2 additions & 0 deletions src/negativity.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export negativity, partial_transpose

@doc raw"""
negativity(ρ::QuantumObject, subsys::Int; logarithmic::Bool=false)
Expand Down
2 changes: 2 additions & 0 deletions src/permutation.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export bdf, get_bdf_blocks

function bdf(A::SparseMatrixCSC{T,M}) where {T,M}
n = LinearAlgebra.checksquare(A)

Expand Down
9 changes: 6 additions & 3 deletions src/quantum_object.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using LinearAlgebra
using LinearAlgebra: checksquare, BlasFloat, BlasComplex, BlasReal, BlasInt
import LinearAlgebra
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
Expand Down
6 changes: 6 additions & 0 deletions src/quantum_operators.jl
Original file line number Diff line number Diff line change
@@ -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)))
Expand Down
3 changes: 2 additions & 1 deletion src/time_evolution/mcsolve.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
42 changes: 24 additions & 18 deletions src/time_evolution/time_evolution.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
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

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
Expand Down Expand Up @@ -139,7 +148,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."))

Expand All @@ -150,11 +159,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
Expand Down Expand Up @@ -244,20 +252,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)
Expand All @@ -277,8 +285,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.
Expand All @@ -292,11 +300,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)
Expand All @@ -308,11 +315,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)
Expand Down
2 changes: 2 additions & 0 deletions src/time_evolution/time_evolution_dynamical.jl
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
4 changes: 4 additions & 0 deletions src/wigner.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export WignerSolver, WignerClenshaw, WignerLaguerre, wigner

abstract type WignerSolver end

struct WignerClenshaw <: WignerSolver end

struct WignerLaguerre <: WignerSolver
parallel::Bool
tol::Float64
Expand Down

0 comments on commit 0f43c6e

Please sign in to comment.