Skip to content

Commit 8589b8b

Browse files
author
cailixun
committed
update tutorial
1 parent ab258f0 commit 8589b8b

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

docs/src/users_guide/plotting_the_bloch_sphere.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,63 @@ These properties can also be accessed via the `print` command:
211211
```@example Bloch_sphere_rendering
212212
b = Bloch()
213213
print(b)
214-
```
214+
```
215+
216+
## Animating with the Bloch sphere
217+
218+
The [`Bloch`](@ref) structure was designed from the outset to generate animations. To animate a set of vectors or data points, the basic idea is: plot the data at time ``t_1``, save the sphere, clear the sphere, plot data at ``t_2``, and so on. The easiest way to animate data on the Bloch sphere is to use the `record` function provided by [`Makie.jl`](https://docs.makie.org/stable/). We will demonstrate this functionality with the following example: the decay of a qubit on the Bloch sphere.
219+
220+
```@example Bloch_sphere_rendering
221+
# system parameters
222+
ω = 2π
223+
θ = 0.2π
224+
n_th = 0.5 # temperature
225+
γ1 = 0.5
226+
γ2 = 0.2
227+
228+
# operators and the Hamiltonian
229+
sx = sigmax()
230+
sy = sigmay()
231+
sz = sigmaz()
232+
sm = sigmam()
233+
H = ω * (cos(θ) * sz + sin(θ) * sx)
234+
235+
# collapse operators
236+
c_op_list = (
237+
√(γ1 * (n_th + 1)) * sm,
238+
√(γ1 * n_th) * sm',
239+
√γ2 * sz
240+
)
241+
242+
# solving evolution
243+
ψ0 = basis(2, 0)
244+
tlist = LinRange(0, 4, 250)
245+
sol = mesolve(H, ψ0, tlist, c_op_list, e_ops = (sx, sy, sz), progress_bar = Val(false))
246+
x = real(sol.expect[1,:])
247+
y = real(sol.expect[2,:])
248+
z = real(sol.expect[3,:])
249+
```
250+
251+
To animate a set of vectors or data points, we use the `record` function provided by [`Makie.jl`](https://docs.makie.org/stable/):
252+
253+
```@example Bloch_sphere_rendering
254+
b = Bloch()
255+
b.view = [50,30]
256+
257+
fig, lscene = render(b)
258+
259+
record(fig, "qubit_decay.mp4", eachindex(tlist), framerate = 20) do idx
260+
clear!(b)
261+
add_vectors!(b, [sin(θ), 0, cos(θ)])
262+
add_points!(b, [x[1:idx], y[1:idx], z[1:idx]])
263+
render(b, location = lscene)
264+
end
265+
nothing # hide
266+
```
267+
268+
```@raw html
269+
<video autoplay loop muted playsinline controls src="./qubit_decay.mp4" />
270+
```
271+
272+
!!! note
273+
Here, we set the keyword argument `location = lscene` in the last `render` function to update the existing Bloch sphere without creating new `Figure` and `LScene`. This is efficient when drawing animations.

0 commit comments

Comments
 (0)