Skip to content

Commit a2aa46c

Browse files
committed
fix CI errors and add some enhancments
1 parent d20a08e commit a2aa46c

File tree

6 files changed

+373
-109
lines changed

6 files changed

+373
-109
lines changed

.typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[default.extend-words]
22
ket = "ket"
33
sme = "sme"
4+
Heros = "Heros"

docs/src/resources/api.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,13 @@ meshgrid
315315
```@docs
316316
plot_wigner
317317
plot_fock_distribution
318+
plot_bloch
319+
Bloch
320+
render
321+
add_points!
322+
add_vectors!
323+
add_line!
324+
add_arc!
325+
clear!
326+
add_states!
318327
```

docs/src/users_guide/plotting_the_bloch_sphere.md

Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,63 @@ In [QuantumToolbox.jl](https://qutip.org/QuantumToolbox.jl/), this can be done u
1515

1616
## Create a Bloch Sphere
1717

18+
In [QuantumToolbox.jl](https://qutip.org/QuantumToolbox.jl/), creating a [`Bloch`](@ref) sphere is accomplished by calling either:
19+
1820
```@example Bloch_sphere_rendering
1921
b = Bloch();
20-
fig, _ = render(b)
22+
```
23+
24+
which will load an instance of [`Bloch`](@ref). Before getting into the details of these objects, we can simply plot the blank [`Bloch`](@ref) sphere associated with these instances via:
25+
26+
```@example Bloch_sphere_rendering
27+
fig, _ = render(b);
28+
fig
2129
```
2230

2331
## Add a Single Data Point
2432

33+
As an example, we can add a single data point via [`add_points!`](@ref):
34+
2535
```@example Bloch_sphere_rendering
26-
pnt = [1 / sqrt(3), 1 / sqrt(3), 1 / sqrt(3)]
27-
add_points!(b, pnt)
28-
fig, _ = render(b)
36+
pnt = [1 / sqrt(3), 1 / sqrt(3), 1 / sqrt(3)];
37+
add_points!(b, pnt);
38+
fig, _ = render(b);
2939
fig
3040
```
3141

3242
## Add a Single Vector
3343

44+
and then a single vector via [`add_vectors!`](@ref):
45+
3446
```@example Bloch_sphere_rendering
35-
clear!(b)
3647
vec = [0, 1, 0];
3748
add_vectors!(b, vec)
3849
fig, _ = render(b)
3950
fig
4051
```
4152

42-
## Add Multiple Vectors
53+
and then add another vector corresponding to the ``|0\rangle`` state:
4354

4455
```@example Bloch_sphere_rendering
45-
clear!(b)
46-
vecs = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
47-
add_vectors!(b, vecs)
56+
x = basis(2, 0)
57+
add_states!(b, [x])
4858
fig, _ = render(b)
4959
fig
5060
```
5161

52-
# Add Arc, Line, and Vector
62+
## Add Multiple Vectors
63+
64+
We can also plot multiple points, vectors, and states at the same time by passing arrays instead of individual elements via [`add_vectors!](@ref). Before giving an example, we can use [`clear!`](@ref) to remove the current data from our [`Bloch`](@ref) sphere instead of creating a new instance:
5365

5466
```@example Bloch_sphere_rendering
5567
clear!(b)
56-
vec = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
57-
add_vectors!(b, vec);
58-
add_line!(b, [1,0,0], [0,1,0])
59-
add_arc!(b, [1, 0, 0], [0, 1, 0], [0, 0, 1])
6068
fig, _ = render(b)
6169
fig
6270
```
6371

64-
# Add Quantum States
72+
Now on the same [`Bloch`](@ref) sphere, we can plot the three states via [`add_states!`](@ref) associated with the `x`, `y`, and `z` directions:
6573

6674
```@example Bloch_sphere_rendering
67-
clear!(b)
6875
x = basis(2, 0) + basis(2, 1)
6976
y = basis(2, 0) - im * basis(2, 1)
7077
z = basis(2, 0)
@@ -74,29 +81,80 @@ fig, _ = render(b)
7481
fig
7582
```
7683

77-
## Add Multiple Points Around the Equator
84+
a similar method works for adding vectors:
85+
86+
```@example Bloch_sphere_rendering
87+
clear!(b)
88+
vecs = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
89+
add_vectors!(b, vecs)
90+
fig, _ = render(b)
91+
fig
92+
```
93+
94+
# Add Arc, Line, and Vector
95+
96+
You can also add lines and arcs via [`add_line!`](@ref) and [`add_arc!`](@ref) respectively:
97+
98+
```@example Bloch_sphere_rendering
99+
clear!(b)
100+
vec = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
101+
add_vectors!(b, vec);
102+
add_line!(b, [1,0,0], [0,1,0])
103+
add_arc!(b, [1, 0, 0], [0, 1, 0], [0, 0, 1])
104+
fig, _ = render(b)
105+
fig
106+
```
107+
108+
## Add Multiple Points
109+
110+
Adding multiple points to the [`Bloch`](@ref) sphere works slightly differently than adding multiple states or vectors. For example, lets add a set of `20` points around the equator (after calling [`clear!`](@ref)):
78111

79112
```@example Bloch_sphere_rendering
80113
th = range(0, 2π; length=20);
81114
clear!(b)
82115
xp = cos.(th);
83116
yp = sin.(th);
84117
zp = zeros(20);
85-
pnts = [xp, yp, zp] ;
86-
pnts = Matrix(hcat(xp, yp, zp)');
118+
pnts = [xp, yp, zp];
87119
add_points!(b, pnts);
88120
fig, ax = render(b);
89121
fig
90122
```
91123

124+
Notice that, in contrast to states or vectors, each point remains the same color as the initial point. This is because adding multiple data points using [`add_points!`](@ref) is interpreted, by default, to correspond to a single data point (single qubit state) plotted at different times. This is very useful when visualizing the dynamics of a qubit. An example of this is given in the example . If we want to plot additional qubit states we can call additional [`add_points!`](@ref) functions:
125+
92126
## Add Another Set of Points
93127

94128
```@example Bloch_sphere_rendering
95129
xz = zeros(20);
96130
yz = sin.(th);
97131
zz = cos.(th);
98-
points = hcat(xz, yz, zz)';
99-
add_points!(b, Matrix(points), meth=:s, color="orange");
132+
pnts = [xz, yz, zz];
133+
add_points!(b, pnts);
134+
fig, ax = render(b);
135+
fig
136+
```
137+
138+
The color and shape of the data points is varied automatically by [`Bloch`](@ref). Notice how the color and point markers change for each set of data. Again, we have had to call add_points twice because adding more than one set of multiple data points is not supported by the add_points function.
139+
140+
What if we want to vary the color of our points. We can tell [`Bloch`](@ref) to vary the color of each point according to the colors listed in the `point_color` attribute..
141+
142+
```@example Bloch_sphere_rendering
143+
clear!(b)
144+
xp = cos.(th);
145+
yp = sin.(th);
146+
zp = zeros(20);
147+
pnts = [xp, yp, zp];
148+
add_points!(b, pnts, meth=:m);
149+
fig, ax = render(b);
150+
fig
151+
```
152+
153+
Now, the data points cycle through a variety of predefined colors. Now lets add another set of points, but this time we want the set to be a single color, representing say a qubit going from the ``|0\rangle`` state to the ``|1\rangle`` state in the `y-z` plane:
154+
155+
```@example Bloch_sphere_rendering
156+
pnts = [xz, yz, zz] ;
157+
add_points!(b, pnts);
100158
fig, ax = render(b);
101159
fig
102160
```

0 commit comments

Comments
 (0)