From 8ae62ea9e84f5574fe0ca31fd6064a833a9ff048 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Thu, 7 Sep 2023 10:11:57 +0800 Subject: [PATCH 01/15] fix docstring --- src/heom_matrices/heom_matrix_base.jl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/heom_matrices/heom_matrix_base.jl b/src/heom_matrices/heom_matrix_base.jl index 00900ebf..b8170955 100644 --- a/src/heom_matrices/heom_matrix_base.jl +++ b/src/heom_matrices/heom_matrix_base.jl @@ -25,7 +25,7 @@ function show(io::IO, M::AbstractHEOMLSMatrix) end print(io, - type, " type HEOM matrix with (system) dim = $(M.dim) and parity = :$(M.parity)\n", + type, " type HEOMLS matrix with (system) dim = $(M.dim) and parity = :$(M.parity)\n", "number of ADOs N = $(M.N)\n", "data =\n" ) @@ -61,7 +61,7 @@ end @doc raw""" addBosonDissipator(M, jumpOP) -Adding bosonic dissipator to a given HEOM matrix which describes how the system dissipatively interacts with an extra bosonic environment. +Adding bosonic dissipator to a given HEOMLS matrix which describes how the system dissipatively interacts with an extra bosonic environment. The dissipator is defined as follows ```math D[J](\cdot) = J(\cdot) J^\dagger - \frac{1}{2}\left(J^\dagger J (\cdot) + (\cdot) J^\dagger J \right), @@ -102,7 +102,7 @@ end @doc raw""" addFermionDissipator(M, jumpOP) -Adding fermionic dissipator to a given HEOM matrix which describes how the system dissipatively interacts with an extra fermionic environment. +Adding fermionic dissipator to a given HEOMLS matrix which describes how the system dissipatively interacts with an extra fermionic environment. The dissipator with `:even` parity is defined as follows ```math D_{\textrm{even}}[J](\cdot) = J(\cdot) J^\dagger - \frac{1}{2}\left(J^\dagger J (\cdot) + (\cdot) J^\dagger J \right), @@ -114,7 +114,7 @@ Similary, the dissipator with `:odd` parity is defined as follows D_{\textrm{odd}}[J](\cdot) = - J(\cdot) J^\dagger - \frac{1}{2}\left(J^\dagger J (\cdot) + (\cdot) J^\dagger J \right), ``` -Note that the parity of the dissipator will be determined by the parity of the given HEOM matrix `M`. +Note that the parity of the dissipator will be determined by the parity of the given HEOMLS matrix `M`. # Parameters - `M::AbstractHEOMLSMatrix` : the matrix given from HEOM model @@ -151,7 +151,7 @@ function addFermionDissipator(M::AbstractHEOMLSMatrix, jumpOP::AbstractMatrix) r @doc raw""" addTerminator(M, Bath) -Adding terminator to a given HEOM matrix. +Adding terminator to a given HEOMLS matrix. The terminator is a Liouvillian term representing the contribution to the system-bath dynamics of all exponential-expansion terms beyond `Bath.Nterm` @@ -170,15 +170,15 @@ Here, `δ` is the approximation discrepancy and `dirac(t)` denotes the Dirac-del function addTerminator(M::Mtype, Bath::Union{BosonBath, FermionBath}) where Mtype <: AbstractHEOMLSMatrix Btype = typeof(Bath) if (Btype == BosonBath) && (Mtype == M_Fermion) - error("For $(Btype), the type of HEOM matrix should be either M_Boson or M_Boson_Fermion.") + error("For $(Btype), the type of HEOMLS matrix should be either M_Boson or M_Boson_Fermion.") elseif (Btype == FermionBath) && (Mtype == M_Boson) - error("For $(Btype), the type of HEOM matrix should be either M_Fermion or M_Boson_Fermion.") + error("For $(Btype), the type of HEOMLS matrix should be either M_Fermion or M_Boson_Fermion.") elseif Mtype == M_S - error("The type of input HEOM matrix does not support this functionality.") + error("The type of input HEOMLS matrix does not support this functionality.") end if M.dim != Bath.dim - error("The system dimension between the HEOM matrix and Bath are not consistent.") + error("The system dimension between the HEOMLS matrix and Bath are not consistent.") end if Bath.δ == 0 From 1cd2b7b77373d9eb7371c0711dba76e19c5b915c Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Fri, 8 Sep 2023 15:39:09 +0800 Subject: [PATCH 02/15] fix examples --- examples/SIAM.jl | 2 +- examples/cavityQED.jl | 4 ++-- examples/dynamical_decoupling.jl | 2 +- examples/electronic_current.jl | 2 +- examples/quick_start.jl | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/SIAM.jl b/examples/SIAM.jl index 7d0d9b53..fcc967d9 100644 --- a/examples/SIAM.jl +++ b/examples/SIAM.jl @@ -33,7 +33,7 @@ Hsys = ϵ * (d_up' * d_up + d_dn' * d_dn) + U * (d_up' * d_up * d_dn' * d_dn) # We assume the fermionic reservoir to have a [Lorentzian-shaped spectral density](@ref doc-Fermion-Lorentz), and we utilize the Padé decomposition. Furthermore, the spectral densities depend on the following physical parameters: # - the coupling strength $\Gamma$ between system and reservoirs # - the band-width $W$ -# - $kT$ (the product of the Boltzmann constant $k$ and the absolute temperature $T$) +# - the product of the Boltzmann constant $k$ and the absolute temperature $T$ : $kT$ # - the chemical potential $\mu$ # - the total number of exponentials for the reservoir $2(N + 1)$ Γ = 2 diff --git a/examples/cavityQED.jl b/examples/cavityQED.jl index a5d7c9ce..05ed546e 100644 --- a/examples/cavityQED.jl +++ b/examples/cavityQED.jl @@ -63,13 +63,13 @@ H_s = H_A + H_c + H_int ## initial state ket0 = QuantumOptics.tensor(QuantumOptics.Ket(a_basis,[1,0,0]),QuantumOptics.Ket(b_spin,[1,0])) -ρ0 = QuantumOptics.tensor(ket0, ket0'); +ρ0 = QuantumOptics.dm(ket0); # ## Construct bath objects # We assume the bosonic reservoir to have a [Drude-Lorentz Spectral Density](@ref Boson-Drude-Lorentz), and we utilize the Padé decomposition. Furthermore, the spectral densities depend on the following physical parameters: # - the coupling strength $\Gamma$ between system and reservoir # - the band-width $W$ -# - $kT$ (the product of the Boltzmann constant $k$ and the absolute temperature $T$) +# - the product of the Boltzmann constant $k$ and the absolute temperature $T$ : $kT$ # - the total number of exponentials for the reservoir $(N + 1)$ Γ = 0.01 W = 1 diff --git a/examples/dynamical_decoupling.jl b/examples/dynamical_decoupling.jl index f0b2e58a..a30b5f19 100644 --- a/examples/dynamical_decoupling.jl +++ b/examples/dynamical_decoupling.jl @@ -75,7 +75,7 @@ Plots.plot( # We assume the bosonic reservoir to have a [Drude-Lorentz Spectral Density](@ref Boson-Drude-Lorentz), and we utilize the Padé decomposition. Furthermore, the spectral densities depend on the following physical parameters: # - the coupling strength $\Gamma$ between system and reservoir # - the band-width $W$ -# - $kT$ (the product of the Boltzmann constant $k$ and the absolute temperature $T$) +# - the product of the Boltzmann constant $k$ and the absolute temperature $T$ : $kT$ # - the total number of exponentials for the reservoir $(N + 1)$ Γ = 0.0005 W = 0.005 diff --git a/examples/electronic_current.jl b/examples/electronic_current.jl index 09197b18..0c32aba1 100644 --- a/examples/electronic_current.jl +++ b/examples/electronic_current.jl @@ -32,7 +32,7 @@ Hsys = ϵ * d' * d # We assume the fermionic reservoir to have a [Lorentzian-shaped spectral density](@ref doc-Fermion-Lorentz), and we utilize the Padé decomposition. Furthermore, the spectral densities depend on the following physical parameters: # - the coupling strength $\Gamma$ between system and reservoirs # - the band-width $W$ -# - $kT$ (the product of the Boltzmann constant $k$ and the absolute temperature $T$) +# - the product of the Boltzmann constant $k$ and the absolute temperature $T$ : $kT$ # - the chemical potential $\mu$ # - the total number of exponentials for the reservoir $2(N + 1)$ Γ = 0.01 diff --git a/examples/quick_start.jl b/examples/quick_start.jl index cd61ab0c..058f74fe 100644 --- a/examples/quick_start.jl +++ b/examples/quick_start.jl @@ -40,7 +40,7 @@ HierarchicalEOM.versioninfo() # We demonstrate this tutorial by `QuantumOptics`: -import QuantumOptics: SpinBasis, sigmaz, sigmax, ⊗, Ket, Bra +import QuantumOptics: SpinBasis, sigmaz, sigmax, ⊗, Ket, Bra, dm basis = SpinBasis(1//2) @@ -51,13 +51,13 @@ basis = SpinBasis(1//2) Hsys = 0.5 * ϵ * sigmaz(basis) + 0.5 * Δ * sigmax(basis) ## System initial state -ρ0 = Ket(basis, [1, 0]) ⊗ Bra(basis, [1, 0]); +ρ0 = dm(Ket(basis, [1, 0])); # #### Bath Properties # Now, we demonstrate how to describe the bath using the built-in implementation of ``J_D(\omega)`` under Pade expansion by calling [`Boson_DrudeLorentz_Pade`](@ref) λ = 0.1 # coupling strength -W = 0.5 # cut-off frequency +W = 0.5 # band-width (cut-off frequency) kT = 0.5 # the product of the Boltzmann constant k and the absolute temperature T Q = sigmaz(basis) # system-bath coupling operator From e67c2923afa82daa4ebf89613f073f4bedad7b0c Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Mon, 11 Sep 2023 16:47:10 +0800 Subject: [PATCH 03/15] revise the structure of documentation --- docs/make.jl | 12 ++- docs/src/bath_boson/Boson_Drude_Lorentz.md | 53 +++++++++++++ .../bosonic_bath_intro.md} | 79 +++---------------- docs/src/bath_fermion/Fermion_Lorentz.md | 57 +++++++++++++ .../fermionic_bath_intro.md} | 78 +++--------------- .../heom_matrix/{intro.md => HEOMLS_intro.md} | 6 +- 6 files changed, 142 insertions(+), 143 deletions(-) create mode 100644 docs/src/bath_boson/Boson_Drude_Lorentz.md rename docs/src/{bosonic_bath.md => bath_boson/bosonic_bath_intro.md} (68%) create mode 100644 docs/src/bath_fermion/Fermion_Lorentz.md rename docs/src/{fermionic_bath.md => bath_fermion/fermionic_bath_intro.md} (62%) rename docs/src/heom_matrix/{intro.md => HEOMLS_intro.md} (97%) diff --git a/docs/make.jl b/docs/make.jl index b5aaecc7..4fd8eeeb 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -50,11 +50,17 @@ const PAGES = Any[ "Cite HierarchicalEOM" => "cite.md" ], "Manual" => Any[ - "Bosonic Bath" => "bosonic_bath.md", - "Fermionic Bath" => "fermionic_bath.md", + "Bosonic Bath" => Any[ + "Introduction" => "bath_boson/bosonic_bath_intro.md", + "Drude-Lorentz Spectral Density" => "bath_boson/Boson_Drude_Lorentz.md" + ], + "Fermionic Bath" => Any[ + "Introduction" => "bath_fermion/fermionic_bath_intro.md", + "Lorentz Spectral Density" => "bath_fermion/Fermion_Lorentz.md" + ], "Auxiliary Density Operators" => "ADOs.md", "HEOMLS Matrices" => Any[ - "Introduction" => "heom_matrix/intro.md", + "Introduction" => "heom_matrix/HEOMLS_intro.md", "HEOMLS for Schrödinger Equation" => "heom_matrix/schrodinger_eq.md", "HEOMLS for Bosonic Bath" => "heom_matrix/M_Boson.md", "HEOMLS for Fermionic Bath" => "heom_matrix/M_Fermion.md", diff --git a/docs/src/bath_boson/Boson_Drude_Lorentz.md b/docs/src/bath_boson/Boson_Drude_Lorentz.md new file mode 100644 index 00000000..4721dafd --- /dev/null +++ b/docs/src/bath_boson/Boson_Drude_Lorentz.md @@ -0,0 +1,53 @@ +# [Drude-Lorentz Spectral Density](@id Boson-Drude-Lorentz) +```math +J(\omega)=\frac{4\Delta W\omega}{\omega^2+W^2} +``` +Here, ``\Delta`` represents the coupling strength between system and the bosonic environment with band-width ``W``. + +## Matsubara Expansion +With Matsubara Expansion, the correlation function can be analytically solved and expressed as follows: +```math +C(t_1, t_2)=\sum_{l=1}^{\infty} \eta_l \exp(-\gamma_l (t_1-t_2)) +``` +with +```math +\begin{aligned} +\gamma_{1} &= W,\\ +\eta_{1} &= \Delta W\left[-i+\cot\left(\frac{W}{2 k_B T}\right)\right],\\ +\gamma_{l\neq 1} &= 2\pi l k_B T,\\ +\eta_{l\neq 1} &= -2 k_B T \cdot \frac{2\Delta W \cdot \gamma_l}{-\gamma_l^2 + W^2}. +\end{aligned} +``` +This can be constructed by the built-in function [`Boson_DrudeLorentz_Matsubara`](@ref): +```julia +Vs # coupling operator +Δ # coupling strength +W # band-width of the environment +kT # the product of the Boltzmann constant k and the absolute temperature T +N # Number of exponential terms +bath = Boson_DrudeLorentz_Matsubara(Vs, Δ, W, kT, N - 1) +``` + +## Padé Expansion +With Padé Expansion, the correlation function can be analytically solved and expressed as the following exponential terms: +```math +C(t_1, t_2)=\sum_{l=1}^{\infty} \eta_l \exp(-\gamma_l (t_1-t_2)) +``` +with +```math +\begin{aligned} +\gamma_{1} &= W,\\ +\eta_{1} &= \Delta W\left[-i+\cot\left(\frac{W}{2 k_B T}\right)\right],\\ +\gamma_{l\neq 1} &= \zeta_l k_B T,\\ +\eta_{l\neq 1} &= -2 \kappa_l k_B T \cdot \frac{2\Delta W \cdot \zeta_l k_B T}{-(\zeta_l k_B T)^2 + W^2}, +\end{aligned} +``` +where the parameters ``\kappa_l`` and ``\zeta_l`` are described in [J. Chem. Phys. 134, 244106 (2011)](https://doi.org/10.1063/1.3602466). This can be constructed by the built-in function [`Boson_DrudeLorentz_Pade`](@ref): +```julia +Vs # coupling operator +Δ # coupling strength +W # band-width of the environment +kT # the product of the Boltzmann constant k and the absolute temperature T +N # Number of exponential terms +bath = Boson_DrudeLorentz_Pade(Vs, Δ, W, kT, N - 1) +``` \ No newline at end of file diff --git a/docs/src/bosonic_bath.md b/docs/src/bath_boson/bosonic_bath_intro.md similarity index 68% rename from docs/src/bosonic_bath.md rename to docs/src/bath_boson/bosonic_bath_intro.md index 582fb8c4..13571498 100644 --- a/docs/src/bosonic_bath.md +++ b/docs/src/bath_boson/bosonic_bath_intro.md @@ -1,5 +1,5 @@ # [Bosonic Bath](@id doc-Bosonic-Bath) -## [Introduction](@id Bosonic-Bath-Introduction) +## [Overview](@id Bosonic-Bath-Overview) The [`BosonBath`](@ref) object describes the interaction between the system (``s``) and a exterior bosonic environment (``b``), which can be modeled by ```math H_{sb}=V_{s}\sum_k g_k (b_k + b_k^\dagger), @@ -19,9 +19,7 @@ C(t_1, t_2)=\sum_i \eta_i e^{-\gamma_i (t_1-t_2)}. ``` This allows us to define an iterative procedure which leads to the hierarchical equations of motion (HEOM). -## Methods - -### Construct BosonBath (with real and imaginary parts are combined) +## Construct BosonBath (with real and imaginary parts are combined) One can construct the [`BosonBath`](@ref) object with the coupling operator `Vs::AbstractMatrix` and the two lists `η::AbstractVector` and `γ::AbstractVector` which corresponds to the exponential terms ``\{\eta_i\}_i`` and ``\{\gamma_i\}_i``, respectively. ```julia bath = BosonBath(Vs, η, γ) @@ -29,7 +27,7 @@ bath = BosonBath(Vs, η, γ) !!! warning "Warning" Here, the length of `η` and `γ` should be the same. -### Construct BosonBath (with real and imaginary parts are separated) +## Construct BosonBath (with real and imaginary parts are separated) When ``\gamma_i \neq \gamma_i^*``, a closed form for the HEOM can be obtained by further decomposing ``C(t_1, t_2)`` into its real (R) and imaginary (I) parts as ```math C(t_1, t_2)=\sum_{u=\textrm{R},\textrm{I}}(\delta_{u, \textrm{R}} + i\delta_{u, \textrm{I}})C^{u}(t_1, t_2) @@ -48,7 +46,7 @@ Here, `η_real::AbstractVector`, `γ_real::AbstractVector`, `η_imag::AbstractVe !!! note "Note" Instead of analytically solving the correlation function ``C(t_1, t_2)`` to obtain a sum of exponential terms, one can also use the built-in functions (for different spectral densities ``J(\omega)`` and spectral decomposition methods, which have been analytically solved by the developers already) listed in the end of this page. -### Print Bosonic Bath +## Print Bosonic Bath One can check the information of the [`BosonBath`](@ref) by the `print` function, for example: ```julia print(bath) @@ -57,14 +55,14 @@ print(bath) BosonBath object with (system) dim = 2 and 4 exponential-expansion terms ``` -### Calculate the correlation function +## Calculate the correlation function To check whether the exponential terms in the [`BosonBath`](@ref) is correct or not, one can call [`C(bath::BosonBath, tlist::AbstractVector)`](@ref) to calculate the correlation function ``C(t)``, where ``t=t_1-t_2``: ```julia c_list = C(bath, tlist) ``` Here, `c_list` is a list which contains the value of ``C(t)`` corresponds to the given time series `tlist`. -### Methods for Exponent +## Exponent `HierarchicalEOM.jl` also supports users to access the specific exponential term with brakets `[]`. This returns an [`Exponent`](@ref) object, which contains the corresponding value of ``\eta_i`` and ``\gamma_i``: ```julia e = bath[2] # the 2nd-term @@ -74,6 +72,11 @@ print(e) Bath Exponent with types = "bRI", operator size = (2, 2), η = 1.5922874021206546e-6 + 0.0im, γ = 0.3141645167860635 + 0.0im. ``` +The different types of the (bosonic-bath) [`Exponent`](@ref): + - `"bR"` : from real part of bosonic correlation function ``C^{u=\textrm{R}}(t_1, t_2)`` + - `"bI"` : from imaginary part of bosonic correlation function ``C^{u=\textrm{I}}(t_1, t_2)`` + - `"bRI"` : from combined (real and imaginary part) bosonic bath correlation function ``C(t_1, t_2)`` + One can even obtain the [`Exponent`](@ref) with iterative method: ```julia for e in bath @@ -88,64 +91,4 @@ Bath Exponent with types = "bRI", operator size = (2, 2), η = 1.592287402120654 Bath Exponent with types = "bRI", operator size = (2, 2), η = 1.0039844180003819e-6 + 0.0im, γ = 0.6479143347831898 + 0.0im. Bath Exponent with types = "bRI", operator size = (2, 2), η = 3.1005439801387293e-6 + 0.0im, γ = 1.8059644711829272 + 0.0im. -``` - -### Types of Exponent -The different types of the (bosonic-bath) [`Exponent`](@ref): - - `"bR"` : from real part of bosonic correlation function ``C^{u=\textrm{R}}(t_1, t_2)`` - - `"bI"` : from imaginary part of bosonic correlation function ``C^{u=\textrm{I}}(t_1, t_2)`` - - `"bRI"` : from combined (real and imaginary part) bosonic bath correlation function ``C(t_1, t_2)`` - -## [Drude-Lorentz Spectral Density](@id Boson-Drude-Lorentz) -```math -J(\omega)=\frac{4\Delta W\omega}{\omega^2+W^2} -``` -Here, ``\Delta`` represents the coupling strength between system and the bosonic environment with band-width ``W``. - -### Matsubara Expansion -With Matsubara Expansion, the correlation function can be analytically solved and expressed as follows: -```math -C(t_1, t_2)=\sum_{l=1}^{\infty} \eta_l \exp(-\gamma_l (t_1-t_2)) -``` -with -```math -\begin{aligned} -\gamma_{1} &= W,\\ -\eta_{1} &= \Delta W\left[-i+\cot\left(\frac{W}{2 k_B T}\right)\right],\\ -\gamma_{l\neq 1} &= 2\pi l k_B T,\\ -\eta_{l\neq 1} &= -2 k_B T \cdot \frac{2\Delta W \cdot \gamma_l}{-\gamma_l^2 + W^2}. -\end{aligned} -``` -This can be constructed by the built-in function [`Boson_DrudeLorentz_Matsubara`](@ref): -```julia -Vs # coupling operator -Δ # coupling strength -W # band-width of the environment -kT # the product of the Boltzmann constant k and the absolute temperature T -N # Number of exponential terms -bath = Boson_DrudeLorentz_Matsubara(Vs, Δ, W, kT, N - 1) -``` - -### Padé Expansion -With Padé Expansion, the correlation function can be analytically solved and expressed as the following exponential terms: -```math -C(t_1, t_2)=\sum_{l=1}^{\infty} \eta_l \exp(-\gamma_l (t_1-t_2)) -``` -with -```math -\begin{aligned} -\gamma_{1} &= W,\\ -\eta_{1} &= \Delta W\left[-i+\cot\left(\frac{W}{2 k_B T}\right)\right],\\ -\gamma_{l\neq 1} &= \zeta_l k_B T,\\ -\eta_{l\neq 1} &= -2 \kappa_l k_B T \cdot \frac{2\Delta W \cdot \zeta_l k_B T}{-(\zeta_l k_B T)^2 + W^2}, -\end{aligned} -``` -where the parameters ``\kappa_l`` and ``\zeta_l`` are described in [J. Chem. Phys. 134, 244106 (2011)](https://doi.org/10.1063/1.3602466). This can be constructed by the built-in function [`Boson_DrudeLorentz_Pade`](@ref): -```julia -Vs # coupling operator -Δ # coupling strength -W # band-width of the environment -kT # the product of the Boltzmann constant k and the absolute temperature T -N # Number of exponential terms -bath = Boson_DrudeLorentz_Pade(Vs, Δ, W, kT, N - 1) ``` \ No newline at end of file diff --git a/docs/src/bath_fermion/Fermion_Lorentz.md b/docs/src/bath_fermion/Fermion_Lorentz.md new file mode 100644 index 00000000..cb343626 --- /dev/null +++ b/docs/src/bath_fermion/Fermion_Lorentz.md @@ -0,0 +1,57 @@ +# [Lorentz Spectral Density](@id doc-Fermion-Lorentz) +```math +J(\omega)=\frac{\Gamma W^2}{(\omega-\mu)^2+W^2} +``` +Here, ``\Gamma`` represents the coupling strength between system and the fermionic environment with chemical potential ``\mu`` and band-width ``W``. + +## Matsubara Expansion +With Matsubara Expansion, the correlation function can be analytically solved and expressed as follows: +```math +C^{\nu}(t_1, t_2)=\sum_{l=1}^{\infty} \eta_l^\nu \exp(-\gamma_l^\nu (t_1-t_2)) +``` +with +```math +\begin{aligned} +\gamma_{1}^{\nu} &= W-\nu i \mu,\\ +\eta_{1}^{\nu} &= \frac{\Gamma W}{2} f\left(\frac{iW}{k_B T}\right),\\ +\gamma_{l\neq 1}^{\nu} &= \zeta_l k_B T - \nu i \mu,\\ +\eta_{l\neq 1}^{\nu} &= -i k_B T \cdot \frac{\Gamma W^2}{-(\zeta_l k_B T)^2+W^2},\\ +f(x) &= \{\exp(x) + 1\}^{-1}, +\end{aligned} +``` +where ``\zeta_l=(2 l - 1)\pi``. This can be constructed by the built-in function [`Fermion_Lorentz_Matsubara`](@ref): +```julia +ds # coupling operator +Γ # coupling strength +μ # chemical potential of the environment +W # band-width of the environment +kT # the product of the Boltzmann constant k and the absolute temperature T +N # Number of exponential terms for each correlation functions (C^{+} and C^{-}) +bath = Fermion_Lorentz_Matsubara(ds, Γ, μ, W, kT, N - 1) +``` + +## Padé Expansion +With Padé Expansion, the correlation function can be analytically solved and expressed as the following exponential terms: +```math +C^\nu(t_1, t_2)=\sum_{l=1}^{\infty} \eta_l^\nu \exp(-\gamma_l^\nu (t_1-t_2)) +``` +with +```math +\begin{aligned} +\gamma_{1}^{\nu} &= W-\nu i \mu,\\ +\eta_{1}^{\nu} &= \frac{\Gamma W}{2} f\left(\frac{iW}{k_B T}\right),\\ +\gamma_{l\neq 1}^{\nu} &= \zeta_l k_B T - \nu i \mu,\\ +\eta_{l\neq 1}^{\nu} &= -i \kappa_l k_B T \cdot \frac{\Gamma W^2}{-(\zeta_l k_B T)^2+W^2},\\ +f(x) &= \frac{1}{2}-\sum_{l=2}^{N} \frac{2\kappa_l x}{x^2+\zeta_l^2}, +\end{aligned} +``` +where the parameters ``\kappa_l`` and ``\zeta_l`` are described in [J. Chem. Phys. 134, 244106 (2011)](https://doi.org/10.1063/1.3602466) and ``N`` represents the number of exponential terms for ``C^{\nu=\pm}``. This can be constructed by the built-in function [`Fermion_Lorentz_Pade`](@ref): +```julia +ds # coupling operator +Γ # coupling strength +μ # chemical potential of the environment +W # band-width of the environment +kT # the product of the Boltzmann constant k and the absolute temperature T +N # Number of exponential terms for each correlation functions (C^{+} and C^{-}) +bath = Fermion_Lorentz_Pade(ds, Γ, μ, W, kT, N - 1) +``` \ No newline at end of file diff --git a/docs/src/fermionic_bath.md b/docs/src/bath_fermion/fermionic_bath_intro.md similarity index 62% rename from docs/src/fermionic_bath.md rename to docs/src/bath_fermion/fermionic_bath_intro.md index d6a88f53..aa851a41 100644 --- a/docs/src/fermionic_bath.md +++ b/docs/src/bath_fermion/fermionic_bath_intro.md @@ -1,6 +1,6 @@ # [Fermionic Bath](@id doc-Fermionic-Bath) -## [Introduction](@id Fermionic-Bath-Introduction) +## [Overview](@id Fermionic-Bath-Overview) The [`FermionBath`](@ref) object describes the interaction between the system (``s``) and a exterior fermionic environment (``f``), which can be modeled by ```math H_{sf}=\sum_k g_k c_k^\dagger d_s + g_k^* c_k d_s^\dagger, @@ -22,8 +22,7 @@ C^{\nu}(t_1, t_2)=\sum_i \eta_i^{\nu} e^{-\gamma_i^{\nu} (t_1-t_2)}. ``` This allows us to define an iterative procedure which leads to the hierarchical equations of motion (HEOM). -## Methods -### Construct FermionBath +## Construct FermionBath One can construct the [`FermionBath`](@ref) object with the coupling operator `ds::AbstractMatrix` and the four lists `η_absorb::AbstractVector`, `γ_absorb::AbstractVector`, `η_emit::AbstractVector` and `γ_emit::AbstractVector` which correspond to the exponential terms ``\{\eta_i^{+}\}_i``, ``\{\gamma_i^{+}\}_i``, ``\{\eta_i^{-}\}_i`` and ``\{\gamma_i^{-}\}_i``, respectively. ```julia bath = FermionBath(ds, η_absorb, γ_absorb, η_emit, γ_emit) @@ -34,7 +33,7 @@ bath = FermionBath(ds, η_absorb, γ_absorb, η_emit, γ_emit) !!! note "Note" Instead of analytically solving the correlation function ``C^{\nu=\pm}(t_1, t_2)`` to obtain a sum of exponential terms, one can also use the built-in functions (for different spectral densities ``J(\omega)`` and spectral decomposition methods, which have been analytically solved by the developers already) listed in the end of this page. -### Print Fermionic Bath +## Print Fermionic Bath One can check the information of the [`FermionBath`](@ref) by the `print` function, for example: ```julia print(bath) @@ -44,14 +43,14 @@ FermionBath object with (system) dim = 2 and 4 exponential-expansion terms ``` Note that [`FermionBath`](@ref) always have even number of exponential terms (half for ``C^{\nu=+}`` and half for ``C^{\nu=-}``) -### Calculate the correlation function +## Calculate the correlation function To check whether the exponential terms in the [`FermionBath`](@ref) is correct or not, one can call [`C(bath::FermionBath, tlist::AbstractVector)`](@ref) to calculate the correlation function ``C(t)``, where ``t=t_1-t_2``: ```julia cp_list, cm_list = C(bath, tlist) ``` Here, `cp_list` and `cm_list` are the lists which contain the value of ``C^{\nu=+}(t)`` and ``C^{\nu=-}(t)`` correspond to the given time series `tlist`, respectively. -### Methods for Exponent +## Exponent `HierarchicalEOM.jl` also supports users to access the specific exponential term with brakets `[]`. This returns an [`Exponent`](@ref) object, which contains the corresponding value of ``\eta_i^\nu`` and ``\gamma_i^\nu``: ```julia e = bath[2] # the 2nd-term @@ -61,6 +60,10 @@ print(e) Bath Exponent with types = "fA", operator size = (2, 2), η = 0.0 + 3.4090909090909113e-6im, γ = 0.1732050807568877 - 0.005im. ``` +The different types of the (fermionic-bath) [`Exponent`](@ref): + - `"fA"` : from absorption fermionic correlation function ``C^{\nu=+}(t_1, t_2)`` + - `"fE"` : from emission fermionic correlation function ``C^{\nu=-}(t_1, t_2)`` + One can even obtain the [`Exponent`](@ref) with iterative method: ```julia for e in bath @@ -75,67 +78,4 @@ Bath Exponent with types = "fA", operator size = (2, 2), η = 0.0 + 3.4090909090 Bath Exponent with types = "fE", operator size = (2, 2), η = 6.25e-6 - 3.4090909090909113e-6im, γ = 0.05 + 0.005im. Bath Exponent with types = "fE", operator size = (2, 2), η = 0.0 + 3.4090909090909113e-6im, γ = 0.1732050807568877 + 0.005im. -``` - -### Types of Exponent -The different types of the (fermionic-bath) [`Exponent`](@ref): - - `"fA"` : from absorption fermionic correlation function ``C^{\nu=+}(t_1, t_2)`` - - `"fE"` : from emission fermionic correlation function ``C^{\nu=-}(t_1, t_2)`` - -## [Lorentz Spectral Density](@id doc-Fermion-Lorentz) -```math -J(\omega)=\frac{\Gamma W^2}{(\omega-\mu)^2+W^2} -``` -Here, ``\Gamma`` represents the coupling strength between system and the fermionic environment with chemical potential ``\mu`` and band-width ``W``. - -### Matsubara Expansion -With Matsubara Expansion, the correlation function can be analytically solved and expressed as follows: -```math -C^{\nu}(t_1, t_2)=\sum_{l=1}^{\infty} \eta_l^\nu \exp(-\gamma_l^\nu (t_1-t_2)) -``` -with -```math -\begin{aligned} -\gamma_{1}^{\nu} &= W-\nu i \mu,\\ -\eta_{1}^{\nu} &= \frac{\Gamma W}{2} f\left(\frac{iW}{k_B T}\right),\\ -\gamma_{l\neq 1}^{\nu} &= \zeta_l k_B T - \nu i \mu,\\ -\eta_{l\neq 1}^{\nu} &= -i k_B T \cdot \frac{\Gamma W^2}{-(\zeta_l k_B T)^2+W^2},\\ -f(x) &= \{\exp(x) + 1\}^{-1}, -\end{aligned} -``` -where ``\zeta_l=(2 l - 1)\pi``. This can be constructed by the built-in function [`Fermion_Lorentz_Matsubara`](@ref): -```julia -ds # coupling operator -Γ # coupling strength -μ # chemical potential of the environment -W # band-width of the environment -kT # the product of the Boltzmann constant k and the absolute temperature T -N # Number of exponential terms for each correlation functions (C^{+} and C^{-}) -bath = Fermion_Lorentz_Matsubara(ds, Γ, μ, W, kT, N - 1) -``` - -### Padé Expansion -With Padé Expansion, the correlation function can be analytically solved and expressed as the following exponential terms: -```math -C^\nu(t_1, t_2)=\sum_{l=1}^{\infty} \eta_l^\nu \exp(-\gamma_l^\nu (t_1-t_2)) -``` -with -```math -\begin{aligned} -\gamma_{1}^{\nu} &= W-\nu i \mu,\\ -\eta_{1}^{\nu} &= \frac{\Gamma W}{2} f\left(\frac{iW}{k_B T}\right),\\ -\gamma_{l\neq 1}^{\nu} &= \zeta_l k_B T - \nu i \mu,\\ -\eta_{l\neq 1}^{\nu} &= -i \kappa_l k_B T \cdot \frac{\Gamma W^2}{-(\zeta_l k_B T)^2+W^2},\\ -f(x) &= \frac{1}{2}-\sum_{l=2}^{N} \frac{2\kappa_l x}{x^2+\zeta_l^2}, -\end{aligned} -``` -where the parameters ``\kappa_l`` and ``\zeta_l`` are described in [J. Chem. Phys. 134, 244106 (2011)](https://doi.org/10.1063/1.3602466) and ``N`` represents the number of exponential terms for ``C^{\nu=\pm}``. This can be constructed by the built-in function [`Fermion_Lorentz_Pade`](@ref): -```julia -ds # coupling operator -Γ # coupling strength -μ # chemical potential of the environment -W # band-width of the environment -kT # the product of the Boltzmann constant k and the absolute temperature T -N # Number of exponential terms for each correlation functions (C^{+} and C^{-}) -bath = Fermion_Lorentz_Pade(ds, Γ, μ, W, kT, N - 1) ``` \ No newline at end of file diff --git a/docs/src/heom_matrix/intro.md b/docs/src/heom_matrix/HEOMLS_intro.md similarity index 97% rename from docs/src/heom_matrix/intro.md rename to docs/src/heom_matrix/HEOMLS_intro.md index 78bc5bc6..e17a4c03 100644 --- a/docs/src/heom_matrix/intro.md +++ b/docs/src/heom_matrix/HEOMLS_intro.md @@ -29,7 +29,7 @@ M = M_Fermion(Hs, Ftier, Fbath) M = M_Boson_Fermion(Hs, Btier, Ftier, Bbath, Fbath) ``` -# [Importance Value and Threshold](@id doc-Importance-Value-and-Threshold) +## [Importance Value and Threshold](@id doc-Importance-Value-and-Threshold) The main computational complexity can be quantified by the total number of [auxiliary density operators (ADOs)](@ref doc-ADOs) because it directly affects the size of ``\hat{\mathcal{M}}``. The computational effort can be further optimized by associating an **importance value** ``\mathcal{I}`` to each ADO and then discarding all the ADOs (in the second and higher levels) whose importance value is smaller than a threshold value ``\mathcal{I}_\textrm{th}``. The importance value for a given ADO : ``\mathcal{I}\left(\rho^{(m,n,p)}_{\textbf{j} \vert \textbf{q}}\right)`` is determined by its corresponding exponential terms of bath correlation function [see [Phys. Rev. B 88, 235426 (2013)](https://doi.org/10.1103/PhysRevB.88.235426) and [Phys. Rev. B 103, 235413 (2021)](https://doi.org/10.1103/PhysRevB.103.235413)]. This allows us to only consider the ADOs which affects the dynamics more, and thus, reduce the size of ``\hat{\mathcal{M}}``. Also see our paper for more details. @@ -49,7 +49,7 @@ M = M_Boson_Fermion(Hs, Btier, Ftier, Bbath, Fbath; threshold=1e-7) !!! note "Default value of importance threshold" The full hierarchical equations can be recovered in the limiting case ``\mathcal{I}_\textrm{th}\rightarrow 0``, which is the default value of the parameter : `threshold=0.0`. This means that all of the ADOs will be taken into account by default. -# [Parity Support for HEOMLS Matrices](@id doc-Parity) +## [Parity Support for HEOMLS Matrices](@id doc-Parity) When the system Hamiltonian contains fermionic systems, the HEOMLS matrix ``\hat{\mathcal{M}}`` might be constructed into a different one depend on the parity of the input operator (HEOMLS) it is acting on. Usually, it is acting on the reduced density operator and [auxiliary density operators (ADOs)](@ref doc-ADOs), which are all in `:even`-parity. However, there are some situations (for example, [calculating spectrum for fermionic systems](@ref doc-DOS)) where ``\hat{\mathcal{M}}`` is acting on ADOs with `:odd`-parity. One can specify the parameter `parity::Symbol` in the function of constructing ``\hat{\mathcal{M}}`` to be `:even` or `:odd`. The default value of the parameter is `parity=:even`. @@ -74,7 +74,7 @@ M_even = M_Boson_Fermion(Hs, Btier, Ftier, Bbath, Fbath, :even) M_odd = M_Boson_Fermion(Hs, Btier, Ftier, Bbath, Fbath, :odd) ``` -# Methods +## Methods All of the HEOMLS matrices supports the following two `Base` Functions : - `size(M::AbstractHEOMLSMatrix)` : Returns the size of the HEOMLS matrix. - Bracket operator `[i,j]` : Returns the `(i, j)`-element(s) in the HEOMLS matrix. From 2b568ecb71ead5f85b95923e235d1239b4e7d225 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Fri, 15 Sep 2023 16:50:31 +0800 Subject: [PATCH 04/15] Handle unsupported matrix type error --- src/ADOs.jl | 12 +++----- src/Bath.jl | 22 ++++++--------- src/HeomBase.jl | 38 +++++++++++-------------- src/HierarchicalEOM.jl | 6 ++-- src/Spectrum.jl | 15 ++++------ src/SteadyState.jl | 6 ++-- src/evolution.jl | 40 ++++++++++----------------- src/heom_matrices/M_Boson.jl | 8 ++---- src/heom_matrices/M_Boson_Fermion.jl | 8 ++---- src/heom_matrices/M_Fermion.jl | 10 +++---- src/heom_matrices/M_S.jl | 8 ++---- src/heom_matrices/heom_matrix_base.jl | 14 +++------- test/bath.jl | 4 +-- test/heom_api.jl | 14 +++++----- test/phys_analysis.jl | 16 +++++------ 15 files changed, 88 insertions(+), 133 deletions(-) diff --git a/src/ADOs.jl b/src/ADOs.jl index 9bb8c49f..f3f20e41 100644 --- a/src/ADOs.jl +++ b/src/ADOs.jl @@ -156,11 +156,9 @@ where ``O`` is the operator and ``\rho`` is the reduced density operator in the """ function Expect(op, ados::ADOs; take_real=true) - if !isValidMatrixType(op, ados.dim) - error("The dimension of `op` is not consistent with `ados`.") - end + _op = HandleMatrixType(op, ados.dim, "op (observable)") - exp_val = tr(op * getRho(ados)) + exp_val = tr(_op * getRho(ados)) if take_real return real(exp_val) @@ -194,13 +192,11 @@ function Expect(op, ados_list::Vector{ADOs}; take_real=true) end end - if !isValidMatrixType(op, dim) - error("The dimension of `op` is not consistent with the elements in `ados_list`.") - end + _op = HandleMatrixType(op, dim, "op (observable)") ρlist = getRho.(ados_list) exp_val = [ - tr(op * ρlist[i]) for i in 1:length(ρlist) + tr(_op * ρlist[i]) for i in 1:length(ρlist) ] if take_real diff --git a/src/Bath.jl b/src/Bath.jl index b7bdf68a..372ed335 100644 --- a/src/Bath.jl +++ b/src/Bath.jl @@ -142,24 +142,18 @@ end isclose(a::Number, b::Number, rtol=1e-05, atol=1e-08) = abs(a - b) <= (atol + rtol * abs(b)) function _check_bosonic_coupling_operator(op) - if isValidMatrixType(op) - N, = size(op) - if !ishermitian(op) - @warn "The system-bosonic-bath coupling operator \"op\" should be Hermitian operator." - end - return N - else - error("Invalid matrix \"op\".") + _op = HandleMatrixType(op) + N, = size(_op) + if !ishermitian(_op) + @warn "The system-bosonic-bath coupling operator \"op\" should be Hermitian operator." end + return N end function _check_fermionic_coupling_operator(op) - if isValidMatrixType(op) - N, = size(op) - return N - else - error("Invalid matrix \"op\".") - end + _op = HandleMatrixType(op) + N, = size(_op) + return N end function _combine_same_gamma(η::Vector{Ti}, γ::Vector{Tj}) where {Ti, Tj <: Number} diff --git a/src/HeomBase.jl b/src/HeomBase.jl index d726b670..1a341f0f 100644 --- a/src/HeomBase.jl +++ b/src/HeomBase.jl @@ -1,29 +1,23 @@ const PROGBAR_OPTIONS = Dict(:barlen=>20, :color=>:green, :showspeed=>true) -function isValidMatrixType(M, dim::Int=0) - if typeof(M) <: AbstractMatrix - if dim > 0 - if size(M) == (dim, dim) - return true - else - @warn "The size of input matrix should be: ($(dim), $(dim))." - return false - end - elseif dim == 0 - N1, N2 = size(M) - if N1 == N2 - return true - else - @warn "The size of input matrix should be squared matrix." - return false - end +function HandleMatrixType(M, dim::Int=0, MatrixName::String="") + error("HierarchicalEOM doesn't support matrix $(MatrixName) with type : $(typeof(M))") +end + +function HandleMatrixType(M::AbstractMatrix, dim::Int=0, MatrixName::String="") + if dim > 0 + if size(M) == (dim, dim) + return copy(M) else - error("The \"dim\" is not correct.") + error("The size of matrix $(MatrixName) should be: ($(dim), $(dim)).") + end + elseif dim == 0 + N1, N2 = size(M) + if N1 == N2 + return copy(M) + else + error("The size of matrix $(MatrixName) should be squared matrix.") end - - else - @warn "HEOM doesn't support matrix type : $(typeof(M))" - return false end end diff --git a/src/HierarchicalEOM.jl b/src/HierarchicalEOM.jl index 681b2bf4..35fb9cc8 100644 --- a/src/HierarchicalEOM.jl +++ b/src/HierarchicalEOM.jl @@ -20,7 +20,7 @@ module HierarchicalEOM import Base: show, length, getindex, lastindex, iterate, checkbounds import LinearAlgebra: I, kron, ishermitian import SparseArrays: sparse, SparseMatrixCSC - import ..HeomBase: isValidMatrixType + import ..HeomBase: HandleMatrixType export AbstractBath, BosonBath, FermionBath, Exponent, C, @@ -54,7 +54,7 @@ module HierarchicalEOM import SparseArrays: sparse, spzeros, sparsevec, reshape, SparseVector, SparseMatrixCSC, AbstractSparseMatrix import ProgressMeter: Progress, next! import FastExpm: fastExpm - import ..HeomBase: PROGBAR_OPTIONS, isValidMatrixType + import ..HeomBase: PROGBAR_OPTIONS, HandleMatrixType # for solving time evolution import SciMLOperators: MatrixOperator @@ -85,7 +85,7 @@ module HierarchicalEOM import SparseArrays: sparse, sparsevec import LinearSolve: LinearProblem, init, solve!, UMFPACKFactorization import ProgressMeter: Progress, next! - import ..HeomBase: PROGBAR_OPTIONS, isValidMatrixType + import ..HeomBase: PROGBAR_OPTIONS, HandleMatrixType export spectrum diff --git a/src/Spectrum.jl b/src/Spectrum.jl index 6f231e3d..c8b066f4 100644 --- a/src/Spectrum.jl +++ b/src/Spectrum.jl @@ -60,28 +60,25 @@ function spectrum( ados_vec = ρ.data - elseif isValidMatrixType(ρ, M.dim) - v = sparsevec(ρ) - ados_vec = sparsevec(v.nzind, v.nzval, Size) else - error("Invalid matrix \"ρ\".") + _ρ = HandleMatrixType(ρ, M.dim, "ρ (state)") + v = sparsevec(_ρ) + ados_vec = sparsevec(v.nzind, v.nzval, Size) end # check dimension of op - if !isValidMatrixType(op, M.dim) - error("Invalid matrix \"op\".") - end + _op = HandleMatrixType(op, M.dim, "op (operator)") # check parity and calculate spectrum if (M.parity == :odd) - return _density_of_states(M, ados_vec, op, ω_list; + return _density_of_states(M, ados_vec, _op, ω_list; solver = solver, verbose = verbose, filename = filename, SOLVEROptions... ) else - return _power_spectrum(M, ados_vec, op, ω_list; + return _power_spectrum(M, ados_vec, _op, ω_list; solver = solver, verbose = verbose, filename = filename, diff --git a/src/SteadyState.jl b/src/SteadyState.jl index 10cdce64..7c727a00 100644 --- a/src/SteadyState.jl +++ b/src/SteadyState.jl @@ -76,12 +76,10 @@ function SteadyState( SOLVEROptions... ) - if !isValidMatrixType(ρ0, M.dim) - error("Invalid matrix \"ρ0\".") - end + _ρ0 = HandleMatrixType(ρ0, M.dim, "ρ0 (initial state)") # vectorize initial state - ρ1 = sparse(sparsevec(ρ0)) + ρ1 = sparse(sparsevec(_ρ0)) ados = ADOs(sparsevec(ρ1.nzind, ρ1.nzval, M.N * M.sup_dim), M.N, M.parity) return SteadyState(M, ados; diff --git a/src/evolution.jl b/src/evolution.jl index 13ca8f61..3a989963 100644 --- a/src/evolution.jl +++ b/src/evolution.jl @@ -31,12 +31,10 @@ function evolution( filename::String = "" ) - if !isValidMatrixType(ρ0, M.dim) - error("Invalid matrix \"ρ0\".") - end + _ρ0 = HandleMatrixType(ρ0, M.dim, "ρ0 (initial state)") # vectorize initial state - ρ1 = sparse(sparsevec(ρ0)) + ρ1 = sparse(sparsevec(_ρ0)) ados = ADOs(sparsevec(ρ1.nzind, ρ1.nzval, M.N * M.sup_dim), M.N, M.parity) return evolution(M, ados, Δt, steps; @@ -186,12 +184,10 @@ function evolution( SOLVEROptions... ) - if !isValidMatrixType(ρ0, M.dim) - error("Invalid matrix \"ρ0\".") - end + _ρ0 = HandleMatrixType(ρ0, M.dim, "ρ0 (initial state)") # vectorize initial state - ρ1 = sparse(sparsevec(ρ0)) + ρ1 = sparse(sparsevec(_ρ0)) ados = ADOs(sparsevec(ρ1.nzind, ρ1.nzval, M.N * M.sup_dim), M.N, M.parity) return evolution(M, ados, tlist; @@ -358,12 +354,10 @@ function evolution( SOLVEROptions... ) - if !isValidMatrixType(ρ0, M.dim) - error("Invalid matrix \"ρ0\".") - end + _ρ0 = HandleMatrixType(ρ0, M.dim, "ρ0 (initial state)") # vectorize initial state - ρ1 = sparse(sparsevec(ρ0)) + ρ1 = sparse(sparsevec(_ρ0)) ados = ADOs(sparsevec(ρ1.nzind, ρ1.nzval, M.N * M.sup_dim), M.N, M.parity) return evolution(M, ados, tlist, H, param; @@ -445,12 +439,10 @@ For more details about solvers and extra options, please refer to [`Differential end end - Ht = H(param, tlist[1]) - if !isValidMatrixType(Ht, M.dim) - error("The dimension of `H` at t=$(tlist[1]) is not consistent with `M.dim`.") - end - Lt = kron(sparse(I, M.N, M.N), - 1im * (spre(Ht) - spost(Ht))) - L = MatrixOperator(M.data + Lt, update_func! = _update_L!) + Ht = H(param, tlist[1]) + _Ht = HandleMatrixType(Ht, M.dim, "H (Hamiltonian) at t=$(tlist[1])") + Lt = kron(sparse(I, M.N, M.N), - 1im * (spre(_Ht) - spost(_Ht))) + L = MatrixOperator(M.data + Lt, update_func! = _update_L!) # problem: dρ/dt = L(t) * ρ(0) ## M.dim will check whether the returned time-dependent Hamiltonian has the correct dimension @@ -505,12 +497,10 @@ function _update_L!(L, u, p, t) M, H, param = p # check system dimension of Hamiltonian - Ht = H(param, t) - if isValidMatrixType(Ht, M.dim) - # update the block diagonal terms of L - L .= M.data - kron(sparse(I, M.N, M.N), 1im * (spre(Ht) - spost(Ht))) - else - error("The dimension of `H` at t=$(t) is not consistent with `M.dim`.") - end + Ht = H(param, t) + _Ht = HandleMatrixType(Ht, M.dim, "H (Hamiltonian) at t=$(t)") + + # update the block diagonal terms of L + L .= M.data - kron(sparse(I, M.N, M.N), 1im * (spre(_Ht) - spost(_Ht))) nothing end \ No newline at end of file diff --git a/src/heom_matrices/M_Boson.jl b/src/heom_matrices/M_Boson.jl index 54e17adf..fd699fe4 100644 --- a/src/heom_matrices/M_Boson.jl +++ b/src/heom_matrices/M_Boson.jl @@ -58,15 +58,13 @@ Note that the parity only need to be set as `:odd` when the system contains ferm end # check for system dimension - if !isValidMatrixType(Hsys) - error("Invalid matrix \"Hsys\" (system Hamiltonian).") - end - Nsys, = size(Hsys) + _Hsys = HandleMatrixType(Hsys, 0, "Hsys (system Hamiltonian)") + Nsys, = size(_Hsys) sup_dim = Nsys ^ 2 I_sup = sparse(I, sup_dim, sup_dim) # the Liouvillian operator for free Hamiltonian term - Lsys = -1im * (spre(Hsys) - spost(Hsys)) + Lsys = -1im * (spre(_Hsys) - spost(_Hsys)) # bosonic bath if verbose && (threshold > 0.0) diff --git a/src/heom_matrices/M_Boson_Fermion.jl b/src/heom_matrices/M_Boson_Fermion.jl index a8677628..e54621bd 100644 --- a/src/heom_matrices/M_Boson_Fermion.jl +++ b/src/heom_matrices/M_Boson_Fermion.jl @@ -75,15 +75,13 @@ Note that the parity only need to be set as `:odd` when the system contains ferm end # check for system dimension - if !isValidMatrixType(Hsys) - error("Invalid matrix \"Hsys\" (system Hamiltonian).") - end - Nsys, = size(Hsys) + _Hsys = HandleMatrixType(Hsys, 0, "Hsys (system Hamiltonian)") + Nsys, = size(_Hsys) sup_dim = Nsys ^ 2 I_sup = sparse(I, sup_dim, sup_dim) # the Liouvillian operator for free Hamiltonian term - Lsys = -1im * (spre(Hsys) - spost(Hsys)) + Lsys = -1im * (spre(_Hsys) - spost(_Hsys)) # check for bosonic and fermionic bath if verbose && (threshold > 0.0) diff --git a/src/heom_matrices/M_Fermion.jl b/src/heom_matrices/M_Fermion.jl index 112a2e7e..1340e4ba 100644 --- a/src/heom_matrices/M_Fermion.jl +++ b/src/heom_matrices/M_Fermion.jl @@ -56,15 +56,13 @@ Generate the fermion-type HEOM Liouvillian superoperator matrix end # check for system dimension - if !isValidMatrixType(Hsys) - error("Invalid matrix \"Hsys\" (system Hamiltonian).") - end - Nsys, = size(Hsys) + _Hsys = HandleMatrixType(Hsys, 0, "Hsys (system Hamiltonian)") + Nsys, = size(_Hsys) sup_dim = Nsys ^ 2 I_sup = sparse(I, sup_dim, sup_dim) - + # the Liouvillian operator for free Hamiltonian term - Lsys = -1im * (spre(Hsys) - spost(Hsys)) + Lsys = -1im * (spre(_Hsys) - spost(_Hsys)) # fermionic bath if verbose && (threshold > 0.0) diff --git a/src/heom_matrices/M_S.jl b/src/heom_matrices/M_S.jl index 63a033cc..c5b1cf53 100644 --- a/src/heom_matrices/M_S.jl +++ b/src/heom_matrices/M_S.jl @@ -52,10 +52,8 @@ Note that the parity only need to be set as `:odd` when the system contains ferm end # check for system dimension - if !isValidMatrixType(Hsys) - error("Invalid matrix \"Hsys\" (system Hamiltonian).") - end - Nsys, = size(Hsys) + _Hsys = HandleMatrixType(Hsys, 0, "Hsys (system Hamiltonian)") + Nsys, = size(_Hsys) sup_dim = Nsys ^ 2 # the Liouvillian operator for free Hamiltonian @@ -63,7 +61,7 @@ Note that the parity only need to be set as `:odd` when the system contains ferm println("Constructing Liouville-von Neumann superoperator...") flush(stdout) end - Lsys = -1im * (spre(Hsys) - spost(Hsys)) + Lsys = -1im * (spre(_Hsys) - spost(_Hsys)) if verbose println("[DONE]") flush(stdout) diff --git a/src/heom_matrices/heom_matrix_base.jl b/src/heom_matrices/heom_matrix_base.jl index b8170955..283b049f 100644 --- a/src/heom_matrices/heom_matrix_base.jl +++ b/src/heom_matrices/heom_matrix_base.jl @@ -81,11 +81,8 @@ function addBosonDissipator(M::T, jumpOP::Vector=[]) where T <: AbstractHEOMLSMa if length(jumpOP) > 0 L = spzeros(ComplexF64, M.sup_dim, M.sup_dim) for J in jumpOP - if isValidMatrixType(J, M.dim) - L += spre(J) * spost(J') - 0.5 * (spre(J' * J) + spost(J' * J)) - else - error("Invalid matrix in \"jumpOP\".") - end + _J = HandleMatrixType(J, M.dim, "in jumpOP") + L += spre(_J) * spost(_J') - 0.5 * (spre(_J' * _J) + spost(_J' * _J)) end if T == M_S @@ -128,11 +125,8 @@ function addFermionDissipator(M::T, jumpOP::Vector=[]) where T <: AbstractHEOMLS parity = eval(M.parity) L = spzeros(ComplexF64, M.sup_dim, M.sup_dim) for J in jumpOP - if isValidMatrixType(J, M.dim) - L += ((-1) ^ parity) * spre(J) * spost(J') - 0.5 * (spre(J' * J) + spost(J' * J)) - else - error("Invalid matrix in \"jumpOP\".") - end + _J = HandleMatrixType(J, M.dim, "in jumpOP") + L += ((-1) ^ parity) * spre(_J) * spost(_J') - 0.5 * (spre(_J' * _J) + spost(_J' * _J)) end if T == M_S return M_S(M.data + L, M.tier, M.dim, M.N, M.sup_dim, M.parity) diff --git a/test/bath.jl b/test/bath.jl index cf57ae70..9b5a77a1 100644 --- a/test/bath.jl +++ b/test/bath.jl @@ -55,7 +55,7 @@ end @test_throws ErrorException BosonBath(op, [0], [0, 0]) @test_throws ErrorException BosonBath(op, [0, 0], [0, 0], [0], [0, 0]) @test_throws ErrorException BosonBath(op, [0, 0], [0], [0, 0], [0, 0]) -@test_throws ErrorException @test_warn "HEOM doesn't support matrix type : Vector{Int64}" BosonBath([0, 0], [0, 0], [0, 0], [0, 0], [0, 0]) +@test_throws ErrorException BosonBath([0, 0], [0, 0], [0, 0], [0, 0], [0, 0]) @test_warn "The system-bosonic-bath coupling operator \"op\" should be Hermitian operator" BosonBath([0 1; 0 0], [0, 0], [0, 0], [0, 0], [0, 0]) ################################################ @@ -81,7 +81,7 @@ end @test_throws ErrorException FermionBath(op, [0, 0], [0], [0, 0], [0, 0]) @test_throws ErrorException FermionBath(op, [0, 0], [0, 0], [0], [0, 0]) @test_throws ErrorException FermionBath(op, [0, 0], [0, 0], [0, 0], [0]) -@test_throws ErrorException @test_warn "The size of input matrix should be squared matrix." FermionBath([0, 0], [0, 0], [0, 0], [0, 0], [0, 0]) +@test_throws ErrorException FermionBath([0, 0], [0, 0], [0, 0], [0, 0], [0, 0]) ################################################ ################################################ diff --git a/test/heom_api.jl b/test/heom_api.jl index d328eb5b..f8c497c4 100644 --- a/test/heom_api.jl +++ b/test/heom_api.jl @@ -37,7 +37,7 @@ @test_throws BoundsError L[1:5, 2] @test_throws ErrorException ados[L.N + 1] @test_throws ErrorException M_S(Hsys, :wrong; verbose=false) - @test_throws ErrorException @test_warn "HEOM doesn't support matrix type : Vector{Int64}" M_S([0, 0]; verbose=false) + @test_throws ErrorException M_S([0, 0]; verbose=false) end λ = 0.1450 @@ -106,7 +106,7 @@ J = [0 0.1450 - 0.7414im; 0.1450 + 0.7414im 0] @test_throws BoundsError L[1:1821, 336] @test_throws ErrorException ados[L.N + 1] @test_throws ErrorException M_Boson(Hsys, tier, Bbath, :wrong; verbose=false) - @test_throws ErrorException @test_warn "HEOM doesn't support matrix type : Vector{Int64}" M_Boson([0, 0], tier, Bbath; verbose=false) + @test_throws ErrorException M_Boson([0, 0], tier, Bbath; verbose=false) end # Test Fermion-type HEOM Liouvillian superoperator matrix @@ -160,7 +160,7 @@ end @test_throws BoundsError L[1:9301, 9300] @test_throws ErrorException ados[L.N + 1] @test_throws ErrorException M_Fermion(Hsys, tier, Fbath, :wrong; verbose=false) - @test_throws ErrorException @test_warn "HEOM doesn't support matrix type : Vector{Int64}" M_Fermion([0, 0], tier, Fbath; verbose=false) + @test_throws ErrorException M_Fermion([0, 0], tier, Fbath; verbose=false) end # Test Boson-Fermion-type HEOM Liouvillian superoperator matrix @@ -232,7 +232,7 @@ end ## check exceptions @test_throws ErrorException ados[L.N + 1] @test_throws ErrorException M_Boson_Fermion(Hsys, tierb, tierf, Bbath, Fbath, :wrong; verbose=false) - @test_throws ErrorException @test_warn "HEOM doesn't support matrix type : Vector{Int64}" M_Boson_Fermion([0, 0], tierb, tierf, Bbath, Fbath; verbose=false) + @test_throws ErrorException M_Boson_Fermion([0, 0], tierb, tierf, Bbath, Fbath; verbose=false) end @testset "Hierarchy Dictionary" begin @@ -316,7 +316,7 @@ end # expections for expect ados_wrong = ADOs(spzeros(Int64, 18), 2) - @test_throws ErrorException("The dimension of `op` is not consistent with `ados`.") @test_warn "The size of input matrix should be: (2, 2)." Expect([0 0 0; 0 0 0; 0 0 0], ados_f) - @test_throws ErrorException("The dimension of the elements in `ados_list` should be consistent.") Expect([0 0; 0 0], [ados_b, ados_wrong]) - @test_throws ErrorException("The dimension of `op` is not consistent with the elements in `ados_list`.") @test_warn "The size of input matrix should be: (2, 2)." Expect([0 0 0; 0 0 0; 0 0 0], [ados_b, ados_f]) + @test_throws ErrorException Expect([0 0 0; 0 0 0; 0 0 0], ados_f) + @test_throws ErrorException Expect([0 0; 0 0], [ados_b, ados_wrong]) + @test_throws ErrorException Expect([0 0 0; 0 0 0; 0 0 0], [ados_b, ados_f]) end \ No newline at end of file diff --git a/test/phys_analysis.jl b/test/phys_analysis.jl index c8cf5892..76206fda 100644 --- a/test/phys_analysis.jl +++ b/test/phys_analysis.jl @@ -29,7 +29,7 @@ ados = SteadyState(L, ρ0; verbose=false) bathf = Fermion_Lorentz_Pade(mat, 1, 1, 1, 1, 2) @test_throws ErrorException SteadyState(M_Fermion(mat, 2, bathf, :odd; verbose=false)) @test_throws ErrorException SteadyState(M_Fermion(mat, 2, bathf, :odd; verbose=false), mat) - @test_throws ErrorException @test_warn "The size of input matrix should be: (2, 2)." SteadyState(L, mat2) + @test_throws ErrorException SteadyState(L, mat2) @test_throws ErrorException SteadyState(L, ADOs(zeros(8), 2)) @test_throws ErrorException SteadyState(L, ADOs(ados.data, ados.N, :odd)) end @@ -52,7 +52,7 @@ end ados_wrong2 = ADOs((ados_list[1]).data, (ados_list[1]).N, :odd) ρ_list_p = getRho.(ados_list) @test_throws ErrorException evolution(L, ρ0, Δt, steps; verbose=false, filename="evolution_p") - @test_throws ErrorException @test_warn "The size of input matrix should be: (2, 2)." evolution(L, ρ_wrong, Δt, steps; verbose=false) + @test_throws ErrorException evolution(L, ρ_wrong, Δt, steps; verbose=false) @test_throws ErrorException evolution(L, ados_wrong1, Δt, steps) @test_throws ErrorException evolution(L, ados_wrong2, Δt, steps) @@ -62,7 +62,7 @@ end # using the method based on ODE solver ρ_list_e = getRho.(evolution(L, ρ0, tlist; verbose=false, filename="evolution_o")) @test_throws ErrorException evolution(L, ρ0, tlist; verbose=false, filename="evolution_o") - @test_throws ErrorException @test_warn "The size of input matrix should be: (2, 2)." evolution(L, ρ_wrong, tlist; verbose=false) + @test_throws ErrorException evolution(L, ρ_wrong, tlist; verbose=false) @test_throws ErrorException evolution(L, ados_wrong1, tlist) @test_throws ErrorException evolution(L, ados_wrong2, tlist) @@ -101,7 +101,7 @@ end end fastDD_ados = evolution(L, ρ0, tlist, Ht, (0.50, 20, π/2); reltol=1e-12, abstol=1e-12, verbose=false, filename="evolution_t"); @test_throws ErrorException evolution(L, ρ0, tlist, Ht, (0.50, 20, π/2); verbose=false, filename="evolution_t") - @test_throws ErrorException @test_warn "The size of input matrix should be: (2, 2)." evolution(L, ρ_wrong, tlist, Ht; verbose=false) + @test_throws ErrorException evolution(L, ρ_wrong, tlist, Ht; verbose=false) fastBoFiN = [ 0.4999999999999999, 0.4972948770876402, @@ -209,8 +209,8 @@ end zeros(3, 3) end end - @test_throws ErrorException("The dimension of `H` at t=0 is not consistent with `M.dim`.") @test_warn "The size of input matrix should be: (2, 2)." evolution(L, ρ0, tlist, H_wrong1; verbose=false); - @test_throws ErrorException @test_warn "The size of input matrix should be: (2, 2)." evolution(L, ρ0, tlist, H_wrong2; verbose=false); + @test_throws ErrorException evolution(L, ρ0, tlist, H_wrong1; verbose=false); + @test_throws ErrorException evolution(L, ρ0, tlist, H_wrong2; verbose=false); @test_throws ErrorException evolution(L, ados_wrong1, tlist, Ht) @test_throws ErrorException evolution(L, ados_wrong2, tlist, Ht) end @@ -269,7 +269,7 @@ end mat2 = spzeros(ComplexF64, 3, 3) bathf = Fermion_Lorentz_Pade(mat, 1, 1, 1, 1, 2) @test_throws ErrorException spectrum(L, ados_s, a, ωlist; verbose=false, filename="PSD") - @test_throws ErrorException @test_warn "The size of input matrix should be: (2, 2)." spectrum(L, ados_s, mat2, ωlist; verbose=false) + @test_throws ErrorException spectrum(L, ados_s, mat2, ωlist; verbose=false) @test_throws ErrorException spectrum(L, ADOs(zeros(8), 2), a, ωlist; verbose=false) @test_throws ErrorException spectrum(L, ADOs(ados_s.data, ados_s.N, :odd), a, ωlist; verbose=false) @test_throws ErrorException spectrum(M_Fermion(mat, 2, bathf, :odd; verbose=false), mat, mat, [0]) @@ -339,7 +339,7 @@ end mat2 = spzeros(ComplexF64, 3, 3) bathb = Boson_DrudeLorentz_Pade(mat, 1, 1, 1, 2) @test_throws ErrorException spectrum(Lo, ados_s, d_up, ωlist; verbose=false, filename="DOS") - @test_throws ErrorException @test_warn "The size of input matrix should be: (2, 2)." spectrum(Lo, ados_s, mat2, ωlist; verbose=false) + @test_throws ErrorException spectrum(Lo, ados_s, mat2, ωlist; verbose=false) @test_throws ErrorException spectrum(Lo, ADOs(zeros(8), 2), d_up, ωlist; verbose=false) @test_throws ErrorException spectrum(Lo, ADOs(ados_s.data, ados_s.N, :odd), d_up, ωlist; verbose=false) @test_throws ErrorException spectrum(M_Boson(mat, 2, bathb; verbose=false), mat, mat, [0]) From 9ce4a3074bfa00bfd092a988adc72ba5a87d8ad2 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Fri, 15 Sep 2023 18:43:50 +0800 Subject: [PATCH 05/15] add runtests for QuantumOptics extension --- Project.toml | 7 +++ ext/HierarchicalEOM_QOExt.jl | 34 +++++++++++++ src/Bath.jl | 52 ++++++++++--------- src/HierarchicalEOM.jl | 3 ++ src/heom_matrices/heom_matrix_base.jl | 4 +- test/QOExt.jl | 72 +++++++++++++++++++++++++++ test/runtests.jl | 7 ++- 7 files changed, 152 insertions(+), 27 deletions(-) create mode 100644 ext/HierarchicalEOM_QOExt.jl create mode 100644 test/QOExt.jl diff --git a/Project.toml b/Project.toml index f1141331..91819f75 100644 --- a/Project.toml +++ b/Project.toml @@ -13,11 +13,18 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca" +QuantumOptics = "6e0679c1-51ea-5a7c-ac74-d61b76210b0c" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f" +[weakdeps] +QuantumOptics = "6e0679c1-51ea-5a7c-ac74-d61b76210b0c" + +[extensions] +HierarchicalEOM_QOExt = "QuantumOptics" + [compat] Crayons = "4.1" FastExpm = "1.1.0" diff --git a/ext/HierarchicalEOM_QOExt.jl b/ext/HierarchicalEOM_QOExt.jl new file mode 100644 index 00000000..c304f353 --- /dev/null +++ b/ext/HierarchicalEOM_QOExt.jl @@ -0,0 +1,34 @@ +module HierarchicalEOM_QOExt + +import QuantumOptics: AbstractOperator, Operator +using HierarchicalEOM +import HierarchicalEOM.HeomBase: HandleMatrixType + +@doc raw""" + QOoperator(data::AbstractMatrix, refOP::AbstractOperator) +Return the operator under the type of `QuantumOptics.AbstractOperator` from a given matrix and the basis in reference operator. + +# Parameters +- `data` : The matrix-type operator. +- `refOP<:QuantumOptics.AbstractOperator` : the reference operator which contains the basis defined in `QuantumOptics`. +""" +QOoperator(data::AbstractMatrix, refOP::AbstractOperator) = Operator(refOP.basis_l, refOP.basis_r, data) + +function HandleMatrixType(M::AbstractOperator, dim::Int=0, MatrixName::String="") + if dim > 0 + if size(M.data) == (dim, dim) + return copy(M.data) + else + error("The size of matrix $(MatrixName) should be: ($(dim), $(dim)).") + end + elseif dim == 0 + N1, N2 = size(M.data) + if N1 == N2 + return copy(M.data) + else + error("The size of matrix $(MatrixName) should be squared matrix.") + end + end +end + +end \ No newline at end of file diff --git a/src/Bath.jl b/src/Bath.jl index 372ed335..6ea41366 100644 --- a/src/Bath.jl +++ b/src/Bath.jl @@ -142,18 +142,18 @@ end isclose(a::Number, b::Number, rtol=1e-05, atol=1e-08) = abs(a - b) <= (atol + rtol * abs(b)) function _check_bosonic_coupling_operator(op) - _op = HandleMatrixType(op) + _op = HandleMatrixType(op, 0, "op (coupling operator)") N, = size(_op) if !ishermitian(_op) @warn "The system-bosonic-bath coupling operator \"op\" should be Hermitian operator." end - return N + return N, _op end function _check_fermionic_coupling_operator(op) - _op = HandleMatrixType(op) + _op = HandleMatrixType(op, 0, "op (coupling operator)") N, = size(_op) - return N + return N, _op end function _combine_same_gamma(η::Vector{Ti}, γ::Vector{Tj}) where {Ti, Tj <: Number} @@ -243,7 +243,8 @@ function BosonBath( else bRI = bosonRealImag(op, real.(η), imag.(η), γ) end - return BosonBath(AbstractBosonBath[bRI], copy(op), bRI.dim, bRI.Nterm, δ) + _op = HandleMatrixType(op, 0, "op (coupling operator)") + return BosonBath(AbstractBosonBath[bRI], _op, bRI.dim, bRI.Nterm, δ) end @doc raw""" @@ -326,12 +327,14 @@ function BosonBath( if Nterm != (Nterm_new + bRI.Nterm) error("Conflicts occur in combining real and imaginary parts of bath correlation function.") end - return BosonBath(AbstractBosonBath[bR, bI, bRI], copy(op), bR.dim, Nterm_new, δ) + _op = HandleMatrixType(op, 0, "op (coupling operator)") + return BosonBath(AbstractBosonBath[bR, bI, bRI], _op, bR.dim, Nterm_new, δ) else - bR = bosonReal(op, η_real, γ_real) - bI = bosonImag(op, η_imag, γ_imag) - return BosonBath(AbstractBosonBath[bR, bI], copy(op), bR.dim, bR.Nterm + bI.Nterm, δ) + bR = bosonReal(op, η_real, γ_real) + bI = bosonImag(op, η_imag, γ_imag) + _op = HandleMatrixType(op, 0, "op (coupling operator)") + return BosonBath(AbstractBosonBath[bR, bI], _op, bR.dim, bR.Nterm + bI.Nterm, δ) end end @@ -369,7 +372,7 @@ function bosonReal( γ_real::Vector{Tj} ) where {Ti, Tj <: Number} - dim = _check_bosonic_coupling_operator(op) + dim, _op = _check_bosonic_coupling_operator(op) # check if the length of coefficients are valid N_exp_term = length(η_real) @@ -377,7 +380,7 @@ function bosonReal( error("The length of \'η_real\' and \'γ_real\' should be the same.") end - return bosonReal(spre(op) - spost(op), dim, η_real, γ_real, N_exp_term) + return bosonReal(spre(_op) - spost(_op), dim, η_real, γ_real, N_exp_term) end @doc raw""" @@ -416,15 +419,15 @@ Generate bosonic bath for the imaginary part of correlation function ``C^{u=\tex γ_imag::Vector{Tj} ) where {Ti, Tj <: Number} - dim = _check_bosonic_coupling_operator(op) + dim, _op = _check_bosonic_coupling_operator(op) # check if the length of coefficients are valid N_exp_term = length(η_imag) if N_exp_term != length(γ_imag) error("The length of \'η_imag\' and \'γ_imag\' should be the same.") end - spreQ = spre(op) - spostQ = spost(op) + spreQ = spre(_op) + spostQ = spost(_op) return bosonImag(spreQ - spostQ, spreQ + spostQ, dim, η_imag, γ_imag, N_exp_term) end @@ -468,15 +471,15 @@ function bosonRealImag( γ::Vector{Tk} ) where {Ti, Tj, Tk <: Number} - dim = _check_bosonic_coupling_operator(op) + dim, _op = _check_bosonic_coupling_operator(op) # check if the length of coefficients are valid N_exp_term = length(η_real) if (N_exp_term != length(η_imag)) || (N_exp_term != length(γ)) error("The length of \'η_real\', \'η_imag\' and \'γ\' should be the same.") end - spreQ = spre(op) - spostQ = spost(op) + spreQ = spre(_op) + spostQ = spost(_op) return bosonRealImag(spreQ - spostQ, spreQ + spostQ, dim, η_real, η_imag, γ, N_exp_term) end @@ -544,9 +547,10 @@ function FermionBath( δ::Tm=0.0 ) where {Ti, Tj, Tk, Tl, Tm <: Number} - fA = fermionAbsorb(adjoint(op), η_absorb, γ_absorb, η_emit) - fE = fermionEmit(op, η_emit, γ_emit, η_absorb) - return FermionBath(AbstractFermionBath[fA, fE], copy(op), fA.dim, fA.Nterm + fE.Nterm, δ) + fA = fermionAbsorb(adjoint(op), η_absorb, γ_absorb, η_emit) + fE = fermionEmit(op, η_emit, γ_emit, η_absorb) + _op = HandleMatrixType(op, 0, "op (coupling operator)") + return FermionBath(AbstractFermionBath[fA, fE], _op, fA.dim, fA.Nterm + fE.Nterm, δ) end @doc raw""" @@ -593,14 +597,14 @@ function fermionAbsorb( η_emit::Vector{Tk} ) where {Ti, Tj, Tk <: Number} - dim = _check_fermionic_coupling_operator(op) + dim, _op = _check_fermionic_coupling_operator(op) # check if the length of coefficients are valid N_exp_term = length(η_absorb) if (N_exp_term != length(γ_absorb)) || (N_exp_term != length(η_emit)) error("The length of \'η_absorb\', \'γ_absorb\' and \'η_emit\' should all be the same.") end - return fermionAbsorb(spre(op), spost(op), spre(adjoint(op)), spost(adjoint(op)), dim, η_absorb, γ_absorb, η_emit, N_exp_term) + return fermionAbsorb(spre(_op), spost(_op), spre(adjoint(_op)), spost(adjoint(_op)), dim, η_absorb, γ_absorb, η_emit, N_exp_term) end @doc raw""" @@ -647,14 +651,14 @@ function fermionEmit( η_absorb::Vector{Tk} ) where {Ti, Tj, Tk <: Number} - dim = _check_fermionic_coupling_operator(op) + dim, _op = _check_fermionic_coupling_operator(op) # check if the length of coefficients are valid N_exp_term = length(η_emit) if (N_exp_term != length(γ_emit)) || (N_exp_term != length(η_absorb)) error("The length of \'η_emit\', \'γ_emit\' and \'η_absorb\' should all be the same.") end - return fermionEmit(spre(op), spost(op), spre(adjoint(op)), spost(adjoint(op)), dim, η_emit, γ_emit, η_absorb, N_exp_term) + return fermionEmit(spre(_op), spost(_op), spre(adjoint(_op)), spost(adjoint(_op)), dim, η_emit, γ_emit, η_absorb, N_exp_term) end @doc raw""" diff --git a/src/HierarchicalEOM.jl b/src/HierarchicalEOM.jl index 35fb9cc8..329a086d 100644 --- a/src/HierarchicalEOM.jl +++ b/src/HierarchicalEOM.jl @@ -4,6 +4,9 @@ module HierarchicalEOM export Bath, HeomAPI, Spectrum + # export for extension + export QOoperator + # sub-module HeomBase for HierarchicalEOM module HeomBase import Pkg diff --git a/src/heom_matrices/heom_matrix_base.jl b/src/heom_matrices/heom_matrix_base.jl index 283b049f..85832af9 100644 --- a/src/heom_matrices/heom_matrix_base.jl +++ b/src/heom_matrices/heom_matrix_base.jl @@ -140,8 +140,8 @@ function addFermionDissipator(M::T, jumpOP::Vector=[]) where T <: AbstractHEOMLS end end -function addBosonDissipator(M::AbstractHEOMLSMatrix, jumpOP::AbstractMatrix) return addBosonDissipator(M, [jumpOP]) end -function addFermionDissipator(M::AbstractHEOMLSMatrix, jumpOP::AbstractMatrix) return addFermionDissipator(M, [jumpOP]) end +function addBosonDissipator(M::AbstractHEOMLSMatrix, jumpOP) return addBosonDissipator(M, [jumpOP]) end +function addFermionDissipator(M::AbstractHEOMLSMatrix, jumpOP) return addFermionDissipator(M, [jumpOP]) end @doc raw""" addTerminator(M, Bath) diff --git a/test/QOExt.jl b/test/QOExt.jl new file mode 100644 index 00000000..3f6818d1 --- /dev/null +++ b/test/QOExt.jl @@ -0,0 +1,72 @@ +# System Hamiltonian and initial state +basis = SpinBasis(1//2) +σx = sigmax(basis) +σz = sigmaz(basis) +σm = sigmam(basis) +I2 = identityoperator(basis) + +Hsys = 0.25 * σz + 0.5 * σx +ρ0 = dm(Ket(basis, [1, 0])) + +λ = 0.1 +W = 0.5 +kT = 0.5 +N = 2 +Q = σz # System-bath coupling operator +bath = Boson_DrudeLorentz_Pade(Q, λ, W, kT, N) + +# SteadyState +ados = SteadyState(L, ρ0; verbose=false) + +# Evolution +tier = 5 +L = M_Boson(Hsys, tier, bath; verbose=false) +O = I2 + 0.5 * σx +Δt = 10 +steps = 1 +tlist = 0:Δt:(Δt * steps) +ados_list = evolution(L, ρ0, Δt, steps; verbose=false) +ados_list = evolution(L, ρ0, tlist; verbose=false) +@test Expect(O, ados_list[end]) ≈ real.(tr.(O * QOoperator(ados_list[end][1], Hsys))) + +# Power spectral density +a = sigmam(basis) +Hsys = a' * a +λ = 1e-4 +W = 2e-1 +kT = 0.5 +N = 5 +bath = Boson_DrudeLorentz_Matsubara((a' + a), λ, W, kT, N) +tier = 3 +L = M_Boson(Hsys, tier, bath; verbose=false) +L = addBosonDissipator(L, 1e-3 * a') +L = addTerminator(L, bath) +ados_s = SteadyState(L; verbose=false) +ωlist = [0.9] +@test spectrum(L, ados_s, a, ωlist; verbose=false)[1] ≈ 0.0008880367286438112 + +# Density of states +e = -5 +U = 10 +d_up = σm ⊗ I2 +d_dn = -σz ⊗ σm +iden = I2 ⊗ I2 +H0 = e * (d_up' * d_up + d_dn' * d_dn) +H1 = U * (d_up' * d_up * d_dn' * d_dn) +Hsys = H0 + H1 +λ = 1 +μ_l = 1 +μ_r = -1 +W = 10 +kT = 0.5 +N = 5 +fuL = Fermion_Lorentz_Pade(d_up, λ, μ_l, W, kT, N) +fdL = Fermion_Lorentz_Pade(d_dn, λ, μ_l, W, kT, N) +fuR = Fermion_Lorentz_Pade(d_up, λ, μ_r, W, kT, N) +fdR = Fermion_Lorentz_Pade(d_dn, λ, μ_r, W, kT, N) +tier = 2 +Le = M_Fermion(Hsys, tier, [fuL, fdL, fuR, fdR]; verbose=false) +Lo = M_Fermion(Hsys, tier, [fuL, fdL, fuR, fdR], :odd; verbose=false) +ados_s = SteadyState(Le; verbose=false) +ωlist = [0] +@test spectrum(Lo, ados_s, d_up, ωlist; verbose=false)[1] ≈ 0.17217519700362002 \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 04d00838..d9d377ef 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,3 +1,4 @@ +using QuantumOptics using HierarchicalEOM using Test using SparseArrays @@ -19,4 +20,8 @@ end include("heom_api.jl") -include("phys_analysis.jl") \ No newline at end of file +include("phys_analysis.jl") + +@testset "QuantumOptics Extension" begin + include("QOExt.jl") +end \ No newline at end of file From 9a3e7e59cbad5a89044bfd914557c764ccf484cc Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Sat, 16 Sep 2023 14:33:31 +0800 Subject: [PATCH 06/15] remove QOoperator --- ext/HierarchicalEOM_QOExt.jl | 4 ++-- src/HierarchicalEOM.jl | 3 --- test/QOExt.jl | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/ext/HierarchicalEOM_QOExt.jl b/ext/HierarchicalEOM_QOExt.jl index c304f353..f146778e 100644 --- a/ext/HierarchicalEOM_QOExt.jl +++ b/ext/HierarchicalEOM_QOExt.jl @@ -5,14 +5,14 @@ using HierarchicalEOM import HierarchicalEOM.HeomBase: HandleMatrixType @doc raw""" - QOoperator(data::AbstractMatrix, refOP::AbstractOperator) + Operator(data::AbstractMatrix, refOP::AbstractOperator) Return the operator under the type of `QuantumOptics.AbstractOperator` from a given matrix and the basis in reference operator. # Parameters - `data` : The matrix-type operator. - `refOP<:QuantumOptics.AbstractOperator` : the reference operator which contains the basis defined in `QuantumOptics`. """ -QOoperator(data::AbstractMatrix, refOP::AbstractOperator) = Operator(refOP.basis_l, refOP.basis_r, data) +Operator(data::AbstractMatrix, refOP::AbstractOperator) = Operator(refOP.basis_l, refOP.basis_r, data) function HandleMatrixType(M::AbstractOperator, dim::Int=0, MatrixName::String="") if dim > 0 diff --git a/src/HierarchicalEOM.jl b/src/HierarchicalEOM.jl index 329a086d..35fb9cc8 100644 --- a/src/HierarchicalEOM.jl +++ b/src/HierarchicalEOM.jl @@ -4,9 +4,6 @@ module HierarchicalEOM export Bath, HeomAPI, Spectrum - # export for extension - export QOoperator - # sub-module HeomBase for HierarchicalEOM module HeomBase import Pkg diff --git a/test/QOExt.jl b/test/QOExt.jl index 3f6818d1..898b07a9 100644 --- a/test/QOExt.jl +++ b/test/QOExt.jl @@ -27,7 +27,7 @@ steps = 1 tlist = 0:Δt:(Δt * steps) ados_list = evolution(L, ρ0, Δt, steps; verbose=false) ados_list = evolution(L, ρ0, tlist; verbose=false) -@test Expect(O, ados_list[end]) ≈ real.(tr.(O * QOoperator(ados_list[end][1], Hsys))) +@test Expect(O, ados_list[end]) ≈ real(tr(O * Operator(ados_list[end][1], Hsys))) # Power spectral density a = sigmam(basis) From 7a0cc21bcc911bd5492849261903d5ae9ce0d0b0 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Sat, 16 Sep 2023 16:15:25 +0800 Subject: [PATCH 07/15] update docs for QOExt --- docs/make.jl | 5 ++- docs/src/extensions/QuantumOptics.md | 54 ++++++++++++++++++++++++++++ docs/src/install.md | 3 ++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 docs/src/extensions/QuantumOptics.md diff --git a/docs/make.jl b/docs/make.jl index 4fd8eeeb..1c3cdec0 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -72,7 +72,10 @@ const PAGES = Any[ "Stationary State" => "stationary_state.md", "Spectrum" => "spectrum.md", "Examples" => EX_output_files, - "Benchmark Solvers" => BM_output_files + "Benchmark Solvers" => BM_output_files, + "Extensions" => Any[ + "QuantumOptics.jl" => "extensions/QuantumOptics.md" + ] ], "Library API" => "libraryAPI.md" ] diff --git a/docs/src/extensions/QuantumOptics.md b/docs/src/extensions/QuantumOptics.md new file mode 100644 index 00000000..2d8e9136 --- /dev/null +++ b/docs/src/extensions/QuantumOptics.md @@ -0,0 +1,54 @@ +# [Extension for QuantumOptics.jl](@id doc-ext-QuantumOptics) + +This is an extension to support [`QuantumOptics`](https://qojulia.org/)-type of operators (matrices) + +!!! compat "Compat" + The described feature requires `Julia 1.9+`. + +When users construct the operators (such as system Hamiltonian, coupling operators, initial states, etc) by [`QuantumOptics.jl`](https://qojulia.org/) and take those matrices as inputs of `HierarchicalEOM.jl`, it will extract the `data` (matrix) part in `QuantumOptics.AbstractOperator`. Therefore, the type of `data` in `AbstractHEOMLSMatrix` still remain as `SparseMatrixCSC{ComplexF64, Int64}` without the basis information stored in `QuantumOptics.AbstractOperator`. + +Although it doesn't store the basis information from `QuantumOptics.AbstractOperator`, it still supports calculating the expectation value ([`Expect`](@ref)) when the observable is given in the type of `QuantumOptics.AbstractOperator` (as long as the size of the matrix is equal). + +Furthermore, it provides an extra method to re-construct reduced density operator with the type of `QuantumOptics.AbstractOperator`. Basically, it copies the basis information from another given `QuantumOptics.AbstractOperator` (as shown in the example below). With this functionality, one can again use the other functions provided in [`QuantumOptics.jl`](https://qojulia.org/). + +The extension will be automatically loaded if user imports the package `QuantumOptics.jl` : +```@example +using QuantumOptics +using HierarchicalEOM + +basis = SpinBasis(1//2) +I2 = identityoperator(basis) +d1 = sigmam(basis) ⊗ I2 +d2 = I2 ⊗ sigmam(basis) + +# system Hamiltonian +Hsys = -3 * d1' * d1 - 5 * d2' * d2 + +# system initial state +ρ0 = dm(Ket(basis, [0, 1])) ⊗ dm(Ket(basis, [0, 1])) + +# construct bath +bath1 = Fermion_Lorentz_Pade(d1, 0.01, 0, 10, 0.05, 2) +bath2 = Fermion_Lorentz_Pade(d2, 0.01, 0, 10, 0.05, 2) +baths = [bath1, bath2] + +# construct HEOMLS matrix +tier = 2 +L = M_Fermion(Hsys, tier, baths) +print(L) + +# solving time evolution +tlist = 0:1:10 +ados_list = evolution(L, ρ0, tlist) + +# expectation value +exp_val = Expect(d1' * d1, ados_list) + +# re-construct reduced density operator +# with the type of QuantumOptics.AbstractOperator +ρ_normal = ados_list[end][1] # reduced density operator ([1]) at t = 10 ([end]) +ρ_QO_type = Operator(ρ_normal, Hsys) # basis information is copied from Hsys + +# can use the functions provided in QuantumOptics.jl such as partial trace: +ptrace(ρ_QO_type, [1]) +``` \ No newline at end of file diff --git a/docs/src/install.md b/docs/src/install.md index f726bb58..6263061d 100644 --- a/docs/src/install.md +++ b/docs/src/install.md @@ -28,6 +28,9 @@ In order to get a better experience and take full advantage of `HierarchicalEOM` The inputs in `HierarchicalEOM` should be child-type of the standard `Base.AbstractVector` (for vector-type quantum states) and `Base.AbstractMatrix` (for matrix-type quantum operators). Users can still construct the vectors or matrices by standard method and take it as the input of `HierarchicalEOM`. For the users who constructs the quantum objects by `QuantumOptics` package, the standard type of vectors or matrices are stored in the `.data` field of the objects, i.e., `op.data` (where `op` is a `QuantumOptics`-type object). Thus, users should take it as the inputs of `HierarchicalEOM` for objects in `QuantumOptics` package. +!!! compat "Extension for QuantumOptics.jl" + `HierarchicalEOM.jl` provides an extension to support `QuantumOptics`-type object, but this feature requires `Julia 1.9+` and `HierarchicalEOM 0.3+`. See [here](@ref doc-ext-QuantumOptics) for more details. + ### [DifferentialEquations.jl](https://diffeq.sciml.ai/stable/) `DifferentialEquations` is needed to provide the low-level ODE solvers especially for solving time [`evolution`](@ref). For [low dependency usage](https://diffeq.sciml.ai/stable/features/low_dep/), users can use [`OrdinaryDiffEq.jl`](https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl) instead. From 731d410b0280aeb123190b70e1309f90e82f02e9 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Sat, 16 Sep 2023 16:15:41 +0800 Subject: [PATCH 08/15] update docs --- examples/benchmark_LS_solvers.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/benchmark_LS_solvers.jl b/examples/benchmark_LS_solvers.jl index f3c51743..d9d46896 100644 --- a/examples/benchmark_LS_solvers.jl +++ b/examples/benchmark_LS_solvers.jl @@ -50,6 +50,7 @@ julia_solver = LUFactorization(); # !!! note "Note" # Using this solver requires adding the package [Pardiso.jl](https://github.com/JuliaSparse/Pardiso.jl), i.e. `using Pardiso` using Pardiso +using LinearSolve mkl_solver = MKLPardisoFactorize() mkl_ite_solver = MKLPardisoIterate(); From 378c0fe1975d16a612031ea7464af80e109d91d9 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Sat, 16 Sep 2023 17:47:40 +0800 Subject: [PATCH 09/15] fix runtest and update CI for Julia 1.8 and 1.9 --- .github/workflows/Runtests.yml | 36 +++++++++++++++++++++-------- .github/workflows/documentation.yml | 12 +++++++--- test/runtests.jl | 35 +++++++++++++++++----------- 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/.github/workflows/Runtests.yml b/.github/workflows/Runtests.yml index b6eaef0b..dbbd1ef8 100644 --- a/.github/workflows/Runtests.yml +++ b/.github/workflows/Runtests.yml @@ -10,21 +10,39 @@ on: jobs: test: - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest strategy: matrix: - julia-version: ['1.8'] - julia-arch: [x64] - os: [ubuntu-latest] # [ubuntu-latest, windows-latest, macOS-latest] + group: + - Core + version: + - '1' + - '1.8' + include: + - version: '1' + group: 'HierarchicalEOM_QOExt' steps: - uses: actions/checkout@v3 - - uses: julia-actions/setup-julia@latest + - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.julia-version }} - - uses: julia-actions/cache@v1 - - uses: julia-actions/julia-buildpkg@latest - - uses: julia-actions/julia-runtest@latest - - uses: julia-actions/julia-processcoverage@latest + - uses: julia-actions/cache@v3 + 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/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 + env: + GROUP: ${{ matrix.group }} + - uses: julia-actions/julia-processcoverage@v1 + with: + directories: src,ext - uses: codecov/codecov-action@v3 with: file: lcov.info diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 5a44b884..b542ff21 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -17,9 +17,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: julia-actions/setup-julia@latest + - uses: julia-actions/setup-julia@v1 with: - version: '1.9' + version: '1' - uses: julia-actions/cache@v1 - name: Install X Server dependencies run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev @@ -29,4 +29,10 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key - run: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=docs/ docs/make.jl + run: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=docs/ --code-coverage=user docs/make.jl + - uses: julia-actions/julia-processcoverage@v1 + with: + directories: src + - uses: codecov/codecov-action@v3 + with: + files: lcov.info \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index d9d377ef..45450de1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,24 +4,31 @@ using Test using SparseArrays using LinearAlgebra -include("utils.jl") +const GROUP = get(ENV, "GROUP", "All") +const HAS_EXTENSIONS = isdefined(Base, :get_extension) -@testset "Print version information" begin - @test HierarchicalEOM.versioninfo() == nothing -end +if GROUP == "All" || GROUP == "Core" + include("utils.jl") -@testset "Bath and Exponent" begin - include("bath.jl") -end + @testset "Print version information" begin + @test HierarchicalEOM.versioninfo() == nothing + end -@testset "Correlation functions" begin - include("corr_func.jl") -end + @testset "Bath and Exponent" begin + include("bath.jl") + end -include("heom_api.jl") + @testset "Correlation functions" begin + include("corr_func.jl") + end -include("phys_analysis.jl") + include("heom_api.jl") + + include("phys_analysis.jl") +end -@testset "QuantumOptics Extension" begin - include("QOExt.jl") +if (GROUP == "All" || GROUP == "HierarchicalEOM_QOExt") && HAS_EXTENSIONS + @testset "QuantumOptics Extension" begin + include("QOExt.jl") + end end \ No newline at end of file From 1282f934f7b99b3f34f831ac4d96cc1f5c7a35bd Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Sat, 16 Sep 2023 17:56:42 +0800 Subject: [PATCH 10/15] fix CI --- .github/workflows/Runtests.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/Runtests.yml b/.github/workflows/Runtests.yml index 1df4bbbe..ee2d4988 100644 --- a/.github/workflows/Runtests.yml +++ b/.github/workflows/Runtests.yml @@ -26,16 +26,7 @@ jobs: - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.julia-version }} - - uses: julia-actions/cache@v3 - 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 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 env: From 815789055ac7077085b617310172d2b244ca5723 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Sat, 16 Sep 2023 18:27:35 +0800 Subject: [PATCH 11/15] fix runtests CI --- .github/workflows/Runtests.yml | 15 ++++++++++++--- .github/workflows/documentation.yml | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/Runtests.yml b/.github/workflows/Runtests.yml index ee2d4988..585e9f10 100644 --- a/.github/workflows/Runtests.yml +++ b/.github/workflows/Runtests.yml @@ -15,18 +15,27 @@ jobs: matrix: group: - Core - version: + julia-version: - '1' - '1.8' include: - - version: '1' + - julia-version: '1' group: 'HierarchicalEOM_QOExt' steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.julia-version }} - - uses: julia-actions/cache@v1 + - uses: actions/cache@v3 + 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/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 env: diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 7c8155c2..2799178d 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -35,4 +35,5 @@ jobs: directories: src - uses: codecov/codecov-action@v3 with: - files: lcov.info \ No newline at end of file + file: lcov.info + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file From b34ad4c437e94b887e4474f9ed9299bcda12c5d2 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Sat, 16 Sep 2023 18:47:03 +0800 Subject: [PATCH 12/15] fix runtest for QOExt --- test/QOExt.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/QOExt.jl b/test/QOExt.jl index 898b07a9..ab17eb91 100644 --- a/test/QOExt.jl +++ b/test/QOExt.jl @@ -14,13 +14,13 @@ kT = 0.5 N = 2 Q = σz # System-bath coupling operator bath = Boson_DrudeLorentz_Pade(Q, λ, W, kT, N) +L = M_Boson(Hsys, tier, bath; verbose=false) # SteadyState ados = SteadyState(L, ρ0; verbose=false) # Evolution tier = 5 -L = M_Boson(Hsys, tier, bath; verbose=false) O = I2 + 0.5 * σx Δt = 10 steps = 1 From 0dc789935bed8e462c4249031425008625c3c1c5 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Sat, 16 Sep 2023 18:53:58 +0800 Subject: [PATCH 13/15] fix runtests --- test/runtests.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 45450de1..22b7cc9b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,8 +7,9 @@ using LinearAlgebra const GROUP = get(ENV, "GROUP", "All") const HAS_EXTENSIONS = isdefined(Base, :get_extension) +include("utils.jl") + if GROUP == "All" || GROUP == "Core" - include("utils.jl") @testset "Print version information" begin @test HierarchicalEOM.versioninfo() == nothing From b2a3c09ba39ebe108488e72bc525c212730f5ef8 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Sat, 16 Sep 2023 19:06:45 +0800 Subject: [PATCH 14/15] fix runtests --- test/QOExt.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/QOExt.jl b/test/QOExt.jl index ab17eb91..50d688d6 100644 --- a/test/QOExt.jl +++ b/test/QOExt.jl @@ -13,6 +13,7 @@ W = 0.5 kT = 0.5 N = 2 Q = σz # System-bath coupling operator +tier = 2 bath = Boson_DrudeLorentz_Pade(Q, λ, W, kT, N) L = M_Boson(Hsys, tier, bath; verbose=false) From ce235eba68292a6f70008a414a4f35bf02bed749 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang Date: Sat, 16 Sep 2023 19:09:55 +0800 Subject: [PATCH 15/15] fix runtest CI --- .github/workflows/Runtests.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/Runtests.yml b/.github/workflows/Runtests.yml index 585e9f10..36069c2f 100644 --- a/.github/workflows/Runtests.yml +++ b/.github/workflows/Runtests.yml @@ -26,16 +26,7 @@ jobs: - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.julia-version }} - - uses: actions/cache@v3 - 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 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 env: