|
2 | 2 |
|
3 | 3 | ## [Time Evolution Solutions](@id doc-TE:Time-Evolution-Solutions) |
4 | 4 |
|
5 | | -This page is still under construction, please visit [API](@ref doc-API) first. |
| 5 | +```@setup TE-solution |
| 6 | +using QuantumToolbox |
| 7 | +``` |
6 | 8 |
|
7 | 9 | ### 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: |
8 | 11 |
|
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