Skip to content

Commit

Permalink
Merge pull request #113 from ytdHuang/dev/structure
Browse files Browse the repository at this point in the history
Re-structure the code fore entire package
  • Loading branch information
ytdHuang authored Oct 29, 2024
2 parents c73c451 + ad81ab0 commit 611e498
Show file tree
Hide file tree
Showing 25 changed files with 555 additions and 621 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ Alternatively, this can also be done in Julia's [Pkg REPL](https://julialang.git
```
More information about `Julia`'s package manager can be found at [`Pkg.jl`](https://julialang.github.io/Pkg.jl/v1/).

To load the package and check the version information, use the command:
To load the package and check the version information, use either `HierarchicalEOM.versioninfo()` or `HierarchicalEOM.about()`, namely
```julia
julia> using HierarchicalEOM
julia> HierarchicalEOM.versioninfo()
using HierarchicalEOM
HierarchicalEOM.versioninfo()
HierarchicalEOM.about()
```

## Documentation
Expand Down
7 changes: 4 additions & 3 deletions docs/src/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ More information about `Julia`'s package manager can be found at [`Pkg.jl`](http
!!! note "Julia 1.10"
`HierarchicalEOM.jl` requires Julia 1.10 or higher (we dropped Julia 1.9 since ver.2.1.0)

To load the package and check the version information, use the command:
To load the package and check the version information, use either [`HierarchicalEOM.versioninfo()`](@ref) or [`HierarchicalEOM.about()`](@ref), namely
```julia
julia> using HierarchicalEOM
julia> HierarchicalEOM.versioninfo()
using HierarchicalEOM
HierarchicalEOM.versioninfo()
HierarchicalEOM.about()
```

## [QuantumToolbox.jl](https://github.com/qutip/QuantumToolbox.jl)
Expand Down
1 change: 1 addition & 0 deletions docs/src/libraryAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ DensityOfStates
## Misc.
```@docs
HierarchicalEOM.versioninfo()
HierarchicalEOM.about()
```
The outputs will be something like the following:
```@example
Expand Down
15 changes: 1 addition & 14 deletions ext/HierarchicalEOM_CUDAExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module HierarchicalEOM_CUDAExt

using HierarchicalEOM
import HierarchicalEOM.HeomBase: AbstractHEOMLSMatrix, _Tr, _HandleVectorType
import HierarchicalEOM: _Tr, _HandleVectorType
import QuantumToolbox: _CType
import CUDA
import CUDA: cu, CuArray
Expand Down Expand Up @@ -78,17 +78,4 @@ end
_HandleVectorType(::AbstractHEOMLSMatrix{<:CuSparseMatrixCSC{T}}, V::SparseVector) where {T<:Number} =
CuArray{_CType(T)}(V)

##### We first remove this part because there are errors when solveing steady states using GPU
# function _HandleSteadyStateMatrix(MatrixType::Type{TM}, M::AbstractHEOMLSMatrix, S::Int) where TM <: CuSparseMatrixCSC
# colptr = Vector{Int32}(M.data.colPtr)
# rowval = Vector{Int32}(M.data.rowVal)
# nzval = Vector{ComplexF32}(M.data.nzVal)
# A = SparseMatrixCSC{ComplexF32, Int32}(S, S, colptr, rowval, nzval)
# A[1,1:S] .= 0f0
#
# # sparse(row_idx, col_idx, values, row_dims, col_dims)
# A += sparse(ones(Int32, M.dim), [Int32((n - 1) * (M.dim + 1) + 1) for n in 1:(M.dim)], ones(ComplexF32, M.dim), S, S)
# return CuSparseMatrixCSC(A)
# end

end
28 changes: 16 additions & 12 deletions src/ADOs.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export ADOs
export getRho, getADO

