Skip to content

Commit dca631a

Browse files
authored
[Doc] update documentation for sesolve and mesolve (#261)
* add documentation for `sesolve` * fix typo in `sesolve` * add documentation for von Neumann eq. * remove title from each time evolution page to fix typo in sidebar * minor changes * update documentation for `mesolve`
1 parent 8f64619 commit dca631a

File tree

9 files changed

+351
-33
lines changed

9 files changed

+351
-33
lines changed

docs/src/users_guide/states_and_operators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,4 +404,4 @@ t = 0.8
404404
exp(L * t)
405405
```
406406

407-
See the section [Time Evolution and Quantum System Dynamics](@ref doc:Time-Evolution-and-Quantum-System-Dynamics) for more details.
407+
See the section [Lindblad Master Equation Solver](@ref doc-TE:Lindblad-Master-Equation-Solver) for more details.

docs/src/users_guide/steadystate.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ solver = SteadyStateLinearSolver(alg = MKLLUFactorization())
6464

6565
See [`LinearSolve.jl` Solvers](https://docs.sciml.ai/LinearSolve/stable/solvers/solvers/) for more details.
6666

67-
## Example: Harmonic Oscillator in Thermal Bath
67+
## Example: Harmonic oscillator in thermal bath
68+
69+
Here, we demonstrate [`steadystate`](@ref) by using the example with the harmonic oscillator in thermal bath from the previous section ([Lindblad Master Equation Solver](@ref doc-TE:Lindblad-Master-Equation-Solver)).
6870

6971
```@example steady_state_example
7072
using QuantumToolbox
@@ -77,16 +79,16 @@ a = destroy(N)
7779
H = a' * a
7880
ψ0 = basis(N, 10) # initial state
7981
κ = 0.1 # coupling to oscillator
80-
n_th = 2 # temperature with average of 2 excitations
82+
n_th = 2 # temperature with average of 2 excitations
8183
8284
# collapse operators
83-
c_op_list = [
85+
c_ops = [
8486
sqrt(κ * (n_th + 1)) * a, # emission
8587
sqrt(κ * n_th ) * a' # absorption
8688
]
8789
8890
# find steady-state solution
89-
ρ_ss = steadystate(H, c_op_list)
91+
ρ_ss = steadystate(H, c_ops)
9092
9193
# find expectation value for particle number in steady state
9294
e_ops = [a' * a]
@@ -95,11 +97,11 @@ exp_ss = real(expect(e_ops[1], ρ_ss))
9597
tlist = LinRange(0, 50, 100)
9698
9799
# monte-carlo
98-
sol_mc = mcsolve(H, ψ0, tlist, c_op_list, e_ops=e_ops, ntraj=100, progress_bar=false)
100+
sol_mc = mcsolve(H, ψ0, tlist, c_ops, e_ops=e_ops, ntraj=100, progress_bar=false)
99101
exp_mc = real(sol_mc.expect[1, :])
100102
101103
# master eq.
102-
sol_me = mesolve(H, ψ0, tlist, c_op_list, e_ops=e_ops, progress_bar=false)
104+
sol_me = mesolve(H, ψ0, tlist, c_ops, e_ops=e_ops, progress_bar=false)
103105
exp_me = real(sol_me.expect[1, :])
104106
105107
# plot the results

docs/src/users_guide/time_evolution/intro.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ Pages = [
1212
"stochastic.md",
1313
"time_dependent.md",
1414
]
15-
Depth = 2:3
15+
Depth = 1:2
1616
```
1717

18-
## [Introduction](@id doc-TE:Introduction)
18+
# [Introduction](@id doc-TE:Introduction)
1919

2020
Although in some cases, we want to find the stationary states of a quantum system, often we are interested in the dynamics: how the state of a system or an ensemble of systems evolves with time. `QuantumToolbox` provides many ways to model dynamics.
2121

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Time Evolution and Quantum System Dynamics
2-
3-
## [Monte-Carlo Solver](@id doc-TE:Monte-Carlo-Solver)
1+
# [Monte-Carlo Solver](@id doc-TE:Monte-Carlo-Solver)
42

53
This page is still under construction, please visit [API](@ref doc-API) first.
Lines changed: 223 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,227 @@
1-
# Time Evolution and Quantum System Dynamics
1+
# [Lindblad Master Equation Solver](@id doc-TE:Lindblad-Master-Equation-Solver)
22

3-
## [Lindblad Master Equation Solver](@id doc-TE:Lindblad-Master-Equation-Solver)
3+
```@setup mesolve
4+
using QuantumToolbox
5+
```
46

5-
This page is still under construction, please visit [API](@ref doc-API) first.
7+
## Von Neumann equation
68

7-
### Von Neumann equation
9+
While the evolution of the state vector in a closed quantum system is deterministic (as we discussed in the previous section: [Schrödinger Equation Solver](@ref doc-TE:Schrödinger-Equation-Solver)), open quantum systems are stochastic in nature. The effect of an environment on the system of interest is to induce stochastic transitions between energy levels, and to introduce uncertainty in the phase difference between states of the system. The state of an open quantum system is therefore described in terms of ensemble averaged states using the density matrix formalism. A density matrix ``\hat{\rho}`` describes a probability distribution of quantum states ``|\psi_n\rangle`` in a matrix representation, namely
810

9-
### The Lindblad master equation
11+
```math
12+
\hat{\rho} = \sum_n p_n |\psi_n\rangle\langle\psi_n|,
13+
```
14+
15+
where ``p_n`` is the classical probability that the system is in the quantum state ``|\psi_n\rangle``. The time evolution of a density matrix ``\hat{\rho}`` is the topic of the remaining portions of this section.
16+
17+
The time evolution of the density matrix ``\hat{\rho}(t)`` under closed system dynamics is governed by the von Neumann equation:
18+
19+
```math
20+
\begin{equation}
21+
\label{von-Neumann-Eq}
22+
\frac{d}{dt}\hat{\rho}(t) = -\frac{i}{\hbar}\left[\hat{H}, \hat{\rho}(t)\right],
23+
\end{equation}
24+
```
25+
26+
where ``[\cdot, \cdot]`` represents the commutator. The above equation is equivalent to the Schrödinger equation described in the [previous section](@ref doc-TE:Schrödinger-Equation-Solver) under the density matrix formalism.
27+
28+
In `QuantumToolbox`, given a Hamiltonian, we can calculate the unitary (non-dissipative) time-evolution of an arbitrary initial state using the `QuantumToolbox` time evolution problem [`mesolveProblem`](@ref) or directly call the function [`mesolve`](@ref). It evolves the density matrix ``\hat{\rho}(t)`` and evaluates the expectation values for a set of operators `e_ops` at each given time points, using an ordinary differential equation solver provided by the powerful julia package [`DifferentialEquation.jl`](https://docs.sciml.ai/DiffEqDocs/stable/).
29+
30+
```@example mesolve
31+
H = 0.5 * sigmax()
32+
state0 = basis(2, 0) # state vector
33+
state0 = ket2dm(basis(2, 0)) # density matrix
34+
tlist = LinRange(0.0, 10.0, 20)
35+
36+
sol = mesolve(H, state0, tlist, e_ops = [sigmaz()])
37+
```
38+
39+
!!! note "Type of initial state"
40+
The initial state `state0` here can be given as a state vector ``|\psi(0)\rangle`` (in the type of [`Ket`](@ref)) or a density matrix ``\hat{\rho}(0)`` (in the type of [`Operator`](@ref)). If it is given as a [`Ket`](@ref), it will be transformed to density matrix ``\hat{\rho}(0) = |\psi(0)\rangle\langle\psi(0)|`` internally in [`mesolve`](@ref).
41+
42+
The function returns [`TimeEvolutionSol`](@ref), as described in the previous section [Time Evolution Solutions](@ref doc-TE:Time-Evolution-Solutions). The stored `states` will always be in the type of [`Operator`](@ref) (density matrix).
43+
44+
```@example mesolve
45+
sol.states
46+
```
47+
48+
Here, only the final state is stored because the `states` will be saved depend on the keyword argument `saveat` in `kwargs`. If `e_ops` is empty, the default value of `saveat=tlist` (saving the states corresponding to `tlist`), otherwise, `saveat=[tlist[end]]` (only save the final state).
49+
50+
One can also specify `e_ops` and `saveat` separately:
51+
52+
```@example mesolve
53+
tlist = [0, 5, 10]
54+
sol = mesolve(H, state0, tlist, e_ops = [sigmay()], saveat = tlist)
55+
```
56+
57+
```@example mesolve
58+
sol.expect
59+
```
60+
61+
```@example mesolve
62+
sol.states
63+
```
64+
65+
## The Lindblad master equation
66+
67+
The standard approach for deriving the equations of motion for a system interacting with its environment is to expand the scope of the system to include the environment. The combined quantum system is then closed, and its evolution is governed by the von Neumann equation given in Eq. \eqref{von-Neumann-Eq}
68+
69+
```math
70+
\begin{equation}
71+
\label{tot-von-Neumann-Eq}
72+
\frac{d}{dt}\hat{\rho}_{\textrm{tot}}(t) = -\frac{i}{\hbar}\left[\hat{H}_{\textrm{tot}}, \hat{\rho}_{\textrm{tot}}(t)\right].
73+
\end{equation}
74+
```
75+
76+
Here, the total Hamiltonian
77+
78+
```math
79+
\hat{H}_{\textrm{tot}} = \hat{H}_{\textrm{sys}} + \hat{H}_{\textrm{env}} + \hat{H}_{\textrm{int}},
80+
```
81+
82+
includes the original system Hamiltonian ``\hat{H}_{\textrm{sys}}``, the Hamiltonian for the environment ``\hat{H}_{\textrm{env}}``, and a term representing the interaction between the system and its environment ``\hat{H}_{\textrm{int}}``. Since we are only interested in the dynamics of the system, we can, perform a partial trace over the environmental degrees of freedom in Eq. \eqref{tot-von-Neumann-Eq}, and thereby obtain a master equation for the motion of the original system density matrix ``\hat{\rho}_{\textrm{sys}}(t)=\textrm{Tr}_{\textrm{env}}[\hat{\rho}_{\textrm{tot}}(t)]``. The most general trace-preserving and completely positive form of this evolution is the Lindblad master equation for the reduced density matrix, namely
83+
84+
```math
85+
\begin{equation}
86+
\label{Lindblad-master-Eq}
87+
\frac{d}{dt}\hat{\rho}_{\textrm{sys}}(t) = -\frac{i}{\hbar}\left[\hat{H}_{\textrm{sys}}, \hat{\rho}_{\textrm{sys}}(t)\right] + \sum_n \hat{C}_n \hat{\rho}_{\textrm{sys}}(t) \hat{C}_n^\dagger - \frac{1}{2} \hat{C}_n^\dagger \hat{C}_n \hat{\rho}_{\textrm{sys}}(t) - \frac{1}{2} \hat{\rho}_{\textrm{sys}}(t) \hat{C}_n^\dagger \hat{C}_n
88+
\end{equation}
89+
```
90+
91+
where ``\hat{C}_n \equiv \sqrt{\gamma_n}\hat{A}_n`` are the collapse operators, ``\hat{A}_n`` are the operators acting on the system in ``\hat{H}_{\textrm{int}}`` which describes the system-environment interaction, and ``\gamma_n`` are the corresponding rates. The derivation of Eq. \eqref{Lindblad-master-Eq} may be found in several sources, and will not be reproduced here. Instead, we emphasize the approximations that are required to arrive at the master equation in the form of Eq. \eqref{Lindblad-master-Eq} from physical arguments, and hence perform a calculation in `QuantumToolbox`:
92+
93+
- **Separability:** At ``t = 0``, there are no correlations between the system and environment, such that the total density matrix can be written as a tensor product, namely ``\hat{\rho}_{\textrm{tot}}(0)=\hat{\rho}_{\textrm{sys}}(0)\otimes\hat{\rho}_{\textrm{env}}(0)``.
94+
- **Born approximation:** Requires: (i) the state of the environment does not significantly change as a result of the interaction with the system; (ii) the system and the environment remain separable throughout the evolution. These assumptions are justified if the interaction is weak, and if the environment is much larger than the system. In summary, ``\hat{\rho}_{\textrm{tot}}(t)\approx\hat{\rho}_{\textrm{sys}}(t)\otimes\hat{\rho}_{\textrm{env}}(0)``.
95+
- **Markov approximation:** The time-scale of decay for the environment ``\tau_{\textrm{env}}`` is much shorter than the smallest time-scale of the system dynamics, i.e., ``\tau_{\textrm{sys}}\gg\tau_{\textrm{env}}``. This approximation is often deemed a “short-memory environment” as it requires the environmental correlation functions decay in a fast time-scale compared to those of the system.
96+
- **Secular approximation:** Stipulates that elements in the master equation corresponding to transition frequencies satisfy ``|\omega_{ab}-\omega_{cd}| \ll 1/\tau_{\textrm{sys}}``, i.e., all fast rotating terms in the interaction picture can be neglected. It also ignores terms that lead to a small renormalization of the system energy levels. This approximation is not strictly necessary for all master-equation formalisms (e.g., the Block-Redfield master equation), but it is required for arriving at the Lindblad form in Eq. \eqref{Lindblad-master-Eq} which is used in [`mesolve`](@ref).
97+
98+
For systems with environments satisfying the conditions outlined above, the Lindblad master equation in Eq. \eqref{Lindblad-master-Eq} governs the time-evolution of the system density matrix, giving an ensemble average of the system dynamics. In order to ensure that these approximations are not violated, it is important that the decay rates ``\gamma_n`` be smaller than the minimum energy splitting in the system Hamiltonian. Situations that demand special attention therefore include, for example, systems strongly coupled to their environment, and systems with degenerate or nearly degenerate energy levels.
99+
100+
What is new in the master equation compared to the Schrödinger equation (or von Neumann equation) are processes that describe dissipation in the quantum system due to its interaction with an environment. For example, evolution that includes incoherent processes such as relaxation and dephasing. These environmental interactions are defined by the operators ``\hat{A}_n`` through which the system couples to the environment, and rates ``\gamma_n`` that describe the strength of the processes.
101+
102+
In `QuantumToolbox`, the function [`mesolve`](@ref) can also be used for solving the master equation. This is done by passing a list of collapse operators (`c_ops`) as the fourth argument of the [`mesolve`](@ref) function in order to define the dissipation processes of the master equation in Eq. \eqref{Lindblad-master-Eq}. As we mentioned above, each collapse operator ``\hat{C}_n`` is the product of ``\sqrt{\gamma_n}`` (the square root of the rate) and ``\hat{A}_n`` (operator which describes the dissipation process).
103+
104+
Furthermore, `QuantumToolbox` solves the master equation in the [`SuperOperator`](@ref) formalism. That is, a Liouvillian [`SuperOperator`](@ref) will be generated internally in [`mesolve`](@ref) by the input system Hamiltonian ``\hat{H}_{\textrm{sys}}`` and the collapse operators ``\hat{C}_n``. One can also generate the Liouvillian [`SuperOperator`](@ref) manually for special purposes, and pass it as the first argument of the [`mesolve`](@ref) function. To do so, it is useful to read the section [Superoperators and Vectorized Operators](@ref doc:Superoperators-and-Vectorized-Operators), and also the docstrings of the following functions:
105+
- [`spre`](@ref)
106+
- [`spost`](@ref)
107+
- [`sprepost`](@ref)
108+
- [`liouvillian`](@ref)
109+
- [`lindblad_dissipator`](@ref)
110+
111+
## Example: Spin dynamics
112+
113+
Using the example with the dynamics of spin-``\frac{1}{2}`` from the previous section ([Schrödinger Equation Solver](@ref doc-TE:Schrödinger-Equation-Solver)), we can easily add a relaxation process (describing the dissipation of energy from the spin to the environment), by adding `[sqrt(γ) * sigmax()]` in the fourth parameter of the [`mesolve`](@ref) function.
114+
115+
```@example mesolve
116+
H = 2 * π * 0.1 * sigmax()
117+
ψ0 = basis(2, 0) # spin-up
118+
tlist = LinRange(0.0, 10.0, 100)
119+
120+
γ = 0.05
121+
c_ops = [sqrt(γ) * sigmax()]
122+
123+
sol = mesolve(H, ψ0, tlist, c_ops, e_ops = [sigmaz(), sigmay()])
124+
```
125+
126+
We can therefore plot the expectation values:
127+
128+
```@example mesolve
129+
using CairoMakie
130+
CairoMakie.enable_only_mime!(MIME"image/svg+xml"())
131+
132+
times = sol.times
133+
expt_z = real(sol.expect[1,:])
134+
expt_y = real(sol.expect[2,:])
135+
136+
fig = Figure(size = (500, 350))
137+
ax = Axis(fig[1, 1], xlabel = "Time", ylabel = "Expectation values")
138+
lines!(ax, times, expt_z, label = L"\langle\hat{\sigma}_z\rangle", linestyle = :solid)
139+
lines!(ax, times, expt_y, label = L"\langle\hat{\sigma}_y\rangle", linestyle = :dash)
140+
141+
axislegend(ax, position = :rt)
142+
143+
fig
144+
```
145+
146+
## Example: Harmonic oscillator in thermal bath
147+
148+
Consider a harmonic oscillator (single-mode cavity) couples to a thermal bath. If the single-mode cavity initially is in a `10`-photon [`fock`](@ref) state, the dynamics is calculated with the following code:
149+
150+
```@example mesolve
151+
# Define parameters
152+
N = 20 # number of basis states to consider
153+
a = destroy(N)
154+
H = a' * a
155+
ψ0 = fock(N, 10) # initial state
156+
κ = 0.1 # coupling to oscillator
157+
n_th = 2 # temperature with average of 2 excitations
158+
tlist = LinRange(0, 50, 100)
159+
160+
# collapse operators
161+
c_ops = [
162+
sqrt(κ * (n_th + 1)) * a, # emission
163+
sqrt(κ * n_th ) * a' # absorption
164+
]
165+
166+
# find expectation value for particle number
167+
e_ops = [a' * a]
168+
169+
sol = mesolve(H, ψ0, tlist, c_ops, e_ops=e_ops)
170+
Num = real(sol.expect[1, :])
171+
172+
# plot the results
173+
fig = Figure(size = (500, 350))
174+
ax = Axis(fig[1, 1],
175+
title = L"Decay of Fock state $|10\rangle$ in a thermal environment with $\langle n\rangle=2$",
176+
xlabel = "Time",
177+
ylabel = "Number of excitations",
178+
)
179+
lines!(ax, tlist, Num)
180+
181+
fig
182+
```
183+
184+
## Example: Two-level atom coupled to dissipative single-mode cavity
185+
186+
Consider a two-level atom coupled to a dissipative single-mode cavity through a dipole-type interaction, which supports a coherent exchange of quanta between the two systems. If the atom initially is in its ground state and the cavity in a `5`-photon [`fock`](@ref) state, the dynamics is calculated with the following code:
187+
188+
!!! note "Generate Liouviilian superoperator manually"
189+
In this example, we demonstrate how to generate the Liouvillian [`SuperOperator`](@ref) manually and pass it as the first argument of the [`mesolve`](@ref) function.
190+
191+
```@example mesolve
192+
# two-level atom
193+
σm = tensor(destroy(2), qeye(10))
194+
H_a = 2 * π * σm' * σm
195+
196+
# dissipative single-mode cavity
197+
γ = 0.1 # dissipation rate
198+
a = tensor(qeye(2), destroy(10))
199+
H_c = 2 * π * a' * a
200+
c_ops = [sqrt(γ) * a]
201+
202+
# coupling between two-level atom and single-mode cavity
203+
g = 0.25 # coupling strength
204+
H_I = 2 * π * g * (σm * a' + σm' * a)
205+
206+
ψ0 = tensor(basis(2,0), fock(10, 5)) # initial state
207+
tlist = LinRange(0.0, 10.0, 200)
208+
209+
# generate Liouvillian superoperator manually
210+
L = liouvillian(H_a + H_c + H_I, c_ops)
211+
sol = mesolve(L, ψ0, tlist, e_ops=[σm' * σm, a' * a])
212+
213+
times = sol.times
214+
215+
# expectation value of Number operator
216+
N_atom = real(sol.expect[1,:])
217+
N_cavity = real(sol.expect[2,:])
218+
219+
fig = Figure(size = (500, 350))
220+
ax = Axis(fig[1, 1], xlabel = "Time", ylabel = "Expectation values")
221+
lines!(ax, times, N_atom, label = "atom excitation probability", linestyle = :solid)
222+
lines!(ax, times, N_cavity, label = "cavity photon number", linestyle = :dash)
223+
224+
axislegend(ax, position = :rt)
225+
226+
fig
227+
```

0 commit comments

Comments
 (0)