Skip to content

Commit 57f3f37

Browse files
authored
update docs (time evolution introduction and solution) (#245)
1 parent 905e658 commit 57f3f37

File tree

2 files changed

+89
-8
lines changed

2 files changed

+89
-8
lines changed

docs/src/users_guide/time_evolution/intro.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ There are two kinds of quantum systems: open systems that interact with a larger
2323

2424
The following table lists the solvers provided by `QuantumToolbox` for dynamic quantum systems and the corresponding type of solution returned by the solver:
2525

26-
| **Equation** | **Function Call** | **Returned Solution** |
27-
|:-------------|:------------------|:----------------------|
28-
| Unitary evolution, Schrödinger equation | [`sesolve`](@ref) | [`TimeEvolutionSol`](@ref) |
29-
| Lindblad master eqn. or Von Neuman eqn. | [`mesolve`](@ref) | [`TimeEvolutionSol`](@ref) |
30-
| Monte Carlo evolution | [`mcsolve`](@ref) | [`TimeEvolutionMCSol`](@ref) |
31-
| Stochastic Schrödinger equation | [`ssesolve`](@ref) | [`TimeEvolutionSSESol`](@ref) |
26+
| **Equation** | **Function Call** | **Problem** | **Returned Solution** |
27+
|:-------------|:------------------|:------------|:----------------------|
28+
| Unitary evolution, Schrödinger equation | [`sesolve`](@ref) | [`sesolveProblem`](@ref) | [`TimeEvolutionSol`](@ref) |
29+
| Lindblad master eqn. or Von Neuman eqn.| [`mesolve`](@ref) | [`mesolveProblem`](@ref) | [`TimeEvolutionSol`](@ref) |
30+
| Monte Carlo evolution | [`mcsolve`](@ref) | [`mcsolveProblem`](@ref) [`mcsolveEnsembleProblem`](@ref) | [`TimeEvolutionMCSol`](@ref) |
31+
| Stochastic Schrödinger equation | [`ssesolve`](@ref) | [`ssesolveProblem`](@ref) [`ssesolveEnsembleProblem`](@ref) | [`TimeEvolutionSSESol`](@ref) |
32+
33+
!!! note "Solving dynamics with pre-defined problems"
34+
`QuantumToolbox` provides two different methods to solve the dynamics. One can use the function calls listed above by either taking all the operators (like Hamiltonian and collapse operators, etc.) as inputs directly, or generating the `prob`lems by yourself and take it as an input of the function call, e.g., `sesolve(prob)`.

docs/src/users_guide/time_evolution/solution.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,86 @@
22

33
## [Time Evolution Solutions](@id doc-TE:Time-Evolution-Solutions)
44

5-
This page is still under construction, please visit [API](@ref doc-API) first.
5+
```@setup TE-solution
6+
using QuantumToolbox
7+
```
68

79
### Solution
10+
`QuantumToolbox` utilizes the powerful [`DifferentialEquation.jl`](https://docs.sciml.ai/DiffEqDocs/stable/) to simulate different kinds of quantum system dynamics. Thus, we will first look at the data structure used for returning the solution (`sol`) from [`DifferentialEquation.jl`](https://docs.sciml.ai/DiffEqDocs/stable/). The solution stores all the crucial data needed for analyzing and plotting the results of a simulation. A generic structure [`TimeEvolutionSol`](@ref) contains the following properties for storing simulation data:
811

9-
### Multiple trajectories solution
12+
| **Fields (Attributes)** | **Description** |
13+
|:------------------------|:----------------|
14+
| `sol.times` | The time list of the evolution. |
15+
| `sol.states` | The list of result states. |
16+
| `sol.expect` | The expectation values corresponding to each time point in `sol.times`. |
17+
| `sol.alg` | The algorithm which is used during the solving process. |
18+
| `sol.abstol` | The absolute tolerance which is used during the solving process. |
19+
| `sol.reltol` | The relative tolerance which is used during the solving process. |
20+
| `sol.retcode` (or `sol.converged`) | The returned status from the solver. |
21+
22+
### Accessing data in solutions
23+
24+
To understand how to access the data in solution, we will use an example as a guide, although we do not worry about the simulation details at this stage. The Schrödinger equation solver ([`sesolve`](@ref)) used in this example returns [`TimeEvolutionSol`](@ref):
25+
26+
```@example TE-solution
27+
H = 0.5 * sigmax()
28+
ψ0 = basis(2, 0)
29+
e_ops = [
30+
proj(basis(2, 0)),
31+
proj(basis(2, 1)),
32+
basis(2, 0) * basis(2, 1)'
33+
]
34+
tlist = LinRange(0, 10, 100)
35+
sol = sesolve(H, ψ0, tlist, e_ops = e_ops, progress_bar = Val(false)); nothing # hide
36+
```
37+
38+
To see what is contained inside the solution, we can use the `print` function:
39+
40+
```@example TE-solution
41+
print(sol)
42+
```
43+
44+
It tells us the number of expectation values are computed and the number of states are stored. Now we have all the information needed to analyze the simulation results. To access the data for the three expectation values, one can do:
45+
46+
```@example TE-solution
47+
expt1 = real(sol.expect[1,:])
48+
expt2 = real(sol.expect[2,:])
49+
expt3 = real(sol.expect[3,:]); nothing # hide
50+
```
51+
52+
Recall that `Julia` uses `Fortran`-style indexing that begins with one (i.e., `[1,:]` represents the 1-st observable, where `:` represents all values corresponding to `tlist`).
53+
54+
Together with the array of times at which these expectation values are calculated:
55+
56+
```@example TE-solution
57+
times = sol.times; nothing # hide
58+
```
59+
60+
we can plot the resulting expectation values:
61+
62+
```@example TE-solution
63+
using CairoMakie
64+
CairoMakie.enable_only_mime!(MIME"image/svg+xml"())
65+
66+
fig = Figure()
67+
ax = Axis(fig[1, 1])
68+
lines!(ax, times, expt1, label = L"P_00")
69+
lines!(ax, times, expt2, label = L"P_11")
70+
lines!(ax, times, expt3, label = L"P_01")
71+
72+
fig
73+
```
74+
75+
State vectors, or density matrices, are accessed in a similar manner:
76+
77+
```@example TE-solution
78+
sol.states
79+
```
80+
81+
Here, the solution contains only one (final) state. Because the `states` will be saved depend on the keyword argument `saveat` in `kwargs`. If `e_ops` is specified, the default value of `saveat=[tlist[end]]` (only save the final state), otherwise, `saveat=tlist` (saving the states corresponding to `tlist`). One can also specify `e_ops` and `saveat` separately.
82+
83+
Some other solvers can have other output.
84+
85+
### Multiple trajectories solution
86+
87+
This part is still under construction, please visit [API](@ref doc-API) first.

0 commit comments

Comments
 (0)