@doc raw"""
struct ADOs
The Auxiliary Density Operators for HEOM model.
Expand Down Expand Up @@ -69,24 +72,24 @@ end
ADOs(ρ, N::Int = 1, parity::AbstractParity = EVEN) =
error("HierarchicalEOM doesn't support input `ρ` with type : $(typeof(ρ))")

checkbounds(A::ADOs, i::Int) =
Base.checkbounds(A::ADOs, i::Int) =
((i > A.N) || (i < 1)) ? error("Attempt to access $(A.N)-element ADOs at index [$(i)]") : nothing

@doc raw"""
length(A::ADOs)
Returns the total number of the Auxiliary Density Operators (ADOs)
"""
length(A::ADOs) = A.N
Base.length(A::ADOs) = A.N

@doc raw"""
eltype(A::ADOs)
Returns the elements' type of the Auxiliary Density Operators (ADOs)
"""
eltype(A::ADOs) = eltype(A.data)
Base.eltype(A::ADOs) = eltype(A.data)

lastindex(A::ADOs) = length(A)
Base.lastindex(A::ADOs) = length(A)

function getindex(A::ADOs, i::Int)
function Base.getindex(A::ADOs, i::Int)
checkbounds(A, i)

D = prod(A.dims)
Expand All @@ -95,7 +98,7 @@ function getindex(A::ADOs, i::Int)
return QuantumObject(reshape(A.data[(back-sup_dim+1):back], D, D), Operator, A.dims)
end

function getindex(A::ADOs, r::UnitRange{Int})
function Base.getindex(A::ADOs, r::UnitRange{Int})
checkbounds(A, r[1])
checkbounds(A, r[end])

Expand All @@ -108,12 +111,13 @@ function getindex(A::ADOs, r::UnitRange{Int})
end
return result
end
getindex(A::ADOs, ::Colon) = getindex(A, 1:lastindex(A))
Base.getindex(A::ADOs, ::Colon) = getindex(A, 1:lastindex(A))

iterate(A::ADOs, state::Int = 1) = state > length(A) ? nothing : (A[state], state + 1)
Base.iterate(A::ADOs, state::Int = 1) = state > length(A) ? nothing : (A[state], state + 1)

show(io::IO, A::ADOs) = print(io, "$(A.N) Auxiliary Density Operators with $(A.parity) and (system) dims = $(A.dims)\n")
show(io::IO, m::MIME"text/plain", A::ADOs) = show(io, A)
Base.show(io::IO, A::ADOs) =
print(io, "$(A.N) Auxiliary Density Operators with $(A.parity) and (system) dims = $(A.dims)\n")
Base.show(io::IO, m::MIME"text/plain", A::ADOs) = show(io, A)

@doc raw"""
getRho(ados)
Expand Down Expand Up @@ -161,7 +165,7 @@ where ``O`` is the operator and ``\rho`` is the reduced density operator in the
# Returns
- `exp_val` : The expectation value
"""
function expect(op, ados::ADOs; take_real::Bool = true)
function QuantumToolbox.expect(op, ados::ADOs; take_real::Bool = true)
if typeof(op) <: HEOMSuperOp
_check_sys_dim_and_ADOs_num(op, ados)
exp_val = dot(transpose(_Tr(ados.dims, ados.N)), (SparseMatrixCSC(op) * ados).data)
Expand Down Expand Up @@ -193,7 +197,7 @@ where ``O`` is the operator and ``\rho`` is the reduced density operator in one
# Returns
- `exp_val` : The expectation value
"""
function expect(op, ados_list::Vector{ADOs}; take_real::Bool = true)
function QuantumToolbox.expect(op, ados_list::Vector{ADOs}; take_real::Bool = true)
dims = ados_list[1].dims
N = ados_list[1].N
for i in 2:length(ados_list)
Expand Down
16 changes: 13 additions & 3 deletions src/HeomBase.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export AbstractHEOMLSMatrix

abstract type AbstractHEOMLSMatrix{T} end

_FType(::AbstractHEOMLSMatrix{<:AbstractArray{T}}) where {T<:Number} = _FType(T)
_CType(::AbstractHEOMLSMatrix{<:AbstractArray{T}}) where {T<:Number} = _CType(T)
QuantumToolbox._FType(::AbstractHEOMLSMatrix{<:AbstractArray{T}}) where {T<:Number} = _FType(T)
QuantumToolbox._CType(::AbstractHEOMLSMatrix{<:AbstractArray{T}}) where {T<:Number} = _CType(T)

