Skip to content

Commit a3068b7

Browse files
authored
Replace n_th with n_thermal for QuTiP compatibility (#249)
* make `n_th` to `n_thermal` and align with qutip * fix fontsize in docs * improve type stability
1 parent d21041f commit a3068b7

File tree

7 files changed

+22
-22
lines changed

7 files changed

+22
-22
lines changed

benchmarks/eigenvalues.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ function benchmark_eigenvalues!(SUITE)
99
ωb = 1
1010
g = 0.2
1111
κ = 0.01
12-
n_thermal = 0.1
12+
n_th = 0.1
1313

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

1818
SUITE["Eigenvalues"]["eigenstates"]["dense"] = @benchmarkable eigenstates($L)

docs/src/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ AbstractLinearMap
238238
QuantumToolbox.versioninfo
239239
QuantumToolbox.about
240240
gaussian
241-
n_th
241+
n_thermal
242242
row_major_reshape
243243
meshgrid
244244
_calculate_expectation!

docs/src/users_guide/steadystate.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,11 @@ sol_me = mesolve(H, ψ0, tlist, c_op_list, e_ops=e_ops, progress_bar=false)
103103
exp_me = real(sol_me.expect[1, :])
104104
105105
# plot the results
106-
fig = Figure(size = (500, 350), fontsize = 15)
106+
fig = Figure(size = (500, 350))
107107
ax = Axis(fig[1, 1],
108108
title = L"Decay of Fock state $|10\rangle$ in a thermal environment with $\langle n\rangle=2$",
109109
xlabel = "Time",
110-
ylabel = "Number of excitations",
111-
titlesize = 24,
112-
xlabelsize = 20,
113-
ylabelsize = 20
110+
ylabel = "Number of excitations",
114111
)
115112
lines!(ax, tlist, exp_mc, label = "Monte-Carlo", linewidth = 2, color = :blue)
116113
lines!(ax, tlist, exp_me, label = "Master Equation", linewidth = 2, color = :orange, linestyle = :dash)

src/time_evolution/time_evolution.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ function liouvillian_generalized(
322322
end
323323

324324
# Ohmic reservoir
325-
N_th = n_th.(Ωp, T_list[i])
325+
N_th = n_thermal.(Ωp, T_list[i])
326326
Sp₀ = QuantumObject(triu(X_op, 1), type = Operator, dims = dims)
327327
Sp₁ = QuantumObject(droptol!((@. Ωp * N_th * Sp₀.data), tol), type = Operator, dims = dims)
328328
Sp₂ = QuantumObject(droptol!((@. Ωp * (1 + N_th) * Sp₀.data), tol), type = Operator, dims = dims)

src/utilities.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Utilities:
33
internal (or external) functions which will be used throughout the entire package
44
=#
55

6-
export gaussian, n_th
6+
export gaussian, n_thermal
77
export row_major_reshape, meshgrid
88

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

3636
@doc raw"""
37-
n_th(ω::Number, T::Real)
37+
n_thermal(ω::Real, ω_th::Real)
3838
39-
Gives the mean number of excitations in a mode with frequency ω at temperature T:
40-
``n_{\rm th} (\omega, T) = \frac{1}{e^{\omega/T} - 1}``
39+
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``:
40+
```math
41+
n(\omega, \omega_{\textrm{th}}) = \frac{1}{e^{\omega/\omega_{\textrm{th}}} - 1},
42+
```
43+
where ``\hbar`` is the reduced Planck constant, and ``k_B`` is the Boltzmann constant.
4144
"""
42-
function n_th::Real, T::Real)::Float64
43-
(T == 0 || ω == 0) && return 0.0
44-
abs/ T) > 50 && return 0.0
45-
return 1 / (exp/ T) - 1)
45+
function n_thermal::Real, ω_th::Real)::Float64
46+
x = exp/ ω_th)
47+
n = ((x != 1) && (ω_th > 0)) ? (1.0 / (x - 1.0)) : 0.0
48+
return n
4649
end
4750

4851
_get_dense_similar(A::AbstractArray, args...) = similar(A, args...)

test/core-test/eigenvalues_and_operators.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050
ωb = 1
5151
g = 0.01
5252
κ = 0.1
53-
n_thermal = 0.01
53+
n_th = 0.01
5454

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

5959
# eigen solve for general matrices
@@ -103,10 +103,10 @@
103103
ωb = 1
104104
g = 0.01
105105
κ = 0.1
106-
n_thermal = 0.01
106+
n_th = 0.01
107107

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

112112
@inferred eigenstates(H, sparse = false)

test/core-test/generalized_master_equation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
a2 = Qobj(dense_to_sparse((U'*a*U).data[1:N_trunc, 1:N_trunc], tol))
4141
sm2 = Qobj(dense_to_sparse((U'*sm*U).data[1:N_trunc, 1:N_trunc], tol))
4242

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

4545
@testset "Type Inference (liouvillian_generalized)" begin
4646
N_c = 30

0 commit comments

Comments
 (0)