|
| 1 | +# [Plotting on the Bloch Sphere](@id doc: plotting_the_bloch_sphere.md) |
| 2 | + |
| 3 | +```@setup Bloch_sphere_rendering |
| 4 | +using QuantumToolbox |
| 5 | +
|
| 6 | +using Makie |
| 7 | +using CairoMakie |
| 8 | +CairoMakie.enable_only_mime!(MIME"image/svg+xml"()) |
| 9 | +``` |
| 10 | + |
| 11 | +## [Introduction](@id doc:Bloch_sphere_rendering) |
| 12 | + |
| 13 | +When studying the dynamics of a two-level system, it's often convenient to visualize the state of the system by plotting the state vector or density matrix on the Bloch sphere. |
| 14 | + |
| 15 | +In [QuantumToolbox.jl](https://qutip.org/QuantumToolbox.jl/), this can be done using the [`Bloch`](@ref) or [`plot_bloch`](@ref) methods that provide same syntax as [QuTiP](https://github.com/qutip/qutip). |
| 16 | + |
| 17 | +## Create a Bloch Sphere |
| 18 | + |
| 19 | +```@example Bloch_sphere_rendering |
| 20 | +b = Bloch(); |
| 21 | +fig, _ = render(b) |
| 22 | +``` |
| 23 | + |
| 24 | +## Add a Single Data Point |
| 25 | + |
| 26 | +```@example Bloch_sphere_rendering |
| 27 | +pnt = [1 / sqrt(3), 1 / sqrt(3), 1 / sqrt(3)] |
| 28 | +add_points!(b, pnt) |
| 29 | +fig, _ = render(b) |
| 30 | +fig |
| 31 | +``` |
| 32 | + |
| 33 | +## Add a Single Vector |
| 34 | + |
| 35 | +```@example Bloch_sphere_rendering |
| 36 | +clear!(b) |
| 37 | +vec = [0, 1, 0]; |
| 38 | +add_vectors!(b, vec) |
| 39 | +fig, _ = render(b) |
| 40 | +fig |
| 41 | +``` |
| 42 | + |
| 43 | +## Add Multiple Vectors |
| 44 | + |
| 45 | +```@example Bloch_sphere_rendering |
| 46 | +clear!(b) |
| 47 | +vecs = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] |
| 48 | +add_vectors!(b, vecs) |
| 49 | +fig, _ = render(b) |
| 50 | +fig |
| 51 | +``` |
| 52 | + |
| 53 | +# Add Arc, Line, and Vector |
| 54 | + |
| 55 | +```@example Bloch_sphere_rendering |
| 56 | +clear!(b) |
| 57 | +vec = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; |
| 58 | +add_vectors!(b, vec); |
| 59 | +add_line!(b, [1,0,0], [0,1,0]) |
| 60 | +add_arc!(b, [1, 0, 0], [0, 1, 0], [0, 0, 1]) |
| 61 | +fig, _ = render(b) |
| 62 | +fig |
| 63 | +``` |
| 64 | + |
| 65 | +# Add Quantum States |
| 66 | + |
| 67 | +```@example Bloch_sphere_rendering |
| 68 | +clear!(b) |
| 69 | +x = basis(2, 0) + basis(2, 1) |
| 70 | +y = basis(2, 0) - im * basis(2, 1) |
| 71 | +z = basis(2, 0) |
| 72 | +b = Bloch() |
| 73 | +add_states!(b, [x, y, z]) |
| 74 | +fig, _ = render(b) |
| 75 | +fig |
| 76 | +``` |
| 77 | + |
| 78 | +## Add Multiple Points Around the Equator |
| 79 | + |
| 80 | +```@example Bloch_sphere_rendering |
| 81 | +th = range(0, 2π; length=20); |
| 82 | +clear!(b) |
| 83 | +xp = cos.(th); |
| 84 | +yp = sin.(th); |
| 85 | +zp = zeros(20); |
| 86 | +pnts = [xp, yp, zp] ; |
| 87 | +pnts = Matrix(hcat(xp, yp, zp)'); |
| 88 | +add_points!(b, pnts); |
| 89 | +fig, ax = render(b); |
| 90 | +fig |
| 91 | +``` |
| 92 | + |
| 93 | +## Add Another Set of Points |
| 94 | + |
| 95 | +```@example Bloch_sphere_rendering |
| 96 | +xz = zeros(20); |
| 97 | +yz = sin.(th); |
| 98 | +zz = cos.(th); |
| 99 | +points = hcat(xz, yz, zz)'; |
| 100 | +add_points!(b, Matrix(points), meth=:s, color="orange"); |
| 101 | +fig, ax = render(b); |
| 102 | +fig |
| 103 | +``` |
0 commit comments