# equal to : sparse(vec(system_identity_matrix))
function _Tr(dims::SVector, N::Int)
Expand Down Expand Up @@ -131,7 +133,7 @@ end
"""
HierarchicalEOM.versioninfo(io::IO=stdout)
Command line output of information on HierarchicalEOM, dependencies, and system informations.
Command line output of information on HierarchicalEOM, dependencies, and system information.
"""
function versioninfo(io::IO = stdout)
cpu = Sys.cpu_info()
Expand Down Expand Up @@ -162,6 +164,7 @@ function versioninfo(io::IO = stdout)
"Julia Ver. $(VERSION)\n",
"HierarchicalEOM Ver. $(_get_pkg_version("HierarchicalEOM"))\n",
"QuantumToolbox Ver. $(_get_pkg_version("QuantumToolbox"))\n",
"SciMLOperators Ver. $(_get_pkg_version("SciMLOperators"))\n",
"LinearSolve Ver. $(_get_pkg_version("LinearSolve"))\n",
"OrdinaryDiffEqCore Ver. $(_get_pkg_version("OrdinaryDiffEqCore"))\n",
)
Expand All @@ -179,3 +182,10 @@ function versioninfo(io::IO = stdout)
println(io, """Threads : $(Threads.nthreads()) (on $(Sys.CPU_THREADS) virtual cores)""")
return print(io, "\n")
end

"""
QuantumToolbox.about(io::IO=stdout)
Command line output of information on HierarchicalEOM, dependencies, and system information, same as [`HierarchicalEOM.versioninfo`](@ref).
"""
about(io::IO = stdout) = versioninfo(io)
203 changes: 47 additions & 156 deletions src/HierarchicalEOM.jl
Original file line number Diff line number Diff line change
@@ -1,164 +1,55 @@
module HierarchicalEOM

# Re-export QuantumToolbox
import Reexport: @reexport
@reexport using QuantumToolbox

# sub-module HeomBase for HierarchicalEOM
module HeomBase
import Pkg
import LinearAlgebra: BLAS, kron, I
import SparseArrays: sparse, SparseVector, SparseMatrixCSC, AbstractSparseMatrix
import StaticArraysCore: SVector
import QuantumToolbox: _FType, _CType, QuantumObject, QuantumObjectType, Operator, SuperOperator

export _Tr,
AbstractHEOMLSMatrix,
_check_sys_dim_and_ADOs_num,
_check_parity,
HandleMatrixType,
_HandleVectorType,
_HandleSteadyStateMatrix

include("HeomBase.jl")
end
import .HeomBase.versioninfo as versioninfo
import .HeomBase.print_logo as print_logo
@reexport import .HeomBase: AbstractHEOMLSMatrix

# sub-module Bath for HierarchicalEOM
module Bath
using ..HeomBase
import Base: show, length, getindex, lastindex, iterate, checkbounds
import LinearAlgebra: ishermitian, eigvals, I
import SparseArrays: SparseMatrixCSC
import StaticArraysCore: SVector
import QuantumToolbox: QuantumObject, _spre, _spost

export AbstractBath,
BosonBath,
BosonBathRWA,
FermionBath,
Exponent,
C,
AbstractBosonBath,
bosonReal,
bosonImag,
bosonRealImag,
bosonAbsorb,
bosonEmit,
AbstractFermionBath,
fermionAbsorb,
fermionEmit,
Boson_DrudeLorentz_Matsubara,
Boson_DrudeLorentz_Pade,
Fermion_Lorentz_Matsubara,
Fermion_Lorentz_Pade

include("Bath.jl")
include("bath_correlation_functions/bath_correlation_func.jl")
end
@reexport using .Bath

