Skip to content

Commit

Permalink
make n_th to n_thermal and align with qutip
Browse files Browse the repository at this point in the history
  • Loading branch information
ytdHuang committed Oct 2, 2024
1 parent f897225 commit c377908
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions benchmarks/eigenvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ function benchmark_eigenvalues!(SUITE)
ωb = 1
g = 0.2
κ = 0.01
n_thermal = 0.1
n_th = 0.1

H = ωc * a_d * a + ωb * b_d * b + g * (a + a_d) * (b + b_d)
c_ops = [((1 + n_thermal) * κ) * a, κ * b, (n_thermal * κ) * a_d]
c_ops = [((1 + n_th) * κ) * a, κ * b, (n_th * κ) * a_d]
L = liouvillian(H, c_ops)

SUITE["Eigenvalues"]["eigenstates"]["dense"] = @benchmarkable eigenstates($L)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ AbstractLinearMap
QuantumToolbox.versioninfo
QuantumToolbox.about
gaussian
n_th
n_thermal
row_major_reshape
meshgrid
_calculate_expectation!
Expand Down
2 changes: 1 addition & 1 deletion src/time_evolution/time_evolution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ function liouvillian_generalized(
end

# Ohmic reservoir
N_th = n_th.(Ωp, T_list[i])
N_th = n_thermal.(Ωp, T_list[i])
Sp₀ = QuantumObject(triu(X_op, 1), type = Operator, dims = dims)
Sp₁ = QuantumObject(droptol!((@. Ωp * N_th * Sp₀.data), tol), type = Operator, dims = dims)
Sp₂ = QuantumObject(droptol!((@. Ωp * (1 + N_th) * Sp₀.data), tol), type = Operator, dims = dims)
Expand Down
19 changes: 11 additions & 8 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Utilities:
internal (or external) functions which will be used throughout the entire package
=#

export gaussian, n_th
export gaussian, n_thermal
export row_major_reshape, meshgrid

@doc raw"""
Expand Down Expand Up @@ -34,15 +34,18 @@ where ``\mu`` and ``\sigma^2`` are the mean and the variance respectively.
gaussian(x::Number, μ::Number, σ::Number) = exp(-(x - μ)^2 / (2 * σ^2))

@doc raw"""
n_th(ω::Number, T::Real)
n_thermal(ω::Real, ω_th::Real)
Gives the mean number of excitations in a mode with frequency ω at temperature T:
``n_{\rm th} (\omega, T) = \frac{1}{e^{\omega/T} - 1}``
Return the number of photons in thermal equilibrium for an harmonic oscillator mode with frequency ``\omega``, at the temperature described by ``\omega_{\textrm{th}} \equiv k_B T / \hbar``:
```math
n(\omega, \omega_{\textrm{th}}) = \frac{1}{e^{\omega/\omega_{\textrm{th}}} - 1},
```
where ``\hbar`` is the reduced Planck constant, and ``k_B`` is the Boltzmann constant.
"""
function n_th::Real, T::Real)::Float64
(T == 0 || ω == 0) && return 0.0
abs/ T) > 50 && return 0.0
return 1 / (exp/ T) - 1)
function n_thermal::Real, ω_th::Real)::Float64
x = exp/ ω_th)
(x != 1) && (ω_th > 0) ? n = (1 / (x - 1)) : n = 0.0
return n
end

_get_dense_similar(A::AbstractArray, args...) = similar(A, args...)
Expand Down
8 changes: 4 additions & 4 deletions test/core-test/eigenvalues_and_operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
ωb = 1
g = 0.01
κ = 0.1
n_thermal = 0.01
n_th = 0.01

H = ωc * a_d * a + ωb * b_d * b + g * (a + a_d) * (b + b_d)
c_ops = [((1 + n_thermal) * κ) * a, κ * b, (n_thermal * κ) * a_d]
c_ops = [((1 + n_th) * κ) * a, κ * b, (n_th * κ) * a_d]
L = liouvillian(H, c_ops)

# eigen solve for general matrices
Expand Down Expand Up @@ -103,10 +103,10 @@
ωb = 1
g = 0.01
κ = 0.1
n_thermal = 0.01
n_th = 0.01

H = ωc * a_d * a + ωb * b_d * b + g * (a + a_d) * (b + b_d)
c_ops = [((1 + n_thermal) * κ) * a, κ * b, (n_thermal * κ) * a_d]
c_ops = [((1 + n_th) * κ) * a, κ * b, (n_th * κ) * a_d]
L = liouvillian(H, c_ops)

@inferred eigenstates(H, sparse = false)
Expand Down
2 changes: 1 addition & 1 deletion test/core-test/generalized_master_equation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
a2 = Qobj(dense_to_sparse((U'*a*U).data[1:N_trunc, 1:N_trunc], tol))
sm2 = Qobj(dense_to_sparse((U'*sm*U).data[1:N_trunc, 1:N_trunc], tol))

@test abs(expect(Xp' * Xp, steadystate(L1)) - n_th(1, Tlist[1])) / n_th(1, Tlist[1]) < 1e-4
@test abs(expect(Xp' * Xp, steadystate(L1)) - n_thermal(1, Tlist[1])) / n_thermal(1, Tlist[1]) < 1e-4

@testset "Type Inference (liouvillian_generalized)" begin
N_c = 30
Expand Down

0 comments on commit c377908

Please sign in to comment.