# sub-module HeomAPI for HierarchicalEOM
module HeomAPI
import Reexport: @reexport
using ..HeomBase
using ..Bath
import Base:
==,
!,
+,
-,
*,
show,
length,
size,
getindex,
keys,
setindex!,
lastindex,
iterate,
checkbounds,
hash,
copy,
eltype
import Base.Threads: @threads, threadid, nthreads, lock, unlock, SpinLock
import LinearAlgebra: I, kron, tr, norm, dot, mul!
import SparseArrays: sparse, sparsevec, spzeros, SparseVector, SparseMatrixCSC, AbstractSparseMatrix
import StaticArraysCore: SVector
import QuantumToolbox:
_FType,
QuantumObject,
Operator,
SuperOperator,
_spre,
_spost,
spre,
spost,
sprepost,
expect,
ket2dm,
liouvillian,
lindblad_dissipator,
steadystate,
ProgressBar,
next!

import FastExpm: fastExpm
import SciMLBase: init, solve, solve!, u_modified!, ODEProblem, FullSpecialize, CallbackSet
import SciMLOperators: MatrixOperator
import OrdinaryDiffEqCore: OrdinaryDiffEqAlgorithm
import OrdinaryDiffEqLowOrderRK: DP5
import DiffEqCallbacks: PresetTimeCallback, TerminateSteadyState
import LinearSolve: LinearProblem, SciMLLinearSolveAlgorithm, UMFPACKFactorization
import JLD2: jldopen

export AbstractParity,
OddParity,
EvenParity,
value,
ODD,
EVEN,
ADOs,
getRho,
getADO,
Nvec,
AbstractHierarchyDict,
HierarchyDict,
MixHierarchyDict,
getIndexEnsemble,
HEOMSuperOp,
M_S,
M_Boson,
M_Fermion,
M_Boson_Fermion,
Propagator,
addBosonDissipator,
addFermionDissipator,
addTerminator,
TimeEvolutionHEOMSol,
HEOMsolve,
PowerSpectrum,
DensityOfStates

include("Parity.jl")
include("ADOs.jl")

include("heom_matrices/heom_matrix_base.jl")
include("heom_matrices/Nvec.jl")
include("heom_matrices/HierarchyDict.jl")
include("heom_matrices/M_S.jl")
include("heom_matrices/M_Boson.jl")
include("heom_matrices/M_Fermion.jl")
include("heom_matrices/M_Boson_Fermion.jl")

include("evolution.jl")
include("steadystate.jl")
include("power_spectrum.jl")
include("density_of_states.jl")
end
@reexport using .HeomAPI

# intrinsic QuantumToolbox functions
import QuantumToolbox: _FType, _CType, _spre, _spost

# SciML packages (for OrdinaryDiffEq and LinearSolve)
import SciMLBase: init, solve, solve!, u_modified!, ODEProblem, FullSpecialize, CallbackSet
import SciMLOperators: MatrixOperator
import OrdinaryDiffEqCore: OrdinaryDiffEqAlgorithm
import OrdinaryDiffEqLowOrderRK: DP5
import DiffEqCallbacks: PresetTimeCallback, TerminateSteadyState
import LinearSolve: LinearProblem, SciMLLinearSolveAlgorithm, UMFPACKFactorization

# other dependencies (in alphabetical order)
import Base.Threads: @threads, threadid, nthreads, lock, unlock, SpinLock
import FastExpm: fastExpm
import JLD2: jldopen
import Pkg

# Basic functions
include("HeomBase.jl")

# Bath
include("bath/BathBase.jl")
include("bath/BosonBath.jl")
include("bath/FermionBath.jl")
include("bath_correlation_functions/bath_correlation_func.jl")

# Parity and ADOs
include("Parity.jl")
include("ADOs.jl")

# HEOM Liouvillian superoperator (HEOMLS) matrices
include("heom_matrices/heom_matrix_base.jl")
include("heom_matrices/Nvec.jl")
include("heom_matrices/HierarchyDict.jl")
include("heom_matrices/M_S.jl")
include("heom_matrices/M_Boson.jl")
include("heom_matrices/M_Fermion.jl")
include("heom_matrices/M_Boson_Fermion.jl")

# Solvers
include("evolution.jl")
include("steadystate.jl")
include("power_spectrum.jl")
include("density_of_states.jl")

# deprecated functions
include("deprecated.jl")

end
Loading

0 comments on commit 611e498

Please sign in to